rugged 0.24.6.1 → 0.25.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_repo.c +44 -36
  3. data/lib/rugged/version.rb +1 -1
  4. data/vendor/libgit2/CMakeLists.txt +10 -21
  5. data/vendor/libgit2/include/git2/checkout.h +0 -7
  6. data/vendor/libgit2/include/git2/commit.h +46 -0
  7. data/vendor/libgit2/include/git2/common.h +1 -16
  8. data/vendor/libgit2/include/git2/odb.h +47 -1
  9. data/vendor/libgit2/include/git2/version.h +2 -2
  10. data/vendor/libgit2/src/array.h +0 -40
  11. data/vendor/libgit2/src/blame.c +3 -8
  12. data/vendor/libgit2/src/blame_git.c +9 -20
  13. data/vendor/libgit2/src/checkout.c +5 -13
  14. data/vendor/libgit2/src/commit.c +132 -52
  15. data/vendor/libgit2/src/common.h +1 -1
  16. data/vendor/libgit2/src/config_cache.c +1 -2
  17. data/vendor/libgit2/src/config_file.c +20 -14
  18. data/vendor/libgit2/src/delta-apply.c +5 -36
  19. data/vendor/libgit2/src/delta-apply.h +0 -12
  20. data/vendor/libgit2/src/describe.c +1 -2
  21. data/vendor/libgit2/src/diff_tform.c +3 -5
  22. data/vendor/libgit2/src/filebuf.c +1 -6
  23. data/vendor/libgit2/src/global.c +8 -28
  24. data/vendor/libgit2/src/global.h +0 -1
  25. data/vendor/libgit2/src/ignore.c +19 -56
  26. data/vendor/libgit2/src/index.c +8 -27
  27. data/vendor/libgit2/src/indexer.c +7 -11
  28. data/vendor/libgit2/src/iterator.c +2 -2
  29. data/vendor/libgit2/src/merge.c +0 -1
  30. data/vendor/libgit2/src/mwindow.c +19 -8
  31. data/vendor/libgit2/src/mwindow.h +2 -1
  32. data/vendor/libgit2/src/object.c +6 -3
  33. data/vendor/libgit2/src/odb.c +188 -48
  34. data/vendor/libgit2/src/odb_loose.c +1 -1
  35. data/vendor/libgit2/src/odb_pack.c +3 -0
  36. data/vendor/libgit2/src/openssl_stream.c +27 -60
  37. data/vendor/libgit2/src/openssl_stream.h +0 -106
  38. data/vendor/libgit2/src/pack-objects.c +2 -4
  39. data/vendor/libgit2/src/pack.c +9 -5
  40. data/vendor/libgit2/src/posix.c +0 -7
  41. data/vendor/libgit2/src/posix.h +0 -1
  42. data/vendor/libgit2/src/push.c +6 -6
  43. data/vendor/libgit2/src/refdb_fs.c +0 -1
  44. data/vendor/libgit2/src/refs.c +0 -3
  45. data/vendor/libgit2/src/refspec.c +2 -4
  46. data/vendor/libgit2/src/remote.c +5 -15
  47. data/vendor/libgit2/src/repository.c +21 -29
  48. data/vendor/libgit2/src/settings.c +1 -23
  49. data/vendor/libgit2/src/stransport_stream.c +9 -15
  50. data/vendor/libgit2/src/submodule.c +2 -3
  51. data/vendor/libgit2/src/sysdir.c +47 -41
  52. data/vendor/libgit2/src/sysdir.h +5 -0
  53. data/vendor/libgit2/src/tag.c +2 -8
  54. data/vendor/libgit2/src/thread-utils.h +51 -5
  55. data/vendor/libgit2/src/transports/http.c +3 -3
  56. data/vendor/libgit2/src/transports/smart_pkt.c +4 -13
  57. data/vendor/libgit2/src/transports/smart_protocol.c +17 -61
  58. data/vendor/libgit2/src/tree.c +100 -83
  59. data/vendor/libgit2/src/tree.h +5 -4
  60. data/vendor/libgit2/src/unix/map.c +0 -5
  61. data/vendor/libgit2/src/util.c +3 -3
  62. data/vendor/libgit2/src/win32/map.c +5 -24
  63. data/vendor/libgit2/src/win32/precompiled.h +1 -1
  64. data/vendor/libgit2/src/win32/{thread.c → pthread.c} +80 -50
  65. data/vendor/libgit2/src/win32/pthread.h +92 -0
  66. data/vendor/libgit2/src/xdiff/xprepare.c +1 -2
  67. metadata +7 -8
  68. data/vendor/libgit2/src/unix/pthread.h +0 -54
  69. data/vendor/libgit2/src/win32/thread.h +0 -62
@@ -178,7 +178,7 @@ const git_blame_hunk *git_blame_get_hunk_byline(git_blame *blame, size_t lineno)
178
178
  return NULL;
179
179
  }
180
180
 
181
- static int normalize_options(
181
+ static void normalize_options(
182
182
  git_blame_options *out,
183
183
  const git_blame_options *in,
184
184
  git_repository *repo)
@@ -190,9 +190,7 @@ static int normalize_options(
190
190
 
191
191
  /* No newest_commit => HEAD */
192
192
  if (git_oid_iszero(&out->newest_commit)) {
193
- if (git_reference_name_to_id(&out->newest_commit, repo, "HEAD") < 0) {
194
- return -1;
195
- }
193
+ git_reference_name_to_id(&out->newest_commit, repo, "HEAD");
196
194
  }
197
195
 
198
196
  /* min_line 0 really means 1 */
@@ -206,8 +204,6 @@ static int normalize_options(
206
204
  out->flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES;
207
205
  if (out->flags & GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES)
208
206
  out->flags |= GIT_BLAME_TRACK_COPIES_SAME_FILE;
209
-
210
- return 0;
211
207
  }
212
208
 
213
209
  static git_blame_hunk *split_hunk_in_vector(
@@ -366,8 +362,7 @@ int git_blame_file(
366
362
  git_blame *blame = NULL;
367
363
 
368
364
  assert(out && repo && path);
369
- if ((error = normalize_options(&normOptions, options, repo)) < 0)
370
- goto on_error;
365
+ normalize_options(&normOptions, options, repo);
371
366
 
372
367
  blame = git_blame__alloc(repo, normOptions, path);
373
368
  GITERR_CHECK_ALLOC(blame);
@@ -37,27 +37,25 @@ static void origin_decref(git_blame__origin *o)
37
37
  static int make_origin(git_blame__origin **out, git_commit *commit, const char *path)
38
38
  {
39
39
  git_blame__origin *o;
40
- git_object *blob;
41
40
  size_t path_len = strlen(path), alloc_len;
42
41
  int error = 0;
43
42
 
44
- if ((error = git_object_lookup_bypath(&blob, (git_object*)commit,
45
- path, GIT_OBJ_BLOB)) < 0)
46
- return error;
47
-
48
43
  GITERR_CHECK_ALLOC_ADD(&alloc_len, sizeof(*o), path_len);
49
44
  GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1);
50
45
  o = git__calloc(1, alloc_len);
51
46
  GITERR_CHECK_ALLOC(o);
52
47
 
53
48
  o->commit = commit;
54
- o->blob = (git_blob *) blob;
55
49
  o->refcnt = 1;
56
50
  strcpy(o->path, path);
57
51
 
58
- *out = o;
59
-
60
- return 0;
52
+ if (!(error = git_object_lookup_bypath((git_object**)&o->blob, (git_object*)commit,
53
+ path, GIT_OBJ_BLOB))) {
54
+ *out = o;
55
+ } else {
56
+ origin_decref(o);
57
+ }
58
+ return error;
61
59
  }
62
60
 
63
61
  /* Locate an existing origin or create a new one. */
@@ -527,20 +525,11 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
527
525
  if (sg_origin[i])
528
526
  continue;
529
527
 
530
- if ((error = git_commit_parent(&p, origin->commit, i)) < 0)
531
- goto finish;
528
+ git_commit_parent(&p, origin->commit, i);
532
529
  porigin = find_origin(blame, p, origin);
533
530
 
534
- if (!porigin) {
535
- /*
536
- * We only have to decrement the parent's
537
- * reference count when no porigin has
538
- * been created, as otherwise the commit
539
- * is assigned to the created object.
540
- */
541
- git_commit_free(p);
531
+ if (!porigin)
542
532
  continue;
543
- }
544
533
  if (porigin->blob && origin->blob &&
545
534
  !git_oid_cmp(git_blob_id(porigin->blob), git_blob_id(origin->blob))) {
546
535
  pass_whole_blame(blame, origin, porigin);
@@ -464,8 +464,7 @@ static int checkout_action_with_wd(
464
464
  *action = CHECKOUT_ACTION_IF(SAFE, REMOVE, NONE);
465
465
  break;
466
466
  case GIT_DELTA_MODIFIED: /* case 16, 17, 18 (or 36 but not really) */
467
- if (wd->mode != GIT_FILEMODE_COMMIT &&
468
- checkout_is_workdir_modified(data, &delta->old_file, &delta->new_file, wd))
467
+ if (checkout_is_workdir_modified(data, &delta->old_file, &delta->new_file, wd))
469
468
  *action = CHECKOUT_ACTION_IF(FORCE, UPDATE_BLOB, CONFLICT);
470
469
  else
471
470
  *action = CHECKOUT_ACTION_IF(SAFE, UPDATE_BLOB, NONE);
@@ -1343,11 +1342,9 @@ fail:
1343
1342
 
1344
1343
  static bool should_remove_existing(checkout_data *data)
1345
1344
  {
1346
- int ignorecase;
1345
+ int ignorecase = 0;
1347
1346
 
1348
- if (git_repository__cvar(&ignorecase, data->repo, GIT_CVAR_IGNORECASE) < 0) {
1349
- ignorecase = 0;
1350
- }
1347
+ git_repository__cvar(&ignorecase, data->repo, GIT_CVAR_IGNORECASE);
1351
1348
 
1352
1349
  return (ignorecase &&
1353
1350
  (data->strategy & GIT_CHECKOUT_DONT_REMOVE_EXISTING) == 0);
@@ -2408,13 +2405,8 @@ static int checkout_data_init(
2408
2405
 
2409
2406
  if (!data->opts.baseline && !data->opts.baseline_index) {
2410
2407
  data->opts_free_baseline = true;
2411
- error = 0;
2412
2408
 
2413
- /* if we don't have an index, this is an initial checkout and
2414
- * should be against an empty baseline
2415
- */
2416
- if (data->index->on_disk)
2417
- error = checkout_lookup_head_tree(&data->opts.baseline, repo);
2409
+ error = checkout_lookup_head_tree(&data->opts.baseline, repo);
2418
2410
 
2419
2411
  if (error == GIT_EUNBORNBRANCH) {
2420
2412
  error = 0;
@@ -2699,7 +2691,7 @@ int git_checkout_tree(
2699
2691
  if ((error = git_repository_index(&index, repo)) < 0)
2700
2692
  return error;
2701
2693
 
2702
- if (opts && (opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) {
2694
+ if ((opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) {
2703
2695
  iter_opts.pathlist.count = opts->paths.count;
2704
2696
  iter_opts.pathlist.strings = opts->paths.strings;
2705
2697
  }
@@ -18,6 +18,7 @@
18
18
  #include "message.h"
19
19
  #include "refs.h"
20
20
  #include "object.h"
21
+ #include "oidarray.h"
21
22
 
22
23
  void git_commit__free(void *_commit)
23
24
  {
@@ -37,94 +38,143 @@ void git_commit__free(void *_commit)
37
38
  git__free(commit);
38
39
  }
39
40
 
40
- static int git_commit__create_internal(
41
- git_oid *id,
41
+ static int git_commit__create_buffer_internal(
42
+ git_buf *out,
42
43
  git_repository *repo,
43
- const char *update_ref,
44
44
  const git_signature *author,
45
45
  const git_signature *committer,
46
46
  const char *message_encoding,
47
47
  const char *message,
48
48
  const git_oid *tree,
49
- git_commit_parent_callback parent_cb,
50
- void *parent_payload,
51
- bool validate)
49
+ git_array_oid_t *parents)
52
50
  {
53
- git_reference *ref = NULL;
54
- int error = 0, matched_parent = 0;
55
- const git_oid *current_id = NULL;
56
- git_buf commit = GIT_BUF_INIT;
57
51
  size_t i = 0;
58
- git_odb *odb;
59
52
  const git_oid *parent;
60
53
 
61
- assert(id && repo && tree && parent_cb);
54
+ assert(out && repo && tree);
62
55
 
63
- if (validate && !git_object__is_valid(repo, tree, GIT_OBJ_TREE))
64
- return -1;
56
+ git_oid__writebuf(out, "tree ", tree);
65
57
 
66
- if (update_ref) {
67
- error = git_reference_lookup_resolved(&ref, repo, update_ref, 10);
68
- if (error < 0 && error != GIT_ENOTFOUND)
69
- return error;
58
+ for (i = 0; i < git_array_size(*parents); i++) {
59
+ parent = git_array_get(*parents, i);
60
+ git_oid__writebuf(out, "parent ", parent);
70
61
  }
71
- giterr_clear();
72
62
 
73
- if (ref)
74
- current_id = git_reference_target(ref);
63
+ git_signature__writebuf(out, "author ", author);
64
+ git_signature__writebuf(out, "committer ", committer);
65
+
66
+ if (message_encoding != NULL)
67
+ git_buf_printf(out, "encoding %s\n", message_encoding);
68
+
69
+ git_buf_putc(out, '\n');
75
70
 
76
- git_oid__writebuf(&commit, "tree ", tree);
71
+ if (git_buf_puts(out, message) < 0)
72
+ goto on_error;
73
+
74
+ return 0;
75
+
76
+ on_error:
77
+ git_buf_free(out);
78
+ return -1;
79
+ }
77
80
 
81
+ static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *repo, const git_oid *tree,
82
+ git_commit_parent_callback parent_cb, void *parent_payload,
83
+ const git_oid *current_id, bool validate)
84
+ {
85
+ size_t i;
86
+ int error;
87
+ git_oid *parent_cpy;
88
+ const git_oid *parent;
89
+
90
+ if (validate && !git_object__is_valid(repo, tree, GIT_OBJ_TREE))
91
+ return -1;
92
+
93
+ i = 0;
78
94
  while ((parent = parent_cb(i, parent_payload)) != NULL) {
79
95
  if (validate && !git_object__is_valid(repo, parent, GIT_OBJ_COMMIT)) {
80
96
  error = -1;
81
97
  goto on_error;
82
98
  }
83
99
 
84
- git_oid__writebuf(&commit, "parent ", parent);
85
- if (i == 0 && current_id && git_oid_equal(current_id, parent))
86
- matched_parent = 1;
100
+ parent_cpy = git_array_alloc(*parents);
101
+ GITERR_CHECK_ALLOC(parent_cpy);
102
+
103
+ git_oid_cpy(parent_cpy, parent);
87
104
  i++;
88
105
  }
89
106
 
90
- if (ref && !matched_parent) {
91
- git_reference_free(ref);
92
- git_buf_free(&commit);
107
+ if (current_id && git_oid_cmp(current_id, git_array_get(*parents, 0))) {
93
108
  giterr_set(GITERR_OBJECT, "failed to create commit: current tip is not the first parent");
94
- return GIT_EMODIFIED;
109
+ error = GIT_EMODIFIED;
110
+ goto on_error;
95
111
  }
96
112
 
97
- git_signature__writebuf(&commit, "author ", author);
98
- git_signature__writebuf(&commit, "committer ", committer);
113
+ return 0;
99
114
 
100
- if (message_encoding != NULL)
101
- git_buf_printf(&commit, "encoding %s\n", message_encoding);
115
+ on_error:
116
+ git_array_clear(*parents);
117
+ return error;
118
+ }
119
+
120
+ static int git_commit__create_internal(
121
+ git_oid *id,
122
+ git_repository *repo,
123
+ const char *update_ref,
124
+ const git_signature *author,
125
+ const git_signature *committer,
126
+ const char *message_encoding,
127
+ const char *message,
128
+ const git_oid *tree,
129
+ git_commit_parent_callback parent_cb,
130
+ void *parent_payload,
131
+ bool validate)
132
+ {
133
+ int error;
134
+ git_odb *odb;
135
+ git_reference *ref = NULL;
136
+ git_buf buf = GIT_BUF_INIT;
137
+ const git_oid *current_id = NULL;
138
+ git_array_oid_t parents = GIT_ARRAY_INIT;
102
139
 
103
- git_buf_putc(&commit, '\n');
140
+ if (update_ref) {
141
+ error = git_reference_lookup_resolved(&ref, repo, update_ref, 10);
142
+ if (error < 0 && error != GIT_ENOTFOUND)
143
+ return error;
144
+ }
145
+ giterr_clear();
104
146
 
105
- if (git_buf_puts(&commit, message) < 0)
106
- goto on_error;
147
+ if (ref)
148
+ current_id = git_reference_target(ref);
149
+
150
+ if ((error = validate_tree_and_parents(&parents, repo, tree, parent_cb, parent_payload, current_id, validate)) < 0)
151
+ goto cleanup;
152
+
153
+ error = git_commit__create_buffer_internal(&buf, repo, author, committer,
154
+ message_encoding, message, tree,
155
+ &parents);
156
+
157
+ if (error < 0)
158
+ goto cleanup;
107
159
 
108
160
  if (git_repository_odb__weakptr(&odb, repo) < 0)
109
- goto on_error;
161
+ goto cleanup;
110
162
 
111
- if (git_odb_write(id, odb, commit.ptr, commit.size, GIT_OBJ_COMMIT) < 0)
112
- goto on_error;
163
+ if (git_odb_write(id, odb, buf.ptr, buf.size, GIT_OBJ_COMMIT) < 0)
164
+ goto cleanup;
113
165
 
114
- git_buf_free(&commit);
115
166
 
116
167
  if (update_ref != NULL) {
117
168
  error = git_reference__update_for_commit(
118
169
  repo, ref, update_ref, id, "commit");
119
- git_reference_free(ref);
120
- return error;
170
+ goto cleanup;
121
171
  }
122
172
 
123
- return 0;
124
-
125
- on_error:
126
- git_buf_free(&commit);
127
- return -1;
173
+ cleanup:
174
+ git_array_clear(parents);
175
+ git_reference_free(ref);
176
+ git_buf_free(&buf);
177
+ return error;
128
178
  }
129
179
 
130
180
  int git_commit_create_from_callback(
@@ -410,11 +460,10 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj)
410
460
  buffer = buffer_start + header_len + 1;
411
461
 
412
462
  /* extract commit message */
413
- if (buffer <= buffer_end)
463
+ if (buffer <= buffer_end) {
414
464
  commit->raw_message = git__strndup(buffer, buffer_end - buffer);
415
- else
416
- commit->raw_message = git__strdup("");
417
- GITERR_CHECK_ALLOC(commit->raw_message);
465
+ GITERR_CHECK_ALLOC(commit->raw_message);
466
+ }
418
467
 
419
468
  return 0;
420
469
 
@@ -677,7 +726,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
677
726
 
678
727
  buf = git_odb_object_data(obj);
679
728
 
680
- while ((h = strchr(buf, '\n')) && h[1] != '\0') {
729
+ while ((h = strchr(buf, '\n')) && h[1] != '\0' && h[1] != '\n') {
681
730
  h++;
682
731
  if (git__prefixcmp(buf, field)) {
683
732
  if (git_buf_put(signed_data, buf, h - buf) < 0)
@@ -740,3 +789,34 @@ cleanup:
740
789
  git_buf_clear(signed_data);
741
790
  return error;
742
791
  }
792
+
793
+ int git_commit_create_buffer(git_buf *out,
794
+ git_repository *repo,
795
+ const git_signature *author,
796
+ const git_signature *committer,
797
+ const char *message_encoding,
798
+ const char *message,
799
+ const git_tree *tree,
800
+ size_t parent_count,
801
+ const git_commit *parents[])
802
+ {
803
+ int error;
804
+ commit_parent_data data = { parent_count, parents, repo };
805
+ git_array_oid_t parents_arr = GIT_ARRAY_INIT;
806
+ const git_oid *tree_id;
807
+
808
+ assert(tree && git_tree_owner(tree) == repo);
809
+
810
+ tree_id = git_tree_id(tree);
811
+
812
+ if ((error = validate_tree_and_parents(&parents_arr, repo, tree_id, commit_parent_from_array, &data, NULL, true)) < 0)
813
+ return error;
814
+
815
+ error = git_commit__create_buffer_internal(
816
+ out, repo, author, committer,
817
+ message_encoding, message, tree_id,
818
+ &parents_arr);
819
+
820
+ git_array_clear(parents_arr);
821
+ return error;
822
+ }
@@ -45,7 +45,7 @@
45
45
  # include "win32/error.h"
46
46
  # include "win32/version.h"
47
47
  # ifdef GIT_THREADS
48
- # include "win32/thread.h"
48
+ # include "win32/pthread.h"
49
49
  # endif
50
50
  # if defined(GIT_MSVC_CRTDBG)
51
51
  # include "win32/w32_stack.h"
@@ -86,8 +86,7 @@ int git_config__cvar(int *out, git_config *config, git_cvar_cached cvar)
86
86
  struct map_data *data = &_cvar_maps[(int)cvar];
87
87
  git_config_entry *entry;
88
88
 
89
- if ((error = git_config__lookup_entry(&entry, config, data->cvar_name, false)) < 0)
90
- return error;
89
+ git_config__lookup_entry(&entry, config, data->cvar_name, false);
91
90
 
92
91
  if (!entry)
93
92
  *out = data->default_value;
@@ -553,15 +553,30 @@ static int config_set_multivar(
553
553
  git_config_backend *cfg, const char *name, const char *regexp, const char *value)
554
554
  {
555
555
  diskfile_backend *b = (diskfile_backend *)cfg;
556
+ refcounted_strmap *map;
557
+ git_strmap *values;
556
558
  char *key;
557
559
  regex_t preg;
558
560
  int result;
561
+ khiter_t pos;
559
562
 
560
563
  assert(regexp);
561
564
 
562
565
  if ((result = git_config__normalize_name(name, &key)) < 0)
563
566
  return result;
564
567
 
568
+ map = refcounted_strmap_take(&b->header);
569
+ values = b->header.values->values;
570
+
571
+ pos = git_strmap_lookup_index(values, key);
572
+ if (!git_strmap_valid_index(values, pos)) {
573
+ /* If we don't have it, behave like a normal set */
574
+ result = config_set(cfg, name, value);
575
+ refcounted_strmap_free(map);
576
+ git__free(key);
577
+ return result;
578
+ }
579
+
565
580
  result = regcomp(&preg, regexp, REG_EXTENDED);
566
581
  if (result != 0) {
567
582
  giterr_set_regex(&preg, result);
@@ -576,6 +591,7 @@ static int config_set_multivar(
576
591
  result = config_refresh(cfg);
577
592
 
578
593
  out:
594
+ refcounted_strmap_free(map);
579
595
  git__free(key);
580
596
  regfree(&preg);
581
597
 
@@ -1016,11 +1032,6 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
1016
1032
  */
1017
1033
 
1018
1034
  first_quote = strchr(line, '"');
1019
- if (first_quote == NULL) {
1020
- set_parse_error(reader, 0, "Missing quotation marks in section header");
1021
- return -1;
1022
- }
1023
-
1024
1035
  last_quote = strrchr(line, '"');
1025
1036
  quoted_len = last_quote - first_quote;
1026
1037
 
@@ -1472,7 +1483,7 @@ static int config_parse(
1472
1483
  int (*on_section)(struct reader **reader, const char *current_section, const char *line, size_t line_len, void *data),
1473
1484
  int (*on_variable)(struct reader **reader, const char *current_section, char *var_name, char *var_value, const char *line, size_t line_len, void *data),
1474
1485
  int (*on_comment)(struct reader **reader, const char *line, size_t line_len, void *data),
1475
- int (*on_eof)(struct reader **reader, const char *current_section, void *data),
1486
+ int (*on_eof)(struct reader **reader, void *data),
1476
1487
  void *data)
1477
1488
  {
1478
1489
  char *current_section = NULL, *var_name, *var_value, *line_start;
@@ -1523,7 +1534,7 @@ static int config_parse(
1523
1534
  }
1524
1535
 
1525
1536
  if (on_eof)
1526
- result = on_eof(&reader, current_section, data);
1537
+ result = on_eof(&reader, data);
1527
1538
 
1528
1539
  git__free(current_section);
1529
1540
  return result;
@@ -1839,8 +1850,7 @@ static int write_on_comment(struct reader **reader, const char *line, size_t lin
1839
1850
  return write_line_to(&write_data->buffered_comment, line, line_len);
1840
1851
  }
1841
1852
 
1842
- static int write_on_eof(
1843
- struct reader **reader, const char *current_section, void *data)
1853
+ static int write_on_eof(struct reader **reader, void *data)
1844
1854
  {
1845
1855
  struct write_data *write_data = (struct write_data *)data;
1846
1856
  int result = 0;
@@ -1859,11 +1869,7 @@ static int write_on_eof(
1859
1869
  * value.
1860
1870
  */
1861
1871
  if ((!write_data->preg || !write_data->preg_replaced) && write_data->value) {
1862
- /* write the section header unless we're already in it */
1863
- if (!current_section || strcmp(current_section, write_data->section))
1864
- result = write_section(write_data->buf, write_data->section);
1865
-
1866
- if (!result)
1872
+ if ((result = write_section(write_data->buf, write_data->section)) == 0)
1867
1873
  result = write_value(write_data);
1868
1874
  }
1869
1875