Skip to content

Commit 4401639

Browse files
committed
Merge branch 'ps/abbrev-length-before-setup-fix'
Setting core.abbrev too early before the repository set-up (typically in "git clone") caused segfault, which as been corrected. * ps/abbrev-length-before-setup-fix: object-name: don't try to abbreviate to lengths greater than hexsz parse-options-cb: stop clamping "--abbrev=" to hash length config: fix segfault when parsing "core.abbrev" without repo
2 parents 9071453 + 037df60 commit 4401639

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,10 +1460,10 @@ static int git_default_core_config(const char *var, const char *value,
14601460
if (!strcasecmp(value, "auto"))
14611461
default_abbrev = -1;
14621462
else if (!git_parse_maybe_bool_text(value))
1463-
default_abbrev = the_hash_algo->hexsz;
1463+
default_abbrev = GIT_MAX_HEXSZ;
14641464
else {
14651465
int abbrev = git_config_int(var, value, ctx->kvi);
1466-
if (abbrev < minimum_abbrev || abbrev > the_hash_algo->hexsz)
1466+
if (abbrev < minimum_abbrev)
14671467
return error(_("abbrev length out of range: %d"), abbrev);
14681468
default_abbrev = abbrev;
14691469
}

object-name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,
837837
}
838838

839839
oid_to_hex_r(hex, oid);
840-
if (len == hexsz || !len)
840+
if (len >= hexsz || !len)
841841
return hexsz;
842842

843843
mad.repo = r;

parse-options-cb.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
3030
opt->long_name);
3131
if (v && v < MINIMUM_ABBREV)
3232
v = MINIMUM_ABBREV;
33-
else if (startup_info->have_repository && v > the_hash_algo->hexsz)
34-
v = the_hash_algo->hexsz;
3533
}
3634
*(int *)(opt->value) = v;
3735
return 0;

t/t4202-log.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,30 @@ test_expect_success 'log.abbrevCommit configuration' '
12371237
test_cmp expect.whatchanged.full actual
12381238
'
12391239

1240+
test_expect_success '--abbrev-commit with core.abbrev=false' '
1241+
git log --no-abbrev >expect &&
1242+
git -c core.abbrev=false log --abbrev-commit >actual &&
1243+
test_cmp expect actual
1244+
'
1245+
1246+
test_expect_success '--abbrev-commit with --no-abbrev' '
1247+
git log --no-abbrev >expect &&
1248+
git log --abbrev-commit --no-abbrev >actual &&
1249+
test_cmp expect actual
1250+
'
1251+
1252+
test_expect_success '--abbrev-commit with core.abbrev=9000' '
1253+
git log --no-abbrev >expect &&
1254+
git -c core.abbrev=9000 log --abbrev-commit >actual &&
1255+
test_cmp expect actual
1256+
'
1257+
1258+
test_expect_success '--abbrev-commit with --abbrev=9000' '
1259+
git log --no-abbrev >expect &&
1260+
git log --abbrev-commit --abbrev=9000 >actual &&
1261+
test_cmp expect actual
1262+
'
1263+
12401264
test_expect_success 'show added path under "--follow -M"' '
12411265
# This tests for a regression introduced in v1.7.2-rc0~103^2~2
12421266
test_create_repo regression &&

t/t5601-clone.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ test_expect_success 'output from clone' '
4646
test $(grep Clon output | wc -l) = 1
4747
'
4848

49+
test_expect_success 'output from clone with core.abbrev does not crash' '
50+
rm -fr dst &&
51+
echo "Cloning into ${SQ}dst${SQ}..." >expect &&
52+
git -c core.abbrev=12 clone -n "file://$(pwd)/src" dst >actual 2>&1 &&
53+
test_cmp expect actual
54+
'
55+
4956
test_expect_success 'clone does not keep pack' '
5057
5158
rm -fr dst &&

0 commit comments

Comments
 (0)