rugged 0.26.0b5 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged.c +24 -0
  3. data/ext/rugged/rugged.h +2 -0
  4. data/ext/rugged/rugged_signature.c +15 -2
  5. data/lib/rugged/version.rb +1 -1
  6. data/vendor/libgit2/CMakeLists.txt +9 -8
  7. data/vendor/libgit2/include/git2/common.h +29 -0
  8. data/vendor/libgit2/include/git2/errors.h +2 -0
  9. data/vendor/libgit2/include/git2/global.h +1 -1
  10. data/vendor/libgit2/include/git2/odb.h +2 -2
  11. data/vendor/libgit2/include/git2/odb_backend.h +1 -1
  12. data/vendor/libgit2/include/git2/remote.h +3 -3
  13. data/vendor/libgit2/include/git2/repository.h +2 -2
  14. data/vendor/libgit2/include/git2/sys/filter.h +11 -0
  15. data/vendor/libgit2/include/git2/sys/merge.h +5 -5
  16. data/vendor/libgit2/include/git2/sys/transport.h +10 -0
  17. data/vendor/libgit2/include/git2/transport.h +6 -6
  18. data/vendor/libgit2/include/git2/version.h +3 -3
  19. data/vendor/libgit2/include/git2/worktree.h +69 -10
  20. data/vendor/libgit2/libgit2.pc.in +2 -2
  21. data/vendor/libgit2/src/attr_file.c +6 -2
  22. data/vendor/libgit2/src/attrcache.c +7 -5
  23. data/vendor/libgit2/src/blame_git.c +12 -8
  24. data/vendor/libgit2/src/branch.c +17 -48
  25. data/vendor/libgit2/src/buffer.c +11 -12
  26. data/vendor/libgit2/src/buffer.h +2 -2
  27. data/vendor/libgit2/src/checkout.c +3 -6
  28. data/vendor/libgit2/src/config.c +42 -35
  29. data/vendor/libgit2/src/config_cache.c +1 -0
  30. data/vendor/libgit2/src/config_file.c +19 -11
  31. data/vendor/libgit2/src/config_file.h +1 -0
  32. data/vendor/libgit2/src/diff.c +35 -0
  33. data/vendor/libgit2/src/diff_parse.c +7 -1
  34. data/vendor/libgit2/src/filebuf.c +12 -1
  35. data/vendor/libgit2/src/filebuf.h +3 -1
  36. data/vendor/libgit2/src/fileops.c +83 -22
  37. data/vendor/libgit2/src/fileops.h +25 -0
  38. data/vendor/libgit2/src/filter.c +30 -14
  39. data/vendor/libgit2/src/global.c +1 -1
  40. data/vendor/libgit2/src/hash/hash_collisiondetect.h +1 -11
  41. data/vendor/libgit2/src/hash/sha1dc/sha1.c +894 -187
  42. data/vendor/libgit2/src/hash/sha1dc/sha1.h +69 -53
  43. data/vendor/libgit2/src/hash/sha1dc/ubc_check.c +13 -2
  44. data/vendor/libgit2/src/hash/sha1dc/ubc_check.h +20 -3
  45. data/vendor/libgit2/src/idxmap.c +1 -1
  46. data/vendor/libgit2/src/idxmap.h +1 -2
  47. data/vendor/libgit2/src/index.c +75 -42
  48. data/vendor/libgit2/src/indexer.c +31 -11
  49. data/vendor/libgit2/src/indexer.h +12 -0
  50. data/vendor/libgit2/src/merge.c +20 -0
  51. data/vendor/libgit2/src/merge_driver.c +29 -0
  52. data/vendor/libgit2/src/odb.c +96 -19
  53. data/vendor/libgit2/src/odb.h +25 -0
  54. data/vendor/libgit2/src/odb_loose.c +20 -6
  55. data/vendor/libgit2/src/odb_pack.c +1 -1
  56. data/vendor/libgit2/src/offmap.c +1 -1
  57. data/vendor/libgit2/src/offmap.h +1 -2
  58. data/vendor/libgit2/src/oidmap.c +1 -1
  59. data/vendor/libgit2/src/oidmap.h +1 -2
  60. data/vendor/libgit2/src/openssl_stream.c +11 -4
  61. data/vendor/libgit2/src/pack-objects.c +4 -0
  62. data/vendor/libgit2/src/pack-objects.h +1 -0
  63. data/vendor/libgit2/src/pack.c +5 -3
  64. data/vendor/libgit2/src/patch_generate.c +8 -79
  65. data/vendor/libgit2/src/patch_parse.c +5 -4
  66. data/vendor/libgit2/src/path.c +9 -7
  67. data/vendor/libgit2/src/posix.c +2 -0
  68. data/vendor/libgit2/src/posix.h +10 -0
  69. data/vendor/libgit2/src/rebase.c +12 -10
  70. data/vendor/libgit2/src/refdb_fs.c +33 -10
  71. data/vendor/libgit2/src/refs.c +89 -8
  72. data/vendor/libgit2/src/refs.h +14 -0
  73. data/vendor/libgit2/src/remote.c +9 -10
  74. data/vendor/libgit2/src/repository.c +178 -146
  75. data/vendor/libgit2/src/repository.h +25 -0
  76. data/vendor/libgit2/src/revparse.c +22 -3
  77. data/vendor/libgit2/src/revwalk.c +6 -3
  78. data/vendor/libgit2/src/settings.c +22 -1
  79. data/vendor/libgit2/src/signature.c +4 -1
  80. data/vendor/libgit2/src/socket_stream.c +2 -4
  81. data/vendor/libgit2/src/strmap.c +1 -1
  82. data/vendor/libgit2/src/strmap.h +1 -3
  83. data/vendor/libgit2/src/submodule.c +27 -7
  84. data/vendor/libgit2/src/sysdir.c +11 -0
  85. data/vendor/libgit2/src/sysdir.h +12 -0
  86. data/vendor/libgit2/src/transports/http.c +3 -0
  87. data/vendor/libgit2/src/transports/smart.c +6 -0
  88. data/vendor/libgit2/src/transports/smart_protocol.c +2 -1
  89. data/vendor/libgit2/src/transports/ssh.c +13 -1
  90. data/vendor/libgit2/src/transports/winhttp.c +1 -2
  91. data/vendor/libgit2/src/tree.c +13 -11
  92. data/vendor/libgit2/src/unix/posix.h +6 -1
  93. data/vendor/libgit2/src/varint.c +1 -1
  94. data/vendor/libgit2/src/win32/posix.h +3 -0
  95. data/vendor/libgit2/src/win32/posix_w32.c +334 -111
  96. data/vendor/libgit2/src/worktree.c +174 -48
  97. data/vendor/libgit2/src/worktree.h +1 -1
  98. metadata +77 -76
@@ -1,4 +1,4 @@
1
- prefix=@PKGCONFIG_PREFIX@
1
+ prefix="@PKGCONFIG_PREFIX@"
2
2
  libdir=@PKGCONFIG_LIBDIR@
3
3
  includedir=@PKGCONFIG_INCLUDEDIR@
4
4
 
@@ -6,7 +6,7 @@ Name: libgit2
6
6
  Description: The git library, take 2
7
7
  Version: @LIBGIT2_VERSION_STRING@
8
8
 
9
- Libs: -L"${libdir}" -lgit2
9
+ Libs: -L${libdir} -lgit2
10
10
  Libs.private: @LIBGIT2_PC_LIBS@
11
11
  Requires.private: @LIBGIT2_PC_REQUIRES@
12
12
 
@@ -395,9 +395,13 @@ bool git_attr_fnmatch__match(
395
395
  if ((match->flags & GIT_ATTR_FNMATCH_DIRECTORY) && !path->is_dir) {
396
396
  bool samename;
397
397
 
398
- /* for attribute checks or root ignore checks, fail match */
398
+ /*
399
+ * for attribute checks or checks at the root of this match's
400
+ * containing_dir (or root of the repository if no containing_dir),
401
+ * do not match.
402
+ */
399
403
  if (!(match->flags & GIT_ATTR_FNMATCH_IGNORE) ||
400
- path->basename == path->path)
404
+ path->basename == relpath)
401
405
  return false;
402
406
 
403
407
  flags |= FNM_LEADING_DIR;
@@ -290,14 +290,16 @@ static int attr_cache__lookup_path(
290
290
  const char *cfgval = entry->value;
291
291
 
292
292
  /* expand leading ~/ as needed */
293
- if (cfgval && cfgval[0] == '~' && cfgval[1] == '/' &&
294
- !git_sysdir_find_global_file(&buf, &cfgval[2]))
295
- *out = git_buf_detach(&buf);
296
- else if (cfgval)
293
+ if (cfgval && cfgval[0] == '~' && cfgval[1] == '/') {
294
+ if (! (error = git_sysdir_expand_global_file(&buf, &cfgval[2])))
295
+ *out = git_buf_detach(&buf);
296
+ } else if (cfgval) {
297
297
  *out = git__strdup(cfgval);
298
+ }
298
299
  }
299
- else if (!git_sysdir_find_xdg_file(&buf, fallback))
300
+ else if (!git_sysdir_find_xdg_file(&buf, fallback)) {
300
301
  *out = git_buf_detach(&buf);
302
+ }
301
303
 
302
304
  git_config_entry_free(entry);
303
305
  git_buf_free(&buf);
@@ -478,14 +478,15 @@ cleanup:
478
478
  * The blobs of origin and porigin exactly match, so everything origin is
479
479
  * suspected for can be blamed on the parent.
480
480
  */
481
- static void pass_whole_blame(git_blame *blame,
481
+ static int pass_whole_blame(git_blame *blame,
482
482
  git_blame__origin *origin, git_blame__origin *porigin)
483
483
  {
484
484
  git_blame__entry *e;
485
485
 
486
- if (!porigin->blob)
487
- git_object_lookup((git_object**)&porigin->blob, blame->repository,
488
- git_blob_id(origin->blob), GIT_OBJ_BLOB);
486
+ if (!porigin->blob &&
487
+ git_object_lookup((git_object**)&porigin->blob, blame->repository,
488
+ git_blob_id(origin->blob), GIT_OBJ_BLOB) < 0)
489
+ return -1;
489
490
  for (e=blame->ent; e; e=e->next) {
490
491
  if (!same_suspect(e->suspect, origin))
491
492
  continue;
@@ -493,6 +494,8 @@ static void pass_whole_blame(git_blame *blame,
493
494
  origin_decref(e->suspect);
494
495
  e->suspect = porigin;
495
496
  }
497
+
498
+ return 0;
496
499
  }
497
500
 
498
501
  static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
@@ -514,11 +517,12 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
514
517
  if (!num_parents) {
515
518
  git_oid_cpy(&blame->options.oldest_commit, git_commit_id(commit));
516
519
  goto finish;
517
- }
518
- else if (num_parents < (int)ARRAY_SIZE(sg_buf))
520
+ } else if (num_parents < (int)ARRAY_SIZE(sg_buf))
519
521
  memset(sg_buf, 0, sizeof(sg_buf));
520
- else
522
+ else {
521
523
  sg_origin = git__calloc(num_parents, sizeof(*sg_origin));
524
+ GITERR_CHECK_ALLOC(sg_origin);
525
+ }
522
526
 
523
527
  for (i=0; i<num_parents; i++) {
524
528
  git_commit *p;
@@ -543,7 +547,7 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
543
547
  }
544
548
  if (porigin->blob && origin->blob &&
545
549
  !git_oid_cmp(git_blob_id(porigin->blob), git_blob_id(origin->blob))) {
546
- pass_whole_blame(blame, origin, porigin);
550
+ error = pass_whole_blame(blame, origin, porigin);
547
551
  origin_decref(porigin);
548
552
  goto finish;
549
553
  }
@@ -127,62 +127,31 @@ int git_branch_create_from_annotated(
127
127
  repository, branch_name, commit->commit, commit->description, force);
128
128
  }
129
129
 
130
- int git_branch_is_checked_out(
131
- const git_reference *branch)
130
+ static int branch_equals(git_repository *repo, const char *path, void *payload)
132
131
  {
133
- git_buf path = GIT_BUF_INIT, buf = GIT_BUF_INIT;
134
- git_strarray worktrees;
135
- git_reference *ref = NULL;
136
- git_repository *repo;
137
- const char *worktree;
138
- int found = false;
139
- size_t i;
140
-
141
- assert(branch && git_reference_is_branch(branch));
142
-
143
- repo = git_reference_owner(branch);
132
+ git_reference *branch = (git_reference *) payload;
133
+ git_reference *head = NULL;
134
+ int equal = 0;
144
135
 
145
- if (git_worktree_list(&worktrees, repo) < 0)
146
- return -1;
147
-
148
- for (i = 0; i < worktrees.count; i++) {
149
- worktree = worktrees.strings[i];
150
-
151
- if (git_repository_head_for_worktree(&ref, repo, worktree) < 0)
152
- continue;
153
-
154
- if (git__strcmp(ref->name, branch->name) == 0) {
155
- found = true;
156
- git_reference_free(ref);
157
- break;
158
- }
159
-
160
- git_reference_free(ref);
161
- }
162
- git_strarray_free(&worktrees);
163
-
164
- if (found)
165
- return found;
136
+ if (git_reference__read_head(&head, repo, path) < 0 ||
137
+ git_reference_type(head) != GIT_REF_SYMBOLIC)
138
+ goto done;
166
139
 
167
- /* Check HEAD of parent */
168
- if (git_buf_joinpath(&path, repo->commondir, GIT_HEAD_FILE) < 0)
169
- goto out;
170
- if (git_futils_readbuffer(&buf, path.ptr) < 0)
171
- goto out;
172
- if (git__prefixcmp(buf.ptr, "ref: ") == 0)
173
- git_buf_consume(&buf, buf.ptr + strlen("ref: "));
174
- git_buf_rtrim(&buf);
140
+ equal = !git__strcmp(head->target.symbolic, branch->name);
175
141
 
176
- found = git__strcmp(buf.ptr, branch->name) == 0;
142
+ done:
143
+ git_reference_free(head);
144
+ return equal;
145
+ }
177
146
 
178
- out:
179
- git_buf_free(&buf);
180
- git_buf_free(&path);
147
+ int git_branch_is_checked_out(const git_reference *branch)
148
+ {
149
+ assert(branch && git_reference_is_branch(branch));
181
150
 
182
- return found;
151
+ return git_repository_foreach_head(git_reference_owner(branch),
152
+ branch_equals, (void *) branch) == 1;
183
153
  }
184
154
 
185
-
186
155
  int git_branch_delete(git_reference *branch)
187
156
  {
188
157
  int is_head;
@@ -18,18 +18,19 @@ char git_buf__initbuf[1];
18
18
  char git_buf__oom[1];
19
19
 
20
20
  #define ENSURE_SIZE(b, d) \
21
- if ((d) > buf->asize && git_buf_grow(b, (d)) < 0)\
21
+ if ((d) > (b)->asize && git_buf_grow((b), (d)) < 0)\
22
22
  return -1;
23
23
 
24
24
 
25
- void git_buf_init(git_buf *buf, size_t initial_size)
25
+ int git_buf_init(git_buf *buf, size_t initial_size)
26
26
  {
27
27
  buf->asize = 0;
28
28
  buf->size = 0;
29
29
  buf->ptr = git_buf__initbuf;
30
30
 
31
- if (initial_size)
32
- git_buf_grow(buf, initial_size);
31
+ ENSURE_SIZE(buf, initial_size);
32
+
33
+ return 0;
33
34
  }
34
35
 
35
36
  int git_buf_try_grow(
@@ -577,7 +578,7 @@ char *git_buf_detach(git_buf *buf)
577
578
  return data;
578
579
  }
579
580
 
580
- void git_buf_attach(git_buf *buf, char *ptr, size_t asize)
581
+ int git_buf_attach(git_buf *buf, char *ptr, size_t asize)
581
582
  {
582
583
  git_buf_free(buf);
583
584
 
@@ -588,9 +589,10 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize)
588
589
  buf->asize = (asize < buf->size) ? buf->size + 1 : asize;
589
590
  else /* pass 0 to fall back on strlen + 1 */
590
591
  buf->asize = buf->size + 1;
591
- } else {
592
- git_buf_grow(buf, asize);
593
592
  }
593
+
594
+ ENSURE_SIZE(buf, asize);
595
+ return 0;
594
596
  }
595
597
 
596
598
  void git_buf_attach_notowned(git_buf *buf, const char *ptr, size_t size)
@@ -724,9 +726,7 @@ int git_buf_join(
724
726
  GITERR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b);
725
727
  GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep);
726
728
  GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
727
- if (git_buf_grow(buf, alloc_len) < 0)
728
- return -1;
729
- assert(buf->ptr);
729
+ ENSURE_SIZE(buf, alloc_len);
730
730
 
731
731
  /* fix up internal pointers */
732
732
  if (offset_a >= 0)
@@ -780,8 +780,7 @@ int git_buf_join3(
780
780
  GITERR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b);
781
781
  GITERR_CHECK_ALLOC_ADD(&len_total, len_total, len_c);
782
782
  GITERR_CHECK_ALLOC_ADD(&len_total, len_total, 1);
783
- if (git_buf_grow(buf, len_total) < 0)
784
- return -1;
783
+ ENSURE_SIZE(buf, len_total);
785
784
 
786
785
  tgt = buf->ptr;
787
786
 
@@ -34,7 +34,7 @@ GIT_INLINE(bool) git_buf_is_allocated(const git_buf *buf)
34
34
  * For the cases where GIT_BUF_INIT cannot be used to do static
35
35
  * initialization.
36
36
  */
37
- extern void git_buf_init(git_buf *buf, size_t initial_size);
37
+ extern int git_buf_init(git_buf *buf, size_t initial_size);
38
38
 
39
39
  /**
40
40
  * Resize the buffer allocation to make more space.
@@ -73,7 +73,7 @@ extern void git_buf_sanitize(git_buf *buf);
73
73
 
74
74
  extern void git_buf_swap(git_buf *buf_a, git_buf *buf_b);
75
75
  extern char *git_buf_detach(git_buf *buf);
76
- extern void git_buf_attach(git_buf *buf, char *ptr, size_t asize);
76
+ extern int git_buf_attach(git_buf *buf, char *ptr, size_t asize);
77
77
 
78
78
  /* Populates a `git_buf` where the contents are not "owned" by the
79
79
  * buffer, and calls to `git_buf_free` will not free the given buf.
@@ -370,10 +370,8 @@ static int checkout_action_wd_only(
370
370
  */
371
371
  const git_index_entry *e = git_index_get_byindex(data->index, pos);
372
372
 
373
- if (e != NULL && data->diff->pfxcomp(e->path, wd->path) == 0) {
374
- notify = GIT_CHECKOUT_NOTIFY_DIRTY;
375
- remove = ((data->strategy & GIT_CHECKOUT_FORCE) != 0);
376
- }
373
+ if (e != NULL && data->diff->pfxcomp(e->path, wd->path) == 0)
374
+ return git_iterator_advance_into(wditem, workdir);
377
375
  }
378
376
  }
379
377
 
@@ -2319,8 +2317,6 @@ static void checkout_data_clear(checkout_data *data)
2319
2317
  git__free(data->pfx);
2320
2318
  data->pfx = NULL;
2321
2319
 
2322
- git_strmap_free(data->mkdir_map);
2323
-
2324
2320
  git_buf_free(&data->target_path);
2325
2321
  git_buf_free(&data->tmp);
2326
2322
 
@@ -2328,6 +2324,7 @@ static void checkout_data_clear(checkout_data *data)
2328
2324
  data->index = NULL;
2329
2325
 
2330
2326
  git_strmap_free(data->mkdir_map);
2327
+ data->mkdir_map = NULL;
2331
2328
 
2332
2329
  git_attr_session__free(&data->attr_session);
2333
2330
  }
@@ -576,22 +576,50 @@ int git_config_foreach_match(
576
576
  * Setters
577
577
  **************/
578
578
 
579
- static int config_error_nofiles(const char *name)
579
+ typedef enum {
580
+ BACKEND_USE_SET,
581
+ BACKEND_USE_DELETE
582
+ } backend_use;
583
+
584
+ static const char *uses[] = {
585
+ "set",
586
+ "delete"
587
+ };
588
+
589
+ static int get_backend_for_use(git_config_backend **out,
590
+ git_config *cfg, const char *name, backend_use use)
580
591
  {
592
+ size_t i;
593
+ file_internal *f;
594
+
595
+ *out = NULL;
596
+
597
+ if (git_vector_length(&cfg->files) == 0) {
598
+ giterr_set(GITERR_CONFIG,
599
+ "cannot %s value for '%s' when no config files exist",
600
+ uses[use], name);
601
+ return GIT_ENOTFOUND;
602
+ }
603
+
604
+ git_vector_foreach(&cfg->files, i, f) {
605
+ if (!f->file->readonly) {
606
+ *out = f->file;
607
+ return 0;
608
+ }
609
+ }
610
+
581
611
  giterr_set(GITERR_CONFIG,
582
- "cannot set value for '%s' when no config files exist", name);
612
+ "cannot %s value for '%s' when all config files are readonly",
613
+ uses[use], name);
583
614
  return GIT_ENOTFOUND;
584
615
  }
585
616
 
586
617
  int git_config_delete_entry(git_config *cfg, const char *name)
587
618
  {
588
619
  git_config_backend *file;
589
- file_internal *internal;
590
620
 
591
- internal = git_vector_get(&cfg->files, 0);
592
- if (!internal || !internal->file)
593
- return config_error_nofiles(name);
594
- file = internal->file;
621
+ if (get_backend_for_use(&file, cfg, name, BACKEND_USE_DELETE) < 0)
622
+ return GIT_ENOTFOUND;
595
623
 
596
624
  return file->del(file, name);
597
625
  }
@@ -617,17 +645,14 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
617
645
  {
618
646
  int error;
619
647
  git_config_backend *file;
620
- file_internal *internal;
621
648
 
622
649
  if (!value) {
623
650
  giterr_set(GITERR_CONFIG, "the value to set cannot be NULL");
624
651
  return -1;
625
652
  }
626
653
 
627
- internal = git_vector_get(&cfg->files, 0);
628
- if (!internal || !internal->file)
629
- return config_error_nofiles(name);
630
- file = internal->file;
654
+ if (get_backend_for_use(&file, cfg, name, BACKEND_USE_SET) < 0)
655
+ return GIT_ENOTFOUND;
631
656
 
632
657
  error = file->set(file, name, value);
633
658
 
@@ -1032,12 +1057,9 @@ on_error:
1032
1057
  int git_config_set_multivar(git_config *cfg, const char *name, const char *regexp, const char *value)
1033
1058
  {
1034
1059
  git_config_backend *file;
1035
- file_internal *internal;
1036
1060
 
1037
- internal = git_vector_get(&cfg->files, 0);
1038
- if (!internal || !internal->file)
1039
- return config_error_nofiles(name);
1040
- file = internal->file;
1061
+ if (get_backend_for_use(&file, cfg, name, BACKEND_USE_DELETE) < 0)
1062
+ return GIT_ENOTFOUND;
1041
1063
 
1042
1064
  return file->set_multivar(file, name, regexp, value);
1043
1065
  }
@@ -1045,12 +1067,9 @@ int git_config_set_multivar(git_config *cfg, const char *name, const char *regex
1045
1067
  int git_config_delete_multivar(git_config *cfg, const char *name, const char *regexp)
1046
1068
  {
1047
1069
  git_config_backend *file;
1048
- file_internal *internal;
1049
1070
 
1050
- internal = git_vector_get(&cfg->files, 0);
1051
- if (!internal || !internal->file)
1052
- return config_error_nofiles(name);
1053
- file = internal->file;
1071
+ if (get_backend_for_use(&file, cfg, name, BACKEND_USE_DELETE) < 0)
1072
+ return GIT_ENOTFOUND;
1054
1073
 
1055
1074
  return file->del_multivar(file, name, regexp);
1056
1075
  }
@@ -1339,9 +1358,6 @@ fail_parse:
1339
1358
 
1340
1359
  int git_config_parse_path(git_buf *out, const char *value)
1341
1360
  {
1342
- int error = 0;
1343
- const git_buf *home;
1344
-
1345
1361
  assert(out && value);
1346
1362
 
1347
1363
  git_buf_sanitize(out);
@@ -1352,16 +1368,7 @@ int git_config_parse_path(git_buf *out, const char *value)
1352
1368
  return -1;
1353
1369
  }
1354
1370
 
1355
- if ((error = git_sysdir_get(&home, GIT_SYSDIR_GLOBAL)) < 0)
1356
- return error;
1357
-
1358
- git_buf_sets(out, home->ptr);
1359
- git_buf_puts(out, value + 1);
1360
-
1361
- if (git_buf_oom(out))
1362
- return -1;
1363
-
1364
- return 0;
1371
+ return git_sysdir_expand_global_file(out, value[1] ? &value[2] : NULL);
1365
1372
  }
1366
1373
 
1367
1374
  return git_buf_sets(out, value);
@@ -78,6 +78,7 @@ static struct map_data _cvar_maps[] = {
78
78
  {"core.logallrefupdates", NULL, 0, GIT_LOGALLREFUPDATES_DEFAULT },
79
79
  {"core.protecthfs", NULL, 0, GIT_PROTECTHFS_DEFAULT },
80
80
  {"core.protectntfs", NULL, 0, GIT_PROTECTNTFS_DEFAULT },
81
+ {"core.fsyncobjectfiles", NULL, 0, GIT_FSYNCOBJECTFILES_DEFAULT },
81
82
  };
82
83
 
83
84
  int git_config__cvar(int *out, git_config *config, git_cvar_cached cvar)
@@ -1027,7 +1027,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
1027
1027
  first_quote = strchr(line, '"');
1028
1028
  if (first_quote == NULL) {
1029
1029
  set_parse_error(reader, 0, "Missing quotation marks in section header");
1030
- return -1;
1030
+ goto end_error;
1031
1031
  }
1032
1032
 
1033
1033
  last_quote = strrchr(line, '"');
@@ -1035,14 +1035,15 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
1035
1035
 
1036
1036
  if (quoted_len == 0) {
1037
1037
  set_parse_error(reader, 0, "Missing closing quotation mark in section header");
1038
- return -1;
1038
+ goto end_error;
1039
1039
  }
1040
1040
 
1041
1041
  GITERR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len);
1042
1042
  GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
1043
1043
 
1044
- git_buf_grow(&buf, alloc_len);
1045
- git_buf_printf(&buf, "%s.", base_name);
1044
+ if (git_buf_grow(&buf, alloc_len) < 0 ||
1045
+ git_buf_printf(&buf, "%s.", base_name) < 0)
1046
+ goto end_error;
1046
1047
 
1047
1048
  rpos = 0;
1048
1049
 
@@ -1058,8 +1059,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
1058
1059
  switch (c) {
1059
1060
  case 0:
1060
1061
  set_parse_error(reader, 0, "Unexpected end-of-line in section header");
1061
- git_buf_free(&buf);
1062
- return -1;
1062
+ goto end_error;
1063
1063
 
1064
1064
  case '"':
1065
1065
  goto end_parse;
@@ -1069,8 +1069,7 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
1069
1069
 
1070
1070
  if (c == 0) {
1071
1071
  set_parse_error(reader, rpos, "Unexpected end-of-line in section header");
1072
- git_buf_free(&buf);
1073
- return -1;
1072
+ goto end_error;
1074
1073
  }
1075
1074
 
1076
1075
  default:
@@ -1082,6 +1081,9 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
1082
1081
  } while (line + rpos < last_quote);
1083
1082
 
1084
1083
  end_parse:
1084
+ if (git_buf_oom(&buf))
1085
+ goto end_error;
1086
+
1085
1087
  if (line[rpos] != '"' || line[rpos + 1] != ']') {
1086
1088
  set_parse_error(reader, rpos, "Unexpected text after closing quotes");
1087
1089
  git_buf_free(&buf);
@@ -1090,6 +1092,11 @@ end_parse:
1090
1092
 
1091
1093
  *section_name = git_buf_detach(&buf);
1092
1094
  return 0;
1095
+
1096
+ end_error:
1097
+ git_buf_free(&buf);
1098
+
1099
+ return -1;
1093
1100
  }
1094
1101
 
1095
1102
  static int parse_section_header(struct reader *reader, char **section_out)
@@ -1249,7 +1256,7 @@ static int included_path(git_buf *out, const char *dir, const char *path)
1249
1256
  {
1250
1257
  /* From the user's home */
1251
1258
  if (path[0] == '~' && path[1] == '/')
1252
- return git_sysdir_find_global_file(out, &path[1]);
1259
+ return git_sysdir_expand_global_file(out, &path[1]);
1253
1260
 
1254
1261
  return git_path_join_unrooted(out, path, dir, NULL);
1255
1262
  }
@@ -1260,7 +1267,7 @@ static const char *escaped = "\n\t\b\"\\";
1260
1267
  /* Escape the values to write them to the file */
1261
1268
  static char *escape_value(const char *ptr)
1262
1269
  {
1263
- git_buf buf = GIT_BUF_INIT;
1270
+ git_buf buf;
1264
1271
  size_t len;
1265
1272
  const char *esc;
1266
1273
 
@@ -1270,7 +1277,8 @@ static char *escape_value(const char *ptr)
1270
1277
  if (!len)
1271
1278
  return git__calloc(1, sizeof(char));
1272
1279
 
1273
- git_buf_grow(&buf, len);
1280
+ if (git_buf_init(&buf, len) < 0)
1281
+ return NULL;
1274
1282
 
1275
1283
  while (*ptr != '\0') {
1276
1284
  if ((esc = strchr(escaped, *ptr)) != NULL) {