Skip to content

Commit 3b9d69e

Browse files
committed
Merge branch 'js/lift-parent-count-limit'
There is no reason to have a hardcoded upper limit of the number of parents for an octopus merge, created via the graft mechanism. * js/lift-parent-count-limit: Remove the line length limit for graft files
2 parents f0f493e + e228c17 commit 3b9d69e

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

builtin/blame.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,17 +1803,17 @@ static int prepare_lines(struct scoreboard *sb)
18031803
static int read_ancestry(const char *graft_file)
18041804
{
18051805
FILE *fp = fopen(graft_file, "r");
1806-
char buf[1024];
1806+
struct strbuf buf = STRBUF_INIT;
18071807
if (!fp)
18081808
return -1;
1809-
while (fgets(buf, sizeof(buf), fp)) {
1809+
while (!strbuf_getwholeline(&buf, fp, '\n')) {
18101810
/* The format is just "Commit Parent1 Parent2 ...\n" */
1811-
int len = strlen(buf);
1812-
struct commit_graft *graft = read_graft_line(buf, len);
1811+
struct commit_graft *graft = read_graft_line(buf.buf, buf.len);
18131812
if (graft)
18141813
register_commit_graft(graft, 0);
18151814
}
18161815
fclose(fp);
1816+
strbuf_release(&buf);
18171817
return 0;
18181818
}
18191819

commit.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,19 @@ struct commit_graft *read_graft_line(char *buf, int len)
196196
static int read_graft_file(const char *graft_file)
197197
{
198198
FILE *fp = fopen(graft_file, "r");
199-
char buf[1024];
199+
struct strbuf buf = STRBUF_INIT;
200200
if (!fp)
201201
return -1;
202-
while (fgets(buf, sizeof(buf), fp)) {
202+
while (!strbuf_getwholeline(&buf, fp, '\n')) {
203203
/* The format is just "Commit Parent1 Parent2 ...\n" */
204-
int len = strlen(buf);
205-
struct commit_graft *graft = read_graft_line(buf, len);
204+
struct commit_graft *graft = read_graft_line(buf.buf, buf.len);
206205
if (!graft)
207206
continue;
208207
if (register_commit_graft(graft, 1))
209-
error("duplicate graft data: %s", buf);
208+
error("duplicate graft data: %s", buf.buf);
210209
}
211210
fclose(fp);
211+
strbuf_release(&buf);
212212
return 0;
213213
}
214214

t/annotate-tests.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,27 @@ test_expect_success 'blame evil merge' '
116116
check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
117117
'
118118

119+
test_expect_success 'blame huge graft' '
120+
test_when_finished "git checkout branch2" &&
121+
test_when_finished "rm -f .git/info/grafts" &&
122+
graft= &&
123+
for i in 0 1 2
124+
do
125+
for j in 0 1 2 3 4 5 6 7 8 9
126+
do
127+
git checkout --orphan "$i$j" &&
128+
printf "%s\n" "$i" "$j" >file &&
129+
test_tick &&
130+
GIT_AUTHOR_NAME=$i$j [email protected] \
131+
git commit -a -m "$i$j" &&
132+
commit=$(git rev-parse --verify HEAD) &&
133+
graft="$graft$commit "
134+
done
135+
done &&
136+
printf "%s " $graft >.git/info/grafts &&
137+
check_count -h 00 01 1 10 1
138+
'
139+
119140
test_expect_success 'setup incomplete line' '
120141
echo "incomplete" | tr -d "\\012" >>file &&
121142
GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="[email protected]" \

t/t6101-rev-parse-parents.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ test_expect_success 'setup' '
2020
test_commit start2 &&
2121
git checkout master &&
2222
git merge -m next start2 &&
23-
test_commit final
23+
test_commit final &&
24+
25+
test_seq 40 |
26+
while read i
27+
do
28+
git checkout --orphan "b$i" &&
29+
test_tick &&
30+
git commit --allow-empty -m "$i" &&
31+
commit=$(git rev-parse --verify HEAD) &&
32+
printf "$commit " >>.git/info/grafts
33+
done
2434
'
2535

2636
test_expect_success 'start is valid' '
@@ -79,6 +89,10 @@ test_expect_success 'final^1^! = final^1 ^final^1^1 ^final^1^2' '
7989
test_cmp expect actual
8090
'
8191

92+
test_expect_success 'large graft octopus' '
93+
test_cmp_rev_output b31 "git rev-parse --verify b1^30"
94+
'
95+
8296
test_expect_success 'repack for next test' '
8397
git repack -a -d
8498
'

0 commit comments

Comments
 (0)