Coverage Report

Created: 2026-02-26 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/git/environment.c
Line
Count
Source
1
/*
2
 * We put all the git config variables in this same object
3
 * file, so that programs can link against the config parser
4
 * without having to link against all the rest of git.
5
 *
6
 * In particular, no need to bring in libz etc unless needed,
7
 * even if you might want to know where the git directory etc
8
 * are.
9
 */
10
11
#define USE_THE_REPOSITORY_VARIABLE
12
13
#include "git-compat-util.h"
14
#include "abspath.h"
15
#include "advice.h"
16
#include "attr.h"
17
#include "branch.h"
18
#include "color.h"
19
#include "convert.h"
20
#include "environment.h"
21
#include "gettext.h"
22
#include "git-zlib.h"
23
#include "ident.h"
24
#include "lockfile.h"
25
#include "mailmap.h"
26
#include "object-name.h"
27
#include "repository.h"
28
#include "config.h"
29
#include "refs.h"
30
#include "fmt-merge-msg.h"
31
#include "commit.h"
32
#include "strvec.h"
33
#include "pager.h"
34
#include "path.h"
35
#include "quote.h"
36
#include "chdir-notify.h"
37
#include "setup.h"
38
#include "ws.h"
39
#include "write-or-die.h"
40
41
static int pack_compression_seen;
42
static int zlib_compression_seen;
43
44
int trust_executable_bit = 1;
45
int trust_ctime = 1;
46
int check_stat = 1;
47
int has_symlinks = 1;
48
int minimum_abbrev = 4, default_abbrev = -1;
49
int ignore_case;
50
int assume_unchanged;
51
int is_bare_repository_cfg = -1; /* unspecified */
52
int warn_on_object_refname_ambiguity = 1;
53
char *git_commit_encoding;
54
char *git_log_output_encoding;
55
char *apply_default_whitespace;
56
char *apply_default_ignorewhitespace;
57
char *git_attributes_file;
58
int zlib_compression_level = Z_BEST_SPEED;
59
int pack_compression_level = Z_DEFAULT_COMPRESSION;
60
int fsync_object_files = -1;
61
int use_fsync = -1;
62
enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
63
enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;
64
char *editor_program;
65
char *askpass_program;
66
char *excludes_file;
67
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
68
enum eol core_eol = EOL_UNSET;
69
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
70
char *check_roundtrip_encoding;
71
enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
72
enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
73
enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
74
#ifndef OBJECT_CREATION_MODE
75
#define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
76
#endif
77
enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
78
int grafts_keep_true_parents;
79
int core_apply_sparse_checkout;
80
int core_sparse_checkout_cone;
81
int sparse_expect_files_outside_of_patterns;
82
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
83
unsigned long pack_size_limit_cfg;
84
85
#ifndef PROTECT_HFS_DEFAULT
86
#define PROTECT_HFS_DEFAULT 0
87
#endif
88
int protect_hfs = PROTECT_HFS_DEFAULT;
89
90
#ifndef PROTECT_NTFS_DEFAULT
91
#define PROTECT_NTFS_DEFAULT 1
92
#endif
93
int protect_ntfs = PROTECT_NTFS_DEFAULT;
94
95
/*
96
 * The character that begins a commented line in user-editable file
97
 * that is subject to stripspace.
98
 */
99
const char *comment_line_str = "#";
100
char *comment_line_str_to_free;
101
#ifndef WITH_BREAKING_CHANGES
102
int auto_comment_line_char;
103
bool warn_on_auto_comment_char;
104
#endif /* !WITH_BREAKING_CHANGES */
105
106
/* This is set by setup_git_directory_gently() and/or git_default_config() */
107
char *git_work_tree_cfg;
108
109
/*
110
 * Repository-local GIT_* environment variables; see environment.h for details.
111
 */
112
const char * const local_repo_env[] = {
113
  ALTERNATE_DB_ENVIRONMENT,
114
  CONFIG_ENVIRONMENT,
115
  CONFIG_DATA_ENVIRONMENT,
116
  CONFIG_COUNT_ENVIRONMENT,
117
  DB_ENVIRONMENT,
118
  GIT_DIR_ENVIRONMENT,
119
  GIT_WORK_TREE_ENVIRONMENT,
120
  GIT_IMPLICIT_WORK_TREE_ENVIRONMENT,
121
  GRAFT_ENVIRONMENT,
122
  INDEX_ENVIRONMENT,
123
  NO_REPLACE_OBJECTS_ENVIRONMENT,
124
  GIT_REPLACE_REF_BASE_ENVIRONMENT,
125
  GIT_PREFIX_ENVIRONMENT,
126
  GIT_SHALLOW_FILE_ENVIRONMENT,
127
  GIT_COMMON_DIR_ENVIRONMENT,
128
  NULL
129
};
130
131
const char *getenv_safe(struct strvec *argv, const char *name)
132
0
{
133
0
  const char *value = getenv(name);
134
135
0
  if (!value)
136
0
    return NULL;
137
138
0
  strvec_push(argv, value);
139
0
  return argv->v[argv->nr - 1];
140
0
}
141
142
int is_bare_repository(void)
143
0
{
144
  /* if core.bare is not 'false', let's see if there is a work tree */
145
0
  return is_bare_repository_cfg && !repo_get_work_tree(the_repository);
146
0
}
147
148
int have_git_dir(void)
149
0
{
150
0
  return startup_info->have_repository
151
0
    || the_repository->gitdir;
152
0
}
153
154
const char *get_git_namespace(void)
155
0
{
156
0
  static const char *namespace;
157
0
  struct strbuf buf = STRBUF_INIT;
158
0
  const char *raw_namespace;
159
0
  struct string_list components = STRING_LIST_INIT_DUP;
160
0
  struct string_list_item *item;
161
162
0
  if (namespace)
163
0
    return namespace;
164
165
0
  raw_namespace = getenv(GIT_NAMESPACE_ENVIRONMENT);
166
0
  if (!raw_namespace || !*raw_namespace) {
167
0
    namespace = "";
168
0
    return namespace;
169
0
  }
170
171
0
  strbuf_addstr(&buf, raw_namespace);
172
173
0
  string_list_split(&components, buf.buf, "/", -1);
174
0
  strbuf_reset(&buf);
175
176
0
  for_each_string_list_item(item, &components) {
177
0
    if (item->string[0])
178
0
      strbuf_addf(&buf, "refs/namespaces/%s/", item->string);
179
0
  }
180
0
  string_list_clear(&components, 0);
181
182
0
  strbuf_trim_trailing_dir_sep(&buf);
183
0
  if (check_refname_format(buf.buf, 0))
184
0
    die(_("bad git namespace path \"%s\""), raw_namespace);
185
0
  strbuf_addch(&buf, '/');
186
187
0
  namespace = strbuf_detach(&buf, NULL);
188
189
0
  return namespace;
190
0
}
191
192
const char *strip_namespace(const char *namespaced_ref)
193
0
{
194
0
  const char *out;
195
0
  if (skip_prefix(namespaced_ref, get_git_namespace(), &out))
196
0
    return out;
197
0
  return NULL;
198
0
}
199
200
const char *get_log_output_encoding(void)
201
0
{
202
0
  return git_log_output_encoding ? git_log_output_encoding
203
0
    : get_commit_output_encoding();
204
0
}
205
206
const char *get_commit_output_encoding(void)
207
0
{
208
0
  return git_commit_encoding ? git_commit_encoding : "UTF-8";
209
0
}
210
211
int use_optional_locks(void)
212
0
{
213
0
  return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT, 1);
214
0
}
215
216
int print_sha1_ellipsis(void)
217
0
{
218
  /*
219
   * Determine if the calling environment contains the variable
220
   * GIT_PRINT_SHA1_ELLIPSIS set to "yes".
221
   */
222
0
  static int cached_result = -1; /* unknown */
223
224
0
  if (cached_result < 0) {
225
0
    const char *v = getenv("GIT_PRINT_SHA1_ELLIPSIS");
226
0
    cached_result = (v && !strcasecmp(v, "yes"));
227
0
  }
228
0
  return cached_result;
229
0
}
230
231
static const struct fsync_component_name {
232
  const char *name;
233
  enum fsync_component component_bits;
234
} fsync_component_names[] = {
235
  { "loose-object", FSYNC_COMPONENT_LOOSE_OBJECT },
236
  { "pack", FSYNC_COMPONENT_PACK },
237
  { "pack-metadata", FSYNC_COMPONENT_PACK_METADATA },
238
  { "commit-graph", FSYNC_COMPONENT_COMMIT_GRAPH },
239
  { "index", FSYNC_COMPONENT_INDEX },
240
  { "objects", FSYNC_COMPONENTS_OBJECTS },
241
  { "reference", FSYNC_COMPONENT_REFERENCE },
242
  { "derived-metadata", FSYNC_COMPONENTS_DERIVED_METADATA },
243
  { "committed", FSYNC_COMPONENTS_COMMITTED },
244
  { "added", FSYNC_COMPONENTS_ADDED },
245
  { "all", FSYNC_COMPONENTS_ALL },
246
};
247
248
static enum fsync_component parse_fsync_components(const char *var, const char *string)
249
0
{
250
0
  enum fsync_component current = FSYNC_COMPONENTS_PLATFORM_DEFAULT;
251
0
  enum fsync_component positive = 0, negative = 0;
252
253
0
  while (string) {
254
0
    size_t len;
255
0
    const char *ep;
256
0
    int negated = 0;
257
0
    int found = 0;
258
259
0
    string = string + strspn(string, ", \t\n\r");
260
0
    ep = strchrnul(string, ',');
261
0
    len = ep - string;
262
0
    if (!strcmp(string, "none")) {
263
0
      current = FSYNC_COMPONENT_NONE;
264
0
      goto next_name;
265
0
    }
266
267
0
    if (*string == '-') {
268
0
      negated = 1;
269
0
      string++;
270
0
      len--;
271
0
      if (!len)
272
0
        warning(_("invalid value for variable %s"), var);
273
0
    }
274
275
0
    if (!len)
276
0
      break;
277
278
0
    for (size_t i = 0; i < ARRAY_SIZE(fsync_component_names); ++i) {
279
0
      const struct fsync_component_name *n = &fsync_component_names[i];
280
281
0
      if (strncmp(n->name, string, len))
282
0
        continue;
283
284
0
      found = 1;
285
0
      if (negated)
286
0
        negative |= n->component_bits;
287
0
      else
288
0
        positive |= n->component_bits;
289
0
    }
290
291
0
    if (!found) {
292
0
      char *component = xstrndup(string, len);
293
0
      warning(_("ignoring unknown core.fsync component '%s'"), component);
294
0
      free(component);
295
0
    }
296
297
0
next_name:
298
0
    string = ep;
299
0
  }
300
301
0
  return (current & ~negative) | positive;
302
0
}
303
304
int git_default_core_config(const char *var, const char *value,
305
          const struct config_context *ctx, void *cb)
306
0
{
307
  /* This needs a better name */
308
0
  if (!strcmp(var, "core.filemode")) {
309
0
    trust_executable_bit = git_config_bool(var, value);
310
0
    return 0;
311
0
  }
312
0
  if (!strcmp(var, "core.trustctime")) {
313
0
    trust_ctime = git_config_bool(var, value);
314
0
    return 0;
315
0
  }
316
0
  if (!strcmp(var, "core.checkstat")) {
317
0
    if (!value)
318
0
      return config_error_nonbool(var);
319
0
    if (!strcasecmp(value, "default"))
320
0
      check_stat = 1;
321
0
    else if (!strcasecmp(value, "minimal"))
322
0
      check_stat = 0;
323
0
    else
324
0
      return error(_("invalid value for '%s': '%s'"),
325
0
             var, value);
326
0
  }
327
328
0
  if (!strcmp(var, "core.quotepath")) {
329
0
    quote_path_fully = git_config_bool(var, value);
330
0
    return 0;
331
0
  }
332
333
0
  if (!strcmp(var, "core.symlinks")) {
334
0
    has_symlinks = git_config_bool(var, value);
335
0
    return 0;
336
0
  }
337
338
0
  if (!strcmp(var, "core.ignorecase")) {
339
0
    ignore_case = git_config_bool(var, value);
340
0
    return 0;
341
0
  }
342
343
0
  if (!strcmp(var, "core.attributesfile")) {
344
0
    FREE_AND_NULL(git_attributes_file);
345
0
    return git_config_pathname(&git_attributes_file, var, value);
346
0
  }
347
348
0
  if (!strcmp(var, "core.bare")) {
349
0
    is_bare_repository_cfg = git_config_bool(var, value);
350
0
    return 0;
351
0
  }
352
353
0
  if (!strcmp(var, "core.ignorestat")) {
354
0
    assume_unchanged = git_config_bool(var, value);
355
0
    return 0;
356
0
  }
357
358
0
  if (!strcmp(var, "core.abbrev")) {
359
0
    if (!value)
360
0
      return config_error_nonbool(var);
361
0
    if (!strcasecmp(value, "auto"))
362
0
      default_abbrev = -1;
363
0
    else if (!git_parse_maybe_bool_text(value))
364
0
      default_abbrev = GIT_MAX_HEXSZ;
365
0
    else {
366
0
      int abbrev = git_config_int(var, value, ctx->kvi);
367
0
      if (abbrev < minimum_abbrev)
368
0
        return error(_("abbrev length out of range: %d"), abbrev);
369
0
      default_abbrev = abbrev;
370
0
    }
371
0
    return 0;
372
0
  }
373
374
0
  if (!strcmp(var, "core.disambiguate"))
375
0
    return set_disambiguate_hint_config(var, value);
376
377
0
  if (!strcmp(var, "core.loosecompression")) {
378
0
    int level = git_config_int(var, value, ctx->kvi);
379
0
    if (level == -1)
380
0
      level = Z_DEFAULT_COMPRESSION;
381
0
    else if (level < 0 || level > Z_BEST_COMPRESSION)
382
0
      die(_("bad zlib compression level %d"), level);
383
0
    zlib_compression_level = level;
384
0
    zlib_compression_seen = 1;
385
0
    return 0;
386
0
  }
387
388
0
  if (!strcmp(var, "core.compression")) {
389
0
    int level = git_config_int(var, value, ctx->kvi);
390
0
    if (level == -1)
391
0
      level = Z_DEFAULT_COMPRESSION;
392
0
    else if (level < 0 || level > Z_BEST_COMPRESSION)
393
0
      die(_("bad zlib compression level %d"), level);
394
0
    if (!zlib_compression_seen)
395
0
      zlib_compression_level = level;
396
0
    if (!pack_compression_seen)
397
0
      pack_compression_level = level;
398
0
    return 0;
399
0
  }
400
401
0
  if (!strcmp(var, "core.autocrlf")) {
402
0
    if (value && !strcasecmp(value, "input")) {
403
0
      auto_crlf = AUTO_CRLF_INPUT;
404
0
      return 0;
405
0
    }
406
0
    auto_crlf = git_config_bool(var, value);
407
0
    return 0;
408
0
  }
409
410
0
  if (!strcmp(var, "core.safecrlf")) {
411
0
    int eol_rndtrp_die;
412
0
    if (value && !strcasecmp(value, "warn")) {
413
0
      global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
414
0
      return 0;
415
0
    }
416
0
    eol_rndtrp_die = git_config_bool(var, value);
417
0
    global_conv_flags_eol = eol_rndtrp_die ?
418
0
      CONV_EOL_RNDTRP_DIE : 0;
419
0
    return 0;
420
0
  }
421
422
0
  if (!strcmp(var, "core.eol")) {
423
0
    if (value && !strcasecmp(value, "lf"))
424
0
      core_eol = EOL_LF;
425
0
    else if (value && !strcasecmp(value, "crlf"))
426
0
      core_eol = EOL_CRLF;
427
0
    else if (value && !strcasecmp(value, "native"))
428
0
      core_eol = EOL_NATIVE;
429
0
    else
430
0
      core_eol = EOL_UNSET;
431
0
    return 0;
432
0
  }
433
434
0
  if (!strcmp(var, "core.checkroundtripencoding")) {
435
0
    FREE_AND_NULL(check_roundtrip_encoding);
436
0
    return git_config_string(&check_roundtrip_encoding, var, value);
437
0
  }
438
439
0
  if (!strcmp(var, "core.editor")) {
440
0
    FREE_AND_NULL(editor_program);
441
0
    return git_config_string(&editor_program, var, value);
442
0
  }
443
444
0
  if (!strcmp(var, "core.commentchar") ||
445
0
      !strcmp(var, "core.commentstring")) {
446
0
    if (!value) {
447
0
      return config_error_nonbool(var);
448
0
#ifndef WITH_BREAKING_CHANGES
449
0
    } else if (!strcasecmp(value, "auto")) {
450
0
      auto_comment_line_char = 1;
451
0
      FREE_AND_NULL(comment_line_str_to_free);
452
0
      comment_line_str = "#";
453
0
#endif /* !WITH_BREAKING_CHANGES */
454
0
    } else if (value[0]) {
455
0
      if (strchr(value, '\n'))
456
0
        return error(_("%s cannot contain newline"), var);
457
0
      comment_line_str = value;
458
0
      FREE_AND_NULL(comment_line_str_to_free);
459
0
#ifndef WITH_BREAKING_CHANGES
460
0
      auto_comment_line_char = 0;
461
0
#endif /* !WITH_BREAKING_CHANGES */
462
0
    } else
463
0
      return error(_("%s must have at least one character"), var);
464
0
    return 0;
465
0
  }
466
467
0
  if (!strcmp(var, "core.askpass")) {
468
0
    FREE_AND_NULL(askpass_program);
469
0
    return git_config_string(&askpass_program, var, value);
470
0
  }
471
472
0
  if (!strcmp(var, "core.excludesfile")) {
473
0
    FREE_AND_NULL(excludes_file);
474
0
    return git_config_pathname(&excludes_file, var, value);
475
0
  }
476
477
0
  if (!strcmp(var, "core.whitespace")) {
478
0
    if (!value)
479
0
      return config_error_nonbool(var);
480
0
    whitespace_rule_cfg = parse_whitespace_rule(value);
481
0
    return 0;
482
0
  }
483
484
0
  if (!strcmp(var, "core.fsync")) {
485
0
    if (!value)
486
0
      return config_error_nonbool(var);
487
0
    fsync_components = parse_fsync_components(var, value);
488
0
    return 0;
489
0
  }
490
491
0
  if (!strcmp(var, "core.fsyncmethod")) {
492
0
    if (!value)
493
0
      return config_error_nonbool(var);
494
0
    if (!strcmp(value, "fsync"))
495
0
      fsync_method = FSYNC_METHOD_FSYNC;
496
0
    else if (!strcmp(value, "writeout-only"))
497
0
      fsync_method = FSYNC_METHOD_WRITEOUT_ONLY;
498
0
    else if (!strcmp(value, "batch"))
499
0
      fsync_method = FSYNC_METHOD_BATCH;
500
0
    else
501
0
      warning(_("ignoring unknown core.fsyncMethod value '%s'"), value);
502
503
0
  }
504
505
0
  if (!strcmp(var, "core.fsyncobjectfiles")) {
506
0
    if (fsync_object_files < 0)
507
0
      warning(_("core.fsyncObjectFiles is deprecated; use core.fsync instead"));
508
0
    fsync_object_files = git_config_bool(var, value);
509
0
    return 0;
510
0
  }
511
512
0
  if (!strcmp(var, "core.lockfilepid")) {
513
0
    lockfile_pid_enabled = git_config_bool(var, value);
514
0
    return 0;
515
0
  }
516
517
0
  if (!strcmp(var, "core.createobject")) {
518
0
    if (!value)
519
0
      return config_error_nonbool(var);
520
0
    if (!strcmp(value, "rename"))
521
0
      object_creation_mode = OBJECT_CREATION_USES_RENAMES;
522
0
    else if (!strcmp(value, "link"))
523
0
      object_creation_mode = OBJECT_CREATION_USES_HARDLINKS;
524
0
    else
525
0
      die(_("invalid mode for object creation: %s"), value);
526
0
    return 0;
527
0
  }
528
529
0
  if (!strcmp(var, "core.sparsecheckout")) {
530
0
    core_apply_sparse_checkout = git_config_bool(var, value);
531
0
    return 0;
532
0
  }
533
534
0
  if (!strcmp(var, "core.sparsecheckoutcone")) {
535
0
    core_sparse_checkout_cone = git_config_bool(var, value);
536
0
    return 0;
537
0
  }
538
539
0
  if (!strcmp(var, "core.precomposeunicode")) {
540
0
    precomposed_unicode = git_config_bool(var, value);
541
0
    return 0;
542
0
  }
543
544
0
  if (!strcmp(var, "core.protecthfs")) {
545
0
    protect_hfs = git_config_bool(var, value);
546
0
    return 0;
547
0
  }
548
549
0
  if (!strcmp(var, "core.protectntfs")) {
550
0
    protect_ntfs = git_config_bool(var, value);
551
0
    return 0;
552
0
  }
553
554
  /* Add other config variables here and to Documentation/config.adoc. */
555
0
  return platform_core_config(var, value, ctx, cb);
556
0
}
557
558
static int git_default_sparse_config(const char *var, const char *value)
559
0
{
560
0
  if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) {
561
0
    sparse_expect_files_outside_of_patterns = git_config_bool(var, value);
562
0
    return 0;
563
0
  }
564
565
  /* Add other config variables here and to Documentation/config/sparse.adoc. */
566
0
  return 0;
567
0
}
568
569
static int git_default_i18n_config(const char *var, const char *value)
570
0
{
571
0
  if (!strcmp(var, "i18n.commitencoding")) {
572
0
    FREE_AND_NULL(git_commit_encoding);
573
0
    return git_config_string(&git_commit_encoding, var, value);
574
0
  }
575
576
0
  if (!strcmp(var, "i18n.logoutputencoding")) {
577
0
    FREE_AND_NULL(git_log_output_encoding);
578
0
    return git_config_string(&git_log_output_encoding, var, value);
579
0
  }
580
581
  /* Add other config variables here and to Documentation/config.adoc. */
582
0
  return 0;
583
0
}
584
585
static int git_default_branch_config(const char *var, const char *value)
586
0
{
587
0
  if (!strcmp(var, "branch.autosetupmerge")) {
588
0
    if (value && !strcmp(value, "always")) {
589
0
      git_branch_track = BRANCH_TRACK_ALWAYS;
590
0
      return 0;
591
0
    } else if (value && !strcmp(value, "inherit")) {
592
0
      git_branch_track = BRANCH_TRACK_INHERIT;
593
0
      return 0;
594
0
    } else if (value && !strcmp(value, "simple")) {
595
0
      git_branch_track = BRANCH_TRACK_SIMPLE;
596
0
      return 0;
597
0
    }
598
0
    git_branch_track = git_config_bool(var, value);
599
0
    return 0;
600
0
  }
601
0
  if (!strcmp(var, "branch.autosetuprebase")) {
602
0
    if (!value)
603
0
      return config_error_nonbool(var);
604
0
    else if (!strcmp(value, "never"))
605
0
      autorebase = AUTOREBASE_NEVER;
606
0
    else if (!strcmp(value, "local"))
607
0
      autorebase = AUTOREBASE_LOCAL;
608
0
    else if (!strcmp(value, "remote"))
609
0
      autorebase = AUTOREBASE_REMOTE;
610
0
    else if (!strcmp(value, "always"))
611
0
      autorebase = AUTOREBASE_ALWAYS;
612
0
    else
613
0
      return error(_("malformed value for %s"), var);
614
0
    return 0;
615
0
  }
616
617
  /* Add other config variables here and to Documentation/config.adoc. */
618
0
  return 0;
619
0
}
620
621
static int git_default_push_config(const char *var, const char *value)
622
0
{
623
0
  if (!strcmp(var, "push.default")) {
624
0
    if (!value)
625
0
      return config_error_nonbool(var);
626
0
    else if (!strcmp(value, "nothing"))
627
0
      push_default = PUSH_DEFAULT_NOTHING;
628
0
    else if (!strcmp(value, "matching"))
629
0
      push_default = PUSH_DEFAULT_MATCHING;
630
0
    else if (!strcmp(value, "simple"))
631
0
      push_default = PUSH_DEFAULT_SIMPLE;
632
0
    else if (!strcmp(value, "upstream"))
633
0
      push_default = PUSH_DEFAULT_UPSTREAM;
634
0
    else if (!strcmp(value, "tracking")) /* deprecated */
635
0
      push_default = PUSH_DEFAULT_UPSTREAM;
636
0
    else if (!strcmp(value, "current"))
637
0
      push_default = PUSH_DEFAULT_CURRENT;
638
0
    else {
639
0
      error(_("malformed value for %s: %s"), var, value);
640
0
      return error(_("must be one of nothing, matching, simple, "
641
0
               "upstream or current"));
642
0
    }
643
0
    return 0;
644
0
  }
645
646
  /* Add other config variables here and to Documentation/config.adoc. */
647
0
  return 0;
648
0
}
649
650
static int git_default_mailmap_config(const char *var, const char *value)
651
0
{
652
0
  if (!strcmp(var, "mailmap.file")) {
653
0
    FREE_AND_NULL(git_mailmap_file);
654
0
    return git_config_pathname(&git_mailmap_file, var, value);
655
0
  }
656
657
0
  if (!strcmp(var, "mailmap.blob")) {
658
0
    FREE_AND_NULL(git_mailmap_blob);
659
0
    return git_config_string(&git_mailmap_blob, var, value);
660
0
  }
661
662
  /* Add other config variables here and to Documentation/config.adoc. */
663
0
  return 0;
664
0
}
665
666
static int git_default_attr_config(const char *var, const char *value)
667
0
{
668
0
  if (!strcmp(var, "attr.tree")) {
669
0
    FREE_AND_NULL(git_attr_tree);
670
0
    return git_config_string(&git_attr_tree, var, value);
671
0
  }
672
673
  /*
674
   * Add other attribute related config variables here and to
675
   * Documentation/config/attr.adoc.
676
   */
677
0
  return 0;
678
0
}
679
680
int git_default_config(const char *var, const char *value,
681
           const struct config_context *ctx, void *cb)
682
0
{
683
0
  if (starts_with(var, "core."))
684
0
    return git_default_core_config(var, value, ctx, cb);
685
686
0
  if (starts_with(var, "user.") ||
687
0
      starts_with(var, "author.") ||
688
0
      starts_with(var, "committer."))
689
0
    return git_ident_config(var, value, ctx, cb);
690
691
0
  if (starts_with(var, "i18n."))
692
0
    return git_default_i18n_config(var, value);
693
694
0
  if (starts_with(var, "branch."))
695
0
    return git_default_branch_config(var, value);
696
697
0
  if (starts_with(var, "push."))
698
0
    return git_default_push_config(var, value);
699
700
0
  if (starts_with(var, "mailmap."))
701
0
    return git_default_mailmap_config(var, value);
702
703
0
  if (starts_with(var, "attr."))
704
0
    return git_default_attr_config(var, value);
705
706
0
  if (starts_with(var, "advice.") || starts_with(var, "color.advice"))
707
0
    return git_default_advice_config(var, value);
708
709
0
  if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
710
0
    pager_use_color = git_config_bool(var,value);
711
0
    return 0;
712
0
  }
713
714
0
  if (!strcmp(var, "pack.packsizelimit")) {
715
0
    pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi);
716
0
    return 0;
717
0
  }
718
719
0
  if (!strcmp(var, "pack.compression")) {
720
0
    int level = git_config_int(var, value, ctx->kvi);
721
0
    if (level == -1)
722
0
      level = Z_DEFAULT_COMPRESSION;
723
0
    else if (level < 0 || level > Z_BEST_COMPRESSION)
724
0
      die(_("bad pack compression level %d"), level);
725
0
    pack_compression_level = level;
726
0
    pack_compression_seen = 1;
727
0
    return 0;
728
0
  }
729
730
0
  if (starts_with(var, "sparse."))
731
0
    return git_default_sparse_config(var, value);
732
733
  /* Add other config variables here and to Documentation/config.adoc. */
734
0
  return 0;
735
0
}