@@ -425,6 +425,8 @@ static int count_ident(const char *cp, unsigned long size)
425
425
cnt ++ ;
426
426
break ;
427
427
}
428
+ if (ch == '\n' )
429
+ break ;
428
430
}
429
431
}
430
432
return cnt ;
@@ -455,6 +457,11 @@ static int ident_to_git(const char *path, const char *src, size_t len,
455
457
dollar = memchr (src + 3 , '$' , len - 3 );
456
458
if (!dollar )
457
459
break ;
460
+ if (memchr (src + 3 , '\n' , dollar - src - 3 )) {
461
+ /* Line break before the next dollar. */
462
+ continue ;
463
+ }
464
+
458
465
memcpy (dst , "Id$" , 3 );
459
466
dst += 3 ;
460
467
len -= dollar + 1 - src ;
@@ -470,7 +477,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
470
477
struct strbuf * buf , int ident )
471
478
{
472
479
unsigned char sha1 [20 ];
473
- char * to_free = NULL , * dollar ;
480
+ char * to_free = NULL , * dollar , * spc ;
474
481
int cnt ;
475
482
476
483
if (!ident )
@@ -506,14 +513,31 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
506
513
} else if (src [2 ] == ':' ) {
507
514
/*
508
515
* 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.
510
520
*/
511
521
dollar = memchr (src + 3 , '$' , len - 3 );
512
522
if (!dollar ) {
513
523
/* incomplete keyword, no more '$', so just quit the loop */
514
524
break ;
515
525
}
516
526
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
+
517
541
len -= dollar + 1 - src ;
518
542
src = dollar + 1 ;
519
543
} else {
0 commit comments