{"thread":{"id":"29587","subject":"[RFC/PATCHv2 0/2] git-p4: possible RCS keyword fixes","startedAt":"2012-02-09T23:17:20Z","lastAt":"2012-02-12T20:07:00Z","messageCount":7,"participants":["Luke Diamand","Junio C Hamano","Pete Wyckoff"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"184281","messageId":"1328829442-12550-1-git-send-email-luke@diamand.org","threadId":"29587","inReplyTo":null,"subject":"[RFC/PATCHv2 0/2] git-p4: possible RCS keyword fixes","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2012-02-09T23:17:20Z","receivedAt":"2012-02-09T23:17:20Z","isPatch":false,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"Re-rolled with elementary shell coding errors fixed as per comments\nfrom Junio - thanks!\n\nI said before I wouldn't try to fix this, but maybe it could be\nmade to work after all. If nothing else, the failing test\ncase would be useful.\n\nLuke Diamand (2):\n  git-p4: add test case for RCS keywords\n  git-p4: initial demonstration of possible RCS keyword fixup\n\n contrib/fast-import/git-p4 |   43 ++++++++++++++++++++++-\n t/t9810-git-p4-rcs.sh      |   81 ++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 122 insertions(+), 2 deletions(-)\n create mode 100755 t/t9810-git-p4-rcs.sh\n\n-- \n1.7.9.rc2.128.gfce41.dirty\n"},{"id":"184282","messageId":"1328829442-12550-2-git-send-email-luke@diamand.org","threadId":"29587","inReplyTo":"1328829442-12550-1-git-send-email-luke@diamand.org","subject":"[RFC/PATCHv2 1/2] git-p4: add test case for RCS keywords","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2012-02-09T23:17:21Z","receivedAt":"2012-02-09T23:17:21Z","isPatch":false,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"RCS keywords cause problems for git-p4 as perforce always\nexpands them (if +k is set) and so when applying the patch,\ngit reports that the files have been modified by both sides,\nwhen in fact they haven't.\n\nThis adds a failing test case to demonstrate the problem.\n\nSigned-off-by: Luke Diamand <luke@diamand.org>\n---\n t/t9810-git-p4-rcs.sh |   80 +++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 80 insertions(+), 0 deletions(-)\n create mode 100755 t/t9810-git-p4-rcs.sh\n\ndiff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh\nnew file mode 100755\nindex 0000000..c09f83d\n--- /dev/null\n+++ b/t/t9810-git-p4-rcs.sh\n@@ -0,0 +1,80 @@\n+#!/bin/sh\n+\n+test_description='git-p4 rcs keywords'\n+\n+. ./lib-git-p4.sh\n+\n+test_expect_success 'start p4d' '\n+\tstart_p4d\n+'\n+\n+create_kw_file() {\n+\tcat <<\\EOF >\"$1\"\n+/* A file\n+\tId: $Id$\n+\tRevision: $Revision$\n+\tFile: $File$\n+ */\n+int main(int argc, const char **argv) {\n+\treturn 0;\n+}\n+EOF\n+}\n+\n+test_expect_success 'init depot' '\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\techo file1 >file1 &&\n+\t\tp4 add file1 &&\n+\t\tp4 submit -d \"change 1\" &&\n+\t\tcreate_kw_file kwfile1.c &&\n+\t\tp4 add kwfile1.c &&\n+\t\tp4 submit -d \"Add rcw kw file\" kwfile1.c\n+\t)\n+'\n+\n+p4_append_to_file() {\n+\tf=$1 &&\n+\tp4 edit -t ktext \"$f\" &&\n+\techo \"/* $(date) */\" >>\"$f\" &&\n+\tp4 submit -d \"appending a line in p4\"\n+}\n+\n+# Create some files with RCS keywords. If they get modified\n+# elsewhere then the version number gets bumped which then\n+# results in a merge conflict if we touch the RCS kw lines,\n+# even though the change itself would otherwise apply cleanly.\n+test_expect_failure 'cope with rcs keyword expansion damage' '\n+\t\"$GITP4\" clone --dest=\"$git\" //depot &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\t\t(cd ../cli && p4_append_to_file kwfile1.c) &&\n+\t\tperl -n -i -e \"print unless m/Revision:/\" kwfile1.c &&\n+\t\tgit add kwfile1.c &&\n+\t\tgit commit -m \"Zap an RCS kw line\" &&\n+\t\t\"$GITP4\" submit &&\n+\t\t\"$GITP4\" rebase &&\n+\t\tgit diff p4/master &&\n+\t\t\"$GITP4\" commit &&\n+\t\techo \"try modifying in both\" &&\n+\t\tcd \"$cli\" &&\n+\t\tp4 edit kwfile1.c &&\n+\t\techo \"line from p4\" >>kwfile1.c &&\n+\t\tp4 submit -d \"add a line in p4\" kwfile1.c &&\n+\t\tcd \"$git\" &&\n+\t\techo \"line from git at the top\" | cat - kwfile1.c >kwfile1.c.new &&\n+\t\tmv kwfile1.c.new kwfile1.c &&\n+\t\tgit commit -m \"Add line in git at the top\" kwfile1.c &&\n+\t\t\"$GITP4\" rebase &&\n+\t\t\"$GITP4\" submit\n+\t) &&\n+\trm -rf \"$git\" && mkdir \"$git\"\n+'\n+\n+\n+test_expect_success 'kill p4d' '\n+\tkill_p4d\n+'\n+\n+test_done\n-- \n1.7.9.rc2.128.gfce41.dirty\n"},{"id":"184283","messageId":"1328829442-12550-3-git-send-email-luke@diamand.org","threadId":"29587","inReplyTo":"1328829442-12550-1-git-send-email-luke@diamand.org","subject":"[RFC/PATCHv2 2/2] git-p4: initial demonstration of possible RCS keyword fixup","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2012-02-09T23:17:22Z","receivedAt":"2012-02-09T23:17:22Z","isPatch":false,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"This change has a go at showing a possible way to fixup RCS\nkeyword handling in git-p4.\n\nIt does not cope with deleted files.\nIt does not have good test coverage.\nIt does not solve the problem of the incorrect error messages.\nBut it does at least work after a fashion, and could provide\na starting point.\n\nSigned-off-by: Luke Diamand <luke@diamand.org>\n---\n contrib/fast-import/git-p4 |   43 +++++++++++++++++++++++++++++++++++++++++--\n t/t9810-git-p4-rcs.sh      |    1 +\n 2 files changed, 42 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex a78d9c5..205fefd 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -753,6 +753,23 @@ class P4Submit(Command, P4UserMap):\n \n         return result\n \n+    def patchRCSKeywords(self, file):\n+        # Attempt to zap the RCS keywords in a p4 controlled file\n+        p4_edit(file)\n+        (handle, outFileName) = tempfile.mkstemp()\n+        outFile = os.fdopen(handle, \"w+\")\n+        inFile = open(file, \"r\")\n+        for line in inFile.readlines():\n+            line = re.sub(r'\\$(Id|Header|Author|Date|DateTime|Change|File|Revision)[^$]*\\$',\n+                   r'$\\1$', line)\n+            outFile.write(line)\n+        inFile.close()\n+        outFile.close()\n+        # Forcibly overwrite the original file\n+        system(\"cat %s\" % outFileName)\n+        system([\"mv\", \"-f\", outFileName, file])\n+        print \"Patched up RCS keywords in %s\" % file\n+\n     def p4UserForCommit(self,id):\n         # Return the tuple (perforce user,git email) for a given git commit id\n         self.getUserMapFromPerforceServer()\n@@ -918,6 +935,7 @@ class P4Submit(Command, P4UserMap):\n         filesToDelete = set()\n         editedFiles = set()\n         filesToChangeExecBit = {}\n+\n         for line in diff:\n             diff = parseDiffTreeEntry(line)\n             modifier = diff['status']\n@@ -964,9 +982,30 @@ class P4Submit(Command, P4UserMap):\n         patchcmd = diffcmd + \" | git apply \"\n         tryPatchCmd = patchcmd + \"--check -\"\n         applyPatchCmd = patchcmd + \"--check --apply -\"\n+        patch_succeeded = True\n \n         if os.system(tryPatchCmd) != 0:\n+            fixed_rcs_keywords = False\n+            patch_succeeded = False\n             print \"Unfortunately applying the change failed!\"\n+\n+            # Patch failed, maybe it's just RCS keyword woes. Look through\n+            # the patch to see if that's possible.\n+            if gitConfig(\"git-p4.attemptRCSCleanup\",\"--bool\") == \"true\":\n+                file = None\n+                for line in read_pipe_lines(diffcmd):\n+                    m = re.match(r'^diff --git a/(.*)\\s+b/(.*)', line)\n+                    if m:\n+                        file = m.group(1)\n+                    if re.match(r'.*\\$(Id|Header|Author|Date|DateTime|Change|File|Revision)[^$]*\\$', line):\n+                        self.patchRCSKeywords(file)\n+                        fixed_rcs_keywords = True\n+            if fixed_rcs_keywords:\n+                print \"Retrying the patch with RCS keywords cleaned up\"\n+                if os.system(tryPatchCmd) == 0:\n+                    patch_succeeded = True\n+\n+        if not patch_succeeded:\n             print \"What do you want to do?\"\n             response = \"x\"\n             while response != \"s\" and response != \"a\" and response != \"w\":\n@@ -1588,11 +1627,11 @@ class P4Sync(Command, P4UserMap):\n         if type_base in (\"text\", \"unicode\", \"binary\"):\n             if \"ko\" in type_mods:\n                 text = ''.join(contents)\n-                text = re.sub(r'\\$(Id|Header):[^$]*\\$', r'$\\1$', text)\n+                text = re.sub(r'\\$(Id|Header)[^$]*\\$', r'$\\1$', text)\n                 contents = [ text ]\n             elif \"k\" in type_mods:\n                 text = ''.join(contents)\n-                text = re.sub(r'\\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\\$', r'$\\1$', text)\n+                text = re.sub(r'\\$(Id|Header|Author|Date|DateTime|Change|File|Revision)[^$]*\\$', r'$\\1$', text)\n                 contents = [ text ]\n \n         self.gitStream.write(\"M %s inline %s\\n\" % (git_mode, relPath))\ndiff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh\nindex c09f83d..efe172c 100755\n--- a/t/t9810-git-p4-rcs.sh\n+++ b/t/t9810-git-p4-rcs.sh\n@@ -49,6 +49,7 @@ test_expect_failure 'cope with rcs keyword expansion damage' '\n \t(\n \t\tcd \"$git\" &&\n \t\tgit config git-p4.skipSubmitEdit true &&\n+\t\tgit config git-p4.attemptRCSCleanup true &&\n \t\t(cd ../cli && p4_append_to_file kwfile1.c) &&\n \t\tperl -n -i -e \"print unless m/Revision:/\" kwfile1.c &&\n \t\tgit add kwfile1.c &&\n-- \n1.7.9.rc2.128.gfce41.dirty\n"},{"id":"184286","messageId":"7vzkcrtwl5.fsf@alter.siamese.dyndns.org","threadId":"29587","inReplyTo":"1328829442-12550-1-git-send-email-luke@diamand.org","subject":"Re: [RFC/PATCHv2 0/2] git-p4: possible RCS keyword fixes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-02-09T23:29:10Z","receivedAt":"2012-02-09T23:29:10Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Luke Diamand <luke@diamand.org> writes:\n\n> I said before I wouldn't try to fix this, but maybe it could be\n> made to work after all. If nothing else, the failing test\n> case would be useful.\n\nWill queue in 'pu' so that git-p4 folks can more easily try it out.  The\nvariable needs to be added to Documentation/git-p4.txt after people are\nsatisfied with the resulting code.\n\nThanks.\n"},{"id":"184484","messageId":"20120211234248.GA16691@padd.com","threadId":"29587","inReplyTo":"1328829442-12550-3-git-send-email-luke@diamand.org","subject":"Re: [RFC/PATCHv2 2/2] git-p4: initial demonstration of possible RCS keyword fixup","fromName":"Pete Wyckoff","fromEmail":"pw@padd.com","sentAt":"2012-02-11T23:42:48Z","receivedAt":"2012-02-11T23:42:48Z","isPatch":false,"sender":{"key":"pw@padd.com","avatar":null},"body":"luke@diamand.org wrote on Thu, 09 Feb 2012 23:17 +0000:\n> This change has a go at showing a possible way to fixup RCS\n> keyword handling in git-p4.\n> \n> It does not cope with deleted files.\n> It does not have good test coverage.\n> It does not solve the problem of the incorrect error messages.\n> But it does at least work after a fashion, and could provide\n> a starting point.\n\nI think this has great promise.  Since p4 can always be trusted\nto regenerate the keywords, we should be able to scrub them off\nat will.\n\nI'm debating whether it's best just _always_ to scrub the files\naffected by a diff rather than trying the patch, checking for\nfailure, then scrubbing and trying again.\n\nI'll send along a bunch of test cases I wrote to play around\nwith this.  Your case had too many moving parts for me to\nunderstand.  If there's something in there that isn't covered,\nmaybe you can factor it out into something small?  Feel free\nto merge any of my code in with a future resubmission.\n\nSome comments in this code below:\n\n> @@ -753,6 +753,23 @@ class P4Submit(Command, P4UserMap):\n>  \n>          return result\n>  \n> +    def patchRCSKeywords(self, file):\n> +        # Attempt to zap the RCS keywords in a p4 controlled file\n> +        p4_edit(file)\n> +        (handle, outFileName) = tempfile.mkstemp()\n> +        outFile = os.fdopen(handle, \"w+\")\n> +        inFile = open(file, \"r\")\n> +        for line in inFile.readlines():\n> +            line = re.sub(r'\\$(Id|Header|Author|Date|DateTime|Change|File|Revision)[^$]*\\$',\n\n> +                   r'$\\1$', line)\n\nI added a couple test cases that show how text+k, text+ko and\neverything else need to be handled differently.\n\n> +            outFile.write(line)\n> +        inFile.close()\n> +        outFile.close()\n> +        # Forcibly overwrite the original file\n> +        system(\"cat %s\" % outFileName)\n> +        system([\"mv\", \"-f\", outFileName, file])\n\nWill need a good bit of error handling in the final version.  I\nlike the way you do it a line at a time, avoiding any issues with\ngigantic files.\n\n> @@ -964,9 +982,30 @@ class P4Submit(Command, P4UserMap):\n>          patchcmd = diffcmd + \" | git apply \"\n>          tryPatchCmd = patchcmd + \"--check -\"\n>          applyPatchCmd = patchcmd + \"--check --apply -\"\n> +        patch_succeeded = True\n>  \n>          if os.system(tryPatchCmd) != 0:\n> +            fixed_rcs_keywords = False\n> +            patch_succeeded = False\n>              print \"Unfortunately applying the change failed!\"\n> +\n> +            # Patch failed, maybe it's just RCS keyword woes. Look through\n> +            # the patch to see if that's possible.\n> +            if gitConfig(\"git-p4.attemptRCSCleanup\",\"--bool\") == \"true\":\n> +                file = None\n> +                for line in read_pipe_lines(diffcmd):\n> +                    m = re.match(r'^diff --git a/(.*)\\s+b/(.*)', line)\n> +                    if m:\n> +                        file = m.group(1)\n> +                    if re.match(r'.*\\$(Id|Header|Author|Date|DateTime|Change|File|Revision)[^$]*\\$', line):\n> +                        self.patchRCSKeywords(file)\n> +                        fixed_rcs_keywords = True\n\nThis is a novel approach too.  Instead of just guessing that\nkeywords are causing the conflict, inspect the diff for context\nor edited lines containing keywords.\n\nOr we could just always scrub every file before even trying to\napply patches.\n\n> +            if fixed_rcs_keywords:\n> +                print \"Retrying the patch with RCS keywords cleaned up\"\n> +                if os.system(tryPatchCmd) == 0:\n> +                    patch_succeeded = True\n> +\n> +        if not patch_succeeded:\n>              print \"What do you want to do?\"\n>              response = \"x\"\n>              while response != \"s\" and response != \"a\" and response != \"w\":\n> @@ -1588,11 +1627,11 @@ class P4Sync(Command, P4UserMap):\n>          if type_base in (\"text\", \"unicode\", \"binary\"):\n>              if \"ko\" in type_mods:\n>                  text = ''.join(contents)\n> -                text = re.sub(r'\\$(Id|Header):[^$]*\\$', r'$\\1$', text)\n> +                text = re.sub(r'\\$(Id|Header)[^$]*\\$', r'$\\1$', text)\n\nIn a few spots I see you've taken the \":\" out of the regex.  This\nwill match strings like $Idiot$ that shouldn't be keyword\nexpanded.\n\nImpressed.\n\n\t\t-- Pete\n"},{"id":"184486","messageId":"20120211234438.GB16691@padd.com","threadId":"29587","inReplyTo":"20120211234248.GA16691@padd.com","subject":"[PATCH] git-p4: more RCS tests","fromName":"Pete Wyckoff","fromEmail":"pw@padd.com","sentAt":"2012-02-11T23:44:38Z","receivedAt":"2012-02-11T23:44:38Z","isPatch":true,"sender":{"key":"pw@padd.com","avatar":null},"body":"Add a few smaller test cases.\n\nSigned-off-by: Pete Wyckoff <pw@padd.com>\n---\n t/t9810-git-p4-rcs.sh |  201 +++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 196 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh\nindex a235913..013a951 100755\n--- a/t/t9810-git-p4-rcs.sh\n+++ b/t/t9810-git-p4-rcs.sh\n@@ -8,6 +8,198 @@ test_expect_success 'start p4d' '\n \tstart_p4d\n '\n \n+#\n+# Make one file with keyword lines at the top, and\n+# enough plain text to be able to test modifications\n+# far away from the keywords.\n+#\n+test_expect_success 'init depot' '\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\tcat <<-\\EOF >filek &&\n+\t\t$Id$\n+\t\t/* $Revision$ */\n+\t\t# $Change$\n+\t\tline4\n+\t\tline5\n+\t\tline6\n+\t\tline7\n+\t\tline8\n+\t\tEOF\n+\t\tcp filek fileko &&\n+\t\tsed -i \"s/Revision/Revision: do not scrub me/\" fileko\n+\t\tcp fileko file_text &&\n+\t\tsed -i \"s/Id/Id: do not scrub me/\" file_text\n+\t\tp4 add -t text+k filek &&\n+\t\tp4 submit -d \"filek\" &&\n+\t\tp4 add -t text+ko fileko &&\n+\t\tp4 submit -d \"fileko\" &&\n+\t\tp4 add -t text file_text &&\n+\t\tp4 submit -d \"file_text\"\n+\t)\n+'\n+\n+#\n+# Generate these in a function to make it easy to use single quote marks.\n+#\n+write_scrub_scripts() {\n+\tcat >\"$TRASH_DIRECTORY/scrub_k.py\" <<-\\EOF &&\n+\timport re, sys\n+\tsys.stdout.write(re.sub(r'(?i)\\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\\$', r'$\\1$', sys.stdin.read()))\n+\tEOF\n+\tcat >\"$TRASH_DIRECTORY/scrub_ko.py\" <<-\\EOF\n+\timport re, sys\n+\tsys.stdout.write(re.sub(r'(?i)\\$(Id|Header):[^$]*\\$', r'$\\1$', sys.stdin.read()))\n+\tEOF\n+}\n+\n+test_expect_success 'scrub scripts' '\n+\twrite_scrub_scripts\n+'\n+\n+#\n+# Compare $cli/file to its scrubbed version, should be different.\n+# Compare scrubbed $cli/file to $git/file, should be same.\n+#\n+scrub_k_check() {\n+\tfile=$1 &&\n+\tscrub=\"$TRASH_DIRECTORY/$file\" &&\n+\t\"$PYTHON_PATH\" \"$TRASH_DIRECTORY/scrub_k.py\" <\"$git/$file\" >\"$scrub\" &&\n+\t! test_cmp \"$cli/$file\" \"$scrub\" &&\n+\ttest_cmp \"$git/$file\" \"$scrub\" &&\n+\trm \"$scrub\"\n+}\n+scrub_ko_check() {\n+\tfile=$1 &&\n+\tscrub=\"$TRASH_DIRECTORY/$file\" &&\n+\t\"$PYTHON_PATH\" \"$TRASH_DIRECTORY/scrub_ko.py\" <\"$git/$file\" >\"$scrub\" &&\n+\t! test_cmp \"$cli/$file\" \"$scrub\" &&\n+\ttest_cmp \"$git/$file\" \"$scrub\" &&\n+\trm \"$scrub\"\n+}\n+\n+#\n+# Modify far away from keywords.  If no RCS lines show up\n+# in the diff, there is no conflict.\n+#\n+test_expect_success 'edit far away from RCS lines' '\n+\ttest_when_finished cleanup_git &&\n+\t\"$GITP4\" clone --dest=\"$git\" //depot &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\t\tsed -i \"s/^line7/line7 edit/\" filek &&\n+\t\tgit commit -m \"filek line7 edit\" filek &&\n+\t\t\"$GITP4\" submit &&\n+\t\tscrub_k_check filek\n+\t)\n+'\n+\n+#\n+# Modify near the keywords.  This will require RCS scrubbing.\n+#\n+test_expect_success 'edit near RCS lines' '\n+\ttest_when_finished cleanup_git &&\n+\t\"$GITP4\" clone --dest=\"$git\" //depot &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\t\tgit config git-p4.attemptRCSCleanup true &&\n+\t\tsed -i \"s/^line4/line4 edit/\" filek &&\n+\t\tgit commit -m \"filek line4 edit\" filek &&\n+\t\t\"$GITP4\" submit &&\n+\t\tscrub_k_check filek\n+\t)\n+'\n+\n+#\n+# Modify the keywords themselves.  This also will require RCS scrubbing.\n+#\n+test_expect_success 'edit keyword lines' '\n+\ttest_when_finished cleanup_git &&\n+\t\"$GITP4\" clone --dest=\"$git\" //depot &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\t\tgit config git-p4.attemptRCSCleanup true &&\n+\t\tsed -i \"/Revision/d\" filek &&\n+\t\tgit commit -m \"filek remove Revision line\" filek &&\n+\t\t\"$GITP4\" submit &&\n+\t\tscrub_k_check filek\n+\t)\n+'\n+\n+#\n+# Scrubbing text+ko files should not alter all keywords, just Id, Header.\n+#\n+test_expect_failure 'scrub ko files differently' '\n+\ttest_when_finished cleanup_git &&\n+\t\"$GITP4\" clone --dest=\"$git\" //depot &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\t\tgit config git-p4.attemptRCSCleanup true &&\n+\t\tsed -i \"s/^line4/line4 edit/\" fileko &&\n+\t\tgit commit -m \"fileko line4 edit\" fileko &&\n+\t\t\"$GITP4\" submit &&\n+\t\tscrub_ko_check fileko &&\n+\t\t! scrub_k_check fileko\n+\t)\n+'\n+\n+# hack; git-p4 submit should do it on its own\n+test_expect_success 'cleanup after failure' '\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\tp4 revert ...\n+\t)\n+'\n+\n+#\n+# Do not scrub anything but +k or +ko files.  Sneak a change into\n+# the cli file so that submit will get a conflict.  Make sure that\n+# scrubbing doesn't make a mess of things.\n+#\n+# Assumes that git-p4 exits leaving the p4 file open, with the\n+# conflict-generating patch unapplied.\n+#\n+# This might happen only if the git repo is behind the p4 repo at\n+# submit time, and there is a conflict.\n+#\n+test_expect_failure 'do not scrub plain text' '\n+\ttest_when_finished cleanup_git &&\n+\t\"$GITP4\" clone --dest=\"$git\" //depot &&\n+\t(\n+\t\tcd \"$git\" &&\n+\t\tgit config git-p4.skipSubmitEdit true &&\n+\t\tgit config git-p4.attemptRCSCleanup true &&\n+\t\tsed -i \"s/^line4/line4 edit/\" file_text &&\n+\t\tgit commit -m \"file_text line4 edit\" file_text &&\n+\t\t(\n+\t\t\tcd \"$cli\" &&\n+\t\t\tp4 open file_text &&\n+\t\t\tsed -i \"s/^line5/line5 p4 edit/\" file_text &&\n+\t\t\tp4 submit -d \"file5 p4 edit\"\n+\t\t) &&\n+\t\t! \"$GITP4\" submit &&\n+\t\t(\n+\t\t\t# exepct something like:\n+\t\t\t#    file_text - file(s) not opened on this client\n+\t\t\t# but not copious diff output\n+\t\t\tcd \"$cli\" &&\n+\t\t\tp4 diff file_text >wc &&\n+\t\t\ttest_line_count = 1 wc\n+\t\t)\n+\t)\n+'\n+\n+# hack; git-p4 submit should do it on its own\n+test_expect_success 'cleanup after failure 2' '\n+\t(\n+\t\tcd \"$cli\" &&\n+\t\tp4 revert ...\n+\t)\n+'\n create_kw_file () {\n \tcat <<\\EOF >\"$1\"\n /* A file\n@@ -21,12 +213,12 @@ int main(int argc, const char **argv) {\n EOF\n }\n \n-test_expect_success 'init depot' '\n+test_expect_success 'add kwfile' '\n \t(\n \t\tcd \"$cli\" &&\n \t\techo file1 >file1 &&\n \t\tp4 add file1 &&\n-\t\tp4 submit -d \"change 1\" &&\n+\t\tp4 submit -d \"file1\" &&\n \t\tcreate_kw_file kwfile1.c &&\n \t\tp4 add kwfile1.c &&\n \t\tp4 submit -d \"Add rcw kw file\" kwfile1.c\n@@ -45,6 +237,7 @@ p4_append_to_file () {\n # results in a merge conflict if we touch the RCS kw lines,\n # even though the change itself would otherwise apply cleanly.\n test_expect_failure 'cope with rcs keyword expansion damage' '\n+\ttest_when_finished cleanup_git &&\n \t\"$GITP4\" clone --dest=\"$git\" //depot &&\n \t(\n \t\tcd \"$git\" &&\n@@ -69,11 +262,9 @@ test_expect_failure 'cope with rcs keyword expansion damage' '\n \t\tgit commit -m \"Add line in git at the top\" kwfile1.c &&\n \t\t\"$GITP4\" rebase &&\n \t\t\"$GITP4\" submit\n-\t) &&\n-\trm -rf \"$git\" && mkdir \"$git\"\n+\t)\n '\n \n-\n test_expect_success 'kill p4d' '\n \tkill_p4d\n '\n-- \n1.7.9.213.g57e99\n"},{"id":"184530","messageId":"4F381BE4.2070807@diamand.org","threadId":"29587","inReplyTo":"20120211234248.GA16691@padd.com","subject":"Re: [RFC/PATCHv2 2/2] git-p4: initial demonstration of possible RCS keyword fixup","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2012-02-12T20:07:00Z","receivedAt":"2012-02-12T20:07:00Z","isPatch":false,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On 11/02/12 23:42, Pete Wyckoff wrote:\n>\n> I'll send along a bunch of test cases I wrote to play around\n> with this.  Your case had too many moving parts for me to\n> understand.  If there's something in there that isn't covered,\n> maybe you can factor it out into something small?  Feel free\n> to merge any of my code in with a future resubmission.\n\nThanks - I'm glad you like it! I'll rework it with your code and resubmit.\n\n\n>\n> Some comments in this code below:\n>\n>\n> This is a novel approach too.  Instead of just guessing that\n> keywords are causing the conflict, inspect the diff for context\n> or edited lines containing keywords.\n>\n> Or we could just always scrub every file before even trying to\n> apply patches.\n\nI guess scrubbing every file could get quite slow. We have people \nchecking in hundreds of megabytes of C test vectors....\n\n>\n> In a few spots I see you've taken the \":\" out of the regex.  This\n> will match strings like $Idiot$ that shouldn't be keyword\n> expanded.\n\nGood point - I'll put the ':' back.\n\n>\n> Impressed.\n\nThanks!\n\nUpdated patch series to follow.\n\n\nLuke\n"}]}