Skip to contentSkip to conversation

git p4: RCS expansion should not span newlines

PATCH In review Pete Wyckoff 2 participants 2 messages Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CACtYWOYOSxmogJHy70McsRVf0m2PVuu=q+pDZ2-gAza7vpeEiA@mail.gmail.com

#1 lore raw

PATCH 1/1 git p4: RCS expansion should not span newlines

This bug was introduced in cb585a9 (git-p4: keyword flattening fixes, 2011-10-16). The newline character is indeed special, and $File$ expansions should not try to match across multiple lines.

---

[email protected] wrote on Mon, 16 Jul 2012 12:49 -0700:

Quoted 13 lines

Hi. Noticed an apparent bug in git-p4 related to RCS keyword expansion. Some files in our Perforce repository have malformed RCS keywords, e.g. "$Revision:" without a closing $. Perforce doesn't expand these, obviously, but when a change to this file is imported into git, everything up to the next $, on another line much later in the file, is deleted. Seems to be due to multi-line matching of RCS keywords. One fix is:

git-p4.py +0 -0
index f895a24..ae7b431 100755

git-p4.py def p4_keywords_regexp_for_type(base, type_mods): · line 221

Quoted 8 lines
git-p4.py +1 -1
@@ -215,7 +215,7 @@ def p4_keywords_regexp_for_type(base, type_mods):
         pattern = r"""
             \$              # Starts with a dollar, followed by...
             (%s)            # one of the keywords, followed by...
-            (:[^$]+)?       # possibly an old expansion, followed by...
+            (:[^\n$]+)?     # possibly an old expansion, followed by...
             \$              # another dollar
             """ % kwords
         return pattern

Chris,

I finally got around to building a test-case for this. The bug has been in since around 1.7.7, so I won't call this exactly urgent, even though it is blatantly buggy as is.

Will try to get it into the next release.

Thanks,

		-- Pete
 git-p4.py             |  2 +-
 t/t9810-git-p4-rcs.sh | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
git-p4.py +1 -1
index 882b1bb..7d6c928 100755
@@ -227,7 +227,7 @@ def p4_keywords_regexp_for_type(base, type_mods):
         pattern = r"""
             \$              # Starts with a dollar, followed by...
             (%s)            # one of the keywords, followed by...
-            (:[^$]+)?       # possibly an old expansion, followed by...
+            (:[^$\n]+)?     # possibly an old expansion, followed by...
             \$              # another dollar
             """ % kwords
         return pattern
t/t9810-git-p4-rcs.sh +19 -0
index fe30ad8..0c2fc3e 100755
@@ -155,6 +155,25 @@ test_expect_success 'cleanup after failure' '
 	)
 '
 
+# perl $File:: bug check
+test_expect_success 'ktext expansion should not expand multi-line $File::' '
+	(
+		cd "$cli" &&
+		cat >lv.pm <<-\EOF
+		my $wanted = sub { my $f = $File::Find::name;
+				    if ( -f && $f =~ /foo/ ) {
+		EOF
+		p4 add -t ktext lv.pm &&
+		p4 submit -d "lv.pm"
+	) &&
+	test_when_finished cleanup_git &&
+	git p4 clone --dest="$git" //depot &&
+	(
+		cd "$git" &&
+		test_cmp "$cli/lv.pm" lv.pm
+	)
+'
+
 #
 # Do not scrub anything but +k or +ko files.  Sneak a change into
 # the cli file so that submit will get a conflict.  Make sure that
Signature · 1 line
1.7.12.1.457.g468b3ef
#2 lore raw
Quoted 7 lines · Pete Wyckoff

This bug was introduced in cb585a9 (git-p4: keyword flattening fixes, 2011-10-16). The newline character is indeed special, and $File$ expansions should not try to match across multiple lines.

Thanks, I'll queue this for 'maint'. Seems obviously correct to me.

-Peff