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

rerere should not repeat the earlier hunks in later ones

When a file has more then one conflicting hunks, it repeated the contents of previous hunks in output for later ones. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 3, 2007 at 16:28 UTC eb3359663d62f35999330797455dbe738bd5ed99
2 files changed +26 -4
builtin-rerere.c
+9
@@ -78,6 +78,13 @@ static void append_line(struct buffer *buffer, const char *line)
78 buffer->nr += len;
79 }
80
81 +static void clear_buffer(struct buffer *buffer)
82 +{
83 + free(buffer->ptr);
84 + buffer->ptr = NULL;
85 + buffer->nr = buffer->alloc = 0;
86 +}
87 +
88 static int handle_file(const char *path,
89 unsigned char *sha1, const char *output)
90 {
@@ -131,6 +138,8 @@ static int handle_file(const char *path,
138 SHA1_Update(&ctx, two->ptr, two->nr);
139 SHA1_Update(&ctx, "\0", 1);
140 }
141 + clear_buffer(one);
142 + clear_buffer(two);
143 } else if (hunk == 1)
144 append_line(one, buf);
145 else if (hunk == 2)
t/t4200-rerere.sh
+17 -4
@@ -34,7 +34,8 @@ EOF
34 git commit -q -a -m first
35
36 git checkout -b second master
37 -git show first:a1 | sed 's/To die, t/To die! T/' > a1
37 +git show first:a1 |
38 +sed -e 's/To die, t/To die! T/' -e 's/life;$/life./' > a1
39 git commit -q -a -m second
40
41 # activate rerere
@@ -42,19 +43,26 @@ mkdir .git/rr-cache
43
44 test_expect_failure 'conflicting merge' 'git pull . first'
45
45 -sha1=4f58849a60b4f969a2848966b6d02893b783e8fb
46 +sha1=$(sed -e 's/\t.*//' .git/rr-cache/MERGE_RR)
47 rr=.git/rr-cache/$sha1
48 test_expect_success 'recorded preimage' "grep ======= $rr/preimage"
49
50 test_expect_success 'no postimage or thisimage yet' \
51 "test ! -f $rr/postimage -a ! -f $rr/thisimage"
52
53 +test_expect_success 'preimage have right number of lines' '
54 +
55 + cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
56 + test "$cnt" = 10
57 +
58 +'
59 +
60 git show first:a1 > a1
61
62 cat > expect << EOF
63 --- a/a1
64 +++ b/a1
57 -@@ -6,11 +6,7 @@
65 +@@ -6,17 +6,9 @@
66 The heart-ache and the thousand natural shocks
67 That flesh is heir to, 'tis a consummation
68 Devoutly to be wish'd.
@@ -66,8 +74,13 @@ cat > expect << EOF
74 To sleep: perchance to dream: ay, there's the rub;
75 For in that sleep of death what dreams may come
76 When we have shuffled off this mortal coil,
77 + Must give us pause: there's the respect
78 +-<<<<<<<
79 +-That makes calamity of so long life.
80 +-=======
81 + That makes calamity of so long life;
82 +->>>>>>>
83 EOF
70 -
84 git rerere diff > out
85
86 test_expect_success 'rerere diff' 'diff -u expect out'