Skip to content

Commit 4007617

Browse files
committed
Merge branch 'ps/commit-with-message-syntax-fix'
The syntax ":/<text>" to name the latest commit with the matching text was broken with a recent change, which has been corrected. * ps/commit-with-message-syntax-fix: object-name: fix reversed ordering with ":/<text>" revisions
2 parents 67761be + 0ff919e commit 4007617

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

object-name.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ static int get_oid_oneline(struct repository *r,
14011401
const char *prefix, struct object_id *oid,
14021402
const struct commit_list *list)
14031403
{
1404-
struct commit_list *copy = NULL;
1404+
struct commit_list *copy = NULL, **copy_tail = &copy;
14051405
const struct commit_list *l;
14061406
int found = 0;
14071407
int negative = 0;
@@ -1423,7 +1423,7 @@ static int get_oid_oneline(struct repository *r,
14231423

14241424
for (l = list; l; l = l->next) {
14251425
l->item->object.flags |= ONELINE_SEEN;
1426-
commit_list_insert(l->item, &copy);
1426+
copy_tail = &commit_list_insert(l->item, copy_tail)->next;
14271427
}
14281428
while (copy) {
14291429
const char *p, *buf;

t/t1500-rev-parse.sh

+15
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,19 @@ test_expect_success '--short= truncates to the actual hash length' '
309309
test_cmp expect actual
310310
'
311311

312+
test_expect_success ':/ and HEAD^{/} favor more recent matching commits' '
313+
test_when_finished "rm -rf repo" &&
314+
git init repo &&
315+
(
316+
cd repo &&
317+
test_commit common-old &&
318+
test_commit --no-tag common-new &&
319+
git rev-parse HEAD >expect &&
320+
git rev-parse :/common >actual &&
321+
test_cmp expect actual &&
322+
git rev-parse HEAD^{/common} >actual &&
323+
test_cmp expect actual
324+
)
325+
'
326+
312327
test_done

0 commit comments

Comments
 (0)