Skip to content

Commit 6c6f878

Browse files
committed
Merge branch 'hg/id-munging'
* hg/id-munging: convert: Keep foreign $Id$ on checkout. convert: Safer handling of $Id$ contraction.
2 parents 8642abc + 07814d9 commit 6c6f878

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

convert.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ static int count_ident(const char *cp, unsigned long size)
425425
cnt++;
426426
break;
427427
}
428+
if (ch == '\n')
429+
break;
428430
}
429431
}
430432
return cnt;
@@ -455,6 +457,11 @@ static int ident_to_git(const char *path, const char *src, size_t len,
455457
dollar = memchr(src + 3, '$', len - 3);
456458
if (!dollar)
457459
break;
460+
if (memchr(src + 3, '\n', dollar - src - 3)) {
461+
/* Line break before the next dollar. */
462+
continue;
463+
}
464+
458465
memcpy(dst, "Id$", 3);
459466
dst += 3;
460467
len -= dollar + 1 - src;
@@ -470,7 +477,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
470477
struct strbuf *buf, int ident)
471478
{
472479
unsigned char sha1[20];
473-
char *to_free = NULL, *dollar;
480+
char *to_free = NULL, *dollar, *spc;
474481
int cnt;
475482

476483
if (!ident)
@@ -506,14 +513,31 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
506513
} else if (src[2] == ':') {
507514
/*
508515
* It's possible that an expanded Id has crept its way into the
509-
* repository, we cope with that by stripping the expansion out
516+
* repository, we cope with that by stripping the expansion out.
517+
* This is probably not a good idea, since it will cause changes
518+
* on checkout, which won't go away by stash, but let's keep it
519+
* for git-style ids.
510520
*/
511521
dollar = memchr(src + 3, '$', len - 3);
512522
if (!dollar) {
513523
/* incomplete keyword, no more '$', so just quit the loop */
514524
break;
515525
}
516526

527+
if (memchr(src + 3, '\n', dollar - src - 3)) {
528+
/* Line break before the next dollar. */
529+
continue;
530+
}
531+
532+
spc = memchr(src + 4, ' ', dollar - src - 4);
533+
if (spc && spc < dollar-1) {
534+
/* There are spaces in unexpected places.
535+
* This is probably an id from some other
536+
* versioning system. Keep it for now.
537+
*/
538+
continue;
539+
}
540+
517541
len -= dollar + 1 - src;
518542
src = dollar + 1;
519543
} else {

t/t0021-conversion.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,21 @@ test_expect_success expanded_in_repo '
6565
echo "\$Id:NoSpaceAtFront \$"
6666
echo "\$Id:NoSpaceAtEitherEnd\$"
6767
echo "\$Id: NoTerminatingSymbol"
68+
echo "\$Id: Foreign Commit With Spaces \$"
69+
echo "\$Id: NoTerminatingSymbolAtEOF"
6870
} > expanded-keywords &&
6971
7072
{
7173
echo "File with expanded keywords"
72-
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
73-
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
74-
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
75-
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
76-
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
77-
echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
74+
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
75+
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
76+
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
77+
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
78+
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
79+
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
7880
echo "\$Id: NoTerminatingSymbol"
81+
echo "\$Id: Foreign Commit With Spaces \$"
82+
echo "\$Id: NoTerminatingSymbolAtEOF"
7983
} > expected-output &&
8084
8185
git add expanded-keywords &&

0 commit comments

Comments
 (0)