@matheusbsbs / matheus-bagliano / commits / 121c813f8d
Fork 0

rerere.autoupdate

When this configuration is set, paths that are autoresolved by git-rerere are updated in the index as well.

Junio C Hamano committed Jun 22, 2008 at 02:04 UTC 121c813f8d6054dbee25c03301599c0f8d645d7f
3 files changed +52
Documentation/config.txt
+5
@@ -650,6 +650,11 @@ gc.rerereunresolved::
650 kept for this many days when `git rerere gc` is run.
651 The default is 15 days. See linkgit:git-rerere[1].
652
653 +rerere.autoupdate::
654 + When set to true, `git-rerere` updates the index with the
655 + resulting contents after it cleanly resolves conflicts using
656 + previously recorded resolution. Defaults to false.
657 +
658 rerere.enabled::
659 Activate recording of resolved conflicts, so that identical
660 conflict hunks can be resolved automatically, should they
builtin-rerere.c
+37
@@ -16,6 +16,9 @@ static int cutoff_resolve = 60;
16 /* if rerere_enabled == -1, fall back to detection of .git/rr-cache */
17 static int rerere_enabled = -1;
18
19 +/* automatically update cleanly resolved paths to the index */
20 +static int rerere_autoupdate;
21 +
22 static char *merge_rr_path;
23
24 static const char *rr_path(const char *name, const char *file)
@@ -276,9 +279,36 @@ static int diff_two(const char *file1, const char *label1,
279 return 0;
280 }
281
282 +static struct lock_file index_lock;
283 +
284 +static int update_paths(struct path_list *update)
285 +{
286 + int i;
287 + int fd = hold_locked_index(&index_lock, 0);
288 + int status = 0;
289 +
290 + if (fd < 0)
291 + return -1;
292 +
293 + for (i = 0; i < update->nr; i++) {
294 + struct path_list_item *item = &update->items[i];
295 + if (add_file_to_cache(item->path, ADD_CACHE_IGNORE_ERRORS))
296 + status = -1;
297 + }
298 +
299 + if (!status && active_cache_changed) {
300 + if (write_cache(fd, active_cache, active_nr) ||
301 + commit_locked_index(&index_lock))
302 + die("Unable to write new index file");
303 + } else if (fd >= 0)
304 + rollback_lock_file(&index_lock);
305 + return status;
306 +}
307 +
308 static int do_plain_rerere(struct path_list *rr, int fd)
309 {
310 struct path_list conflict = { NULL, 0, 0, 1 };
311 + struct path_list update = { NULL, 0, 0, 1 };
312 int i;
313
314 find_conflict(&conflict);
@@ -323,6 +353,8 @@ static int do_plain_rerere(struct path_list *rr, int fd)
353 if (!merge(name, path)) {
354 fprintf(stderr, "Resolved '%s' using "
355 "previous resolution.\n", path);
356 + if (rerere_autoupdate)
357 + path_list_insert(path, &update);
358 goto mark_resolved;
359 }
360 }
@@ -338,6 +370,9 @@ static int do_plain_rerere(struct path_list *rr, int fd)
370 rr->items[i].util = NULL;
371 }
372
373 + if (update.nr)
374 + update_paths(&update);
375 +
376 return write_rr(rr, fd);
377 }
378
@@ -349,6 +384,8 @@ static int git_rerere_config(const char *var, const char *value, void *cb)
384 cutoff_noresolve = git_config_int(var, value);
385 else if (!strcmp(var, "rerere.enabled"))
386 rerere_enabled = git_config_bool(var, value);
387 + else if (!strcmp(var, "rerere.autoupdate"))
388 + rerere_autoupdate = git_config_bool(var, value);
389 else
390 return git_default_config(var, value, cb);
391 return 0;
t/t4200-rerere.sh
+10
@@ -193,9 +193,19 @@ test_expect_success 'resolution was recorded properly' '
193 echo Bello > file3 &&
194 git add file3 &&
195 git commit -m version2 &&
196 + git tag version2 &&
197 test_must_fail git merge fifth &&
198 test Cello = "$(cat file3)" &&
199 test 0 != $(git ls-files -u | wc -l)
200 '
201
202 +test_expect_success 'rerere.autoupdate' '
203 + git config rerere.autoupdate true
204 + git reset --hard &&
205 + git checkout version2 &&
206 + test_must_fail git merge fifth &&
207 + test 0 = $(git ls-files -u | wc -l)
208 +
209 +'
210 +
211 test_done