@matheusbsbs / matheus-bagliano / commits / b4372ef136
Fork 0

Enable "git rerere" by the config variable rerere.enabled

Earlier, "git rerere" was enabled by creating the directory .git/rr-cache. That is definitely not in line with most other features, which are enabled by a config variable. So, check the config variable "rerere.enabled". If it is set to "false" explicitely, do not activate rerere, even if .git/rr-cache exists. This should help when you want to disable rerere temporarily. If "rerere.enabled" is not set at all, fall back to detection of the directory .git/rr-cache. [jc: with minimum tweaks] Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 6, 2007 at 13:05 UTC b4372ef136b0a5a2c1dbd88a11dd72b478d0e0a5
9 files changed +64 -40
Documentation/config.txt
+5
@@ -448,6 +448,11 @@ gc.rerereunresolved::
448 kept for this many days when `git rerere gc` is run.
449 The default is 15 days. See gitlink:git-rerere[1].
450
451 +rerere.enabled::
452 + Activate recording of resolved conflicts, so that identical
453 + conflict hunks can be resolved automatically, should they
454 + be encountered again. See gitlink:git-rerere[1].
455 +
456 gitcvs.enabled::
457 Whether the cvs server interface is enabled for this repository.
458 See gitlink:git-cvsserver[1].
Documentation/git-rerere.txt
+2 -2
@@ -23,7 +23,7 @@ initial manual merge, and later by noticing the same automerge
23 results and applying the previously recorded hand resolution.
24
25 [NOTE]
26 -You need to create `$GIT_DIR/rr-cache` directory to enable this
26 +You need to set the config variable rerere.enabled to enable this
27 command.
28
29
@@ -171,7 +171,7 @@ records it if it is a new conflict, or reuses the earlier hand
171 resolve when it is not. `git-commit` also invokes `git-rerere`
172 when recording a merge result. What this means is that you do
173 not have to do anything special yourself (Note: you still have
174 -to create `$GIT_DIR/rr-cache` directory to enable this command).
174 +to set the config variable rerere.enabled to enable this command).
175
176 In our example, when you did the test merge, the manual
177 resolution is recorded, and it will be reused when you do the
builtin-rerere.c
+28 -4
@@ -12,6 +12,9 @@ static const char git_rerere_usage[] =
12 static int cutoff_noresolve = 15;
13 static int cutoff_resolve = 60;
14
15 +/* if rerere_enabled == -1, fall back to detection of .git/rr-cache */
16 +static int rerere_enabled = -1;
17 +
18 static char *merge_rr_path;
19
20 static const char *rr_path(const char *name, const char *file)
@@ -387,21 +390,41 @@ static int git_rerere_config(const char *var, const char *value)
390 cutoff_resolve = git_config_int(var, value);
391 else if (!strcmp(var, "gc.rerereunresolved"))
392 cutoff_noresolve = git_config_int(var, value);
393 + else if (!strcmp(var, "rerere.enabled"))
394 + rerere_enabled = git_config_bool(var, value);
395 else
396 return git_default_config(var, value);
397 return 0;
398 }
399
395 -int cmd_rerere(int argc, const char **argv, const char *prefix)
400 +static int is_rerere_enabled(void)
401 {
397 - struct path_list merge_rr = { NULL, 0, 0, 1 };
398 - int i, fd = -1;
402 struct stat st;
403 + const char *rr_cache;
404 + int rr_cache_exists;
405
401 - if (stat(git_path("rr-cache"), &st) || !S_ISDIR(st.st_mode))
406 + if (!rerere_enabled)
407 return 0;
408
409 + rr_cache = git_path("rr-cache");
410 + rr_cache_exists = !stat(rr_cache, &st) && S_ISDIR(st.st_mode);
411 + if (rerere_enabled < 0)
412 + return rr_cache_exists;
413 +
414 + if (!rr_cache_exists &&
415 + (mkdir(rr_cache, 0777) || adjust_shared_perm(rr_cache)))
416 + die("Could not create directory %s", rr_cache);
417 + return 1;
418 +}
419 +
420 +int cmd_rerere(int argc, const char **argv, const char *prefix)
421 +{
422 + struct path_list merge_rr = { NULL, 0, 0, 1 };
423 + int i, fd = -1;
424 +
425 git_config(git_rerere_config);
426 + if (!is_rerere_enabled())
427 + return 0;
428
429 merge_rr_path = xstrdup(git_path("rr-cache/MERGE_RR"));
430 fd = hold_lock_file_for_update(&write_lock, merge_rr_path, 1);
@@ -411,6 +434,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
434 return do_plain_rerere(&merge_rr, fd);
435 else if (!strcmp(argv[1], "clear")) {
436 for (i = 0; i < merge_rr.nr; i++) {
437 + struct stat st;
438 const char *name = (const char *)merge_rr.items[i].util;
439 if (!stat(git_path("rr-cache/%s", name), &st) &&
440 S_ISDIR(st.st_mode) &&
contrib/emacs/git.el
+1 -2
@@ -681,8 +681,7 @@ and returns the process output as a string."
681 (condition-case nil (delete-file ".git/MERGE_MSG") (error nil))
682 (with-current-buffer buffer (erase-buffer))
683 (git-set-files-state files 'uptodate)
684 - (when (file-directory-p ".git/rr-cache")
685 - (git-run-command nil nil "rerere"))
684 + (git-run-command nil nil "rerere")
685 (git-refresh-files)
686 (git-refresh-ewoc-hf git-status)
687 (message "Committed %s." commit)
git-am.sh
+3 -12
@@ -95,10 +95,7 @@ It does not apply to blobs recorded in its index."
95 eval GITHEAD_$his_tree='"$SUBJECT"'
96 export GITHEAD_$his_tree
97 git-merge-recursive $orig_tree -- HEAD $his_tree || {
98 - if test -d "$GIT_DIR/rr-cache"
99 - then
100 - git rerere
101 - fi
98 + git rerere
99 echo Failed to merge in the changes.
100 exit 1
101 }
@@ -252,10 +249,7 @@ last=`cat "$dotest/last"`
249 this=`cat "$dotest/next"`
250 if test "$skip" = t
251 then
255 - if test -d "$GIT_DIR/rr-cache"
256 - then
257 - git rerere clear
258 - fi
252 + git rerere clear
253 this=`expr "$this" + 1`
254 resume=
255 fi
@@ -420,10 +414,7 @@ do
414 stop_here_user_resolve $this
415 fi
416 apply_status=0
423 - if test -d "$GIT_DIR/rr-cache"
424 - then
425 - git rerere
426 - fi
417 + git rerere
418 ;;
419 esac
420
git-commit.sh
+1 -4
@@ -610,10 +610,7 @@ rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
610
611 cd_to_toplevel
612
613 -if test -d "$GIT_DIR/rr-cache"
614 -then
615 - git rerere
616 -fi
613 +git rerere
614
615 if test "$ret" = 0
616 then
git-merge.sh
+1 -4
@@ -496,9 +496,6 @@ Conflicts:
496 sed -e 's/^[^ ]* / /' |
497 uniq
498 } >>"$GIT_DIR/MERGE_MSG"
499 - if test -d "$GIT_DIR/rr-cache"
500 - then
501 - git rerere
502 - fi
499 + git rerere
500 die "Automatic merge failed; fix conflicts and then commit the result."
501 fi
git-rebase.sh
+3 -9
@@ -101,7 +101,7 @@ call_merge () {
101 return
102 ;;
103 1)
104 - test -d "$GIT_DIR/rr-cache" && git rerere
104 + git rerere
105 die "$RESOLVEMSG"
106 ;;
107 2)
@@ -160,10 +160,7 @@ do
160 --skip)
161 if test -d "$dotest"
162 then
163 - if test -d "$GIT_DIR/rr-cache"
164 - then
165 - git rerere clear
166 - fi
163 + git rerere clear
164 prev_head="`cat $dotest/prev_head`"
165 end="`cat $dotest/end`"
166 msgnum="`cat $dotest/msgnum`"
@@ -181,10 +178,7 @@ do
178 exit
179 ;;
180 --abort)
184 - if test -d "$GIT_DIR/rr-cache"
185 - then
186 - git rerere clear
187 - fi
181 + git rerere clear
182 if test -d "$dotest"
183 then
184 rm -r "$dotest"
t/t4200-rerere.sh
+20 -3
@@ -39,15 +39,32 @@ sed -e 's/To die, t/To die! T/' > a1
39 echo "* END *" >>a1
40 git commit -q -a -m second
41
42 -# activate rerere
43 -mkdir .git/rr-cache
42 +test_expect_success 'nothing recorded without rerere' '
43 + (rm -rf .git/rr-cache; git config rerere.enabled false) &&
44 + ! git merge first &&
45 + ! test -d .git/rr-cache
46 +'
47
45 -test_expect_failure 'conflicting merge' 'git pull . first'
48 +# activate rerere, old style
49 +test_expect_success 'conflicting merge' '
50 + git reset --hard &&
51 + mkdir .git/rr-cache &&
52 + git config --unset rerere.enabled &&
53 + ! git merge first
54 +'
55
56 sha1=$(sed -e 's/ .*//' .git/rr-cache/MERGE_RR)
57 rr=.git/rr-cache/$sha1
58 test_expect_success 'recorded preimage' "grep ======= $rr/preimage"
59
60 +test_expect_success 'rerere.enabled works, too' '
61 + rm -rf .git/rr-cache &&
62 + git config rerere.enabled true &&
63 + git reset --hard &&
64 + ! git merge first &&
65 + grep ======= $rr/preimage
66 +'
67 +
68 test_expect_success 'no postimage or thisimage yet' \
69 "test ! -f $rr/postimage -a ! -f $rr/thisimage"
70