{"thread":{"id":"26739","subject":"[PATCH 1/3] git-p4: Teach gitConfig method about arguments.","startedAt":"2011-03-15T12:08:01Z","lastAt":"2011-03-15T21:44:40Z","messageCount":4,"participants":["Tor Arvid Lund","Pete Wyckoff"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"163387","messageId":"1300190883-31833-1-git-send-email-torarvid@gmail.com","threadId":"26739","inReplyTo":null,"subject":"[PATCH 1/3] git-p4: Teach gitConfig method about arguments.","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2011-03-15T12:08:01Z","receivedAt":"2011-03-15T12:08:01Z","isPatch":true,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"With this patch, it is possible to call the gitConfig method with an optional\nargument string, which will be passed to the \"git config\" executable. For\ninstance:\n\ngitConfig(\"core.ignorecase\", \"--bool\")\n\nwill ensure that you get the value \"true\", and won't have to check the returned\nvalue for [1, true, on, yes].\n\nSigned-off-by: Tor Arvid Lund <torarvid@gmail.com>\n---\n contrib/fast-import/git-p4 |    8 ++++++--\n 1 files changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex 7cb479c..4425220 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -333,9 +333,13 @@ def gitBranchExists(branch):\n     return proc.wait() == 0;\n \n _gitConfig = {}\n-def gitConfig(key):\n+def gitConfig(key, args = None): # set args to \"--bool\", for instance\n     if not _gitConfig.has_key(key):\n-        _gitConfig[key] = read_pipe(\"git config %s\" % key, ignore_error=True).strip()\n+        argsFilter = \"\"\n+        if args != None:\n+            argsFilter = \"%s \" % args\n+        cmd = \"git config %s%s\" % (argsFilter, key)\n+        _gitConfig[key] = read_pipe(cmd, ignore_error=True).strip()\n     return _gitConfig[key]\n \n def p4BranchesInGit(branchesAreInRemotes = True):\n-- \n1.7.3.1.68.g06779.dirty\n"},{"id":"163388","messageId":"1300190883-31833-2-git-send-email-torarvid@gmail.com","threadId":"26739","inReplyTo":"1300190883-31833-1-git-send-email-torarvid@gmail.com","subject":"[PATCH 2/3] Teach git-p4 to ignore case in perforce filenames if configured.","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2011-03-15T12:08:02Z","receivedAt":"2011-03-15T12:08:02Z","isPatch":true,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"When files are added to perforce, the path to that file has whichever case\nconfiguration that exists on the machine of the user who added the file.\nWhat does that mean? It means that when Alice adds a file\n\n//depot/DirA/FileA.txt\n\n... and Bob adds:\n\n//depot/dirA/FileB.txt\n\n... we may or may not get a problem. If a user sets the config variable\ngit-p4.ignorecase to \"true\", we will consider //depot/DirA and //depot/dirA\nto be the same directory.\n\nSigned-off-by: Tor Arvid Lund <torarvid@gmail.com>\n---\n contrib/fast-import/git-p4 |   27 ++++++++++++++++++++-------\n 1 files changed, 20 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex 4425220..d47596f 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -456,6 +456,19 @@ def p4ChangesForPaths(depotPaths, changeRange):\n     changelist.sort()\n     return changelist\n \n+def p4PathStartsWith(path, prefix):\n+    # This method tries to remedy a potential mixed-case issue:\n+    #\n+    # If UserA adds  //depot/DirA/file1\n+    # and UserB adds //depot/dira/file2\n+    #\n+    # we may or may not have a problem. If you have core.ignorecase=true,\n+    # we treat DirA and dira as the same directory\n+    ignorecase = gitConfig(\"core.ignorecase\", \"--bool\") == \"true\"\n+    if ignorecase:\n+        return path.lower().startswith(prefix.lower())\n+    return path.startswith(prefix)\n+\n class Command:\n     def __init__(self):\n         self.usage = \"usage: %prog [options]\"\n@@ -603,7 +616,7 @@ class P4Submit(Command):\n                     lastTab = path.rfind(\"\\t\")\n                     if lastTab != -1:\n                         path = path[:lastTab]\n-                        if not path.startswith(self.depotPath):\n+                        if not p4PathStartsWith(path, self.depotPath):\n                             continue\n                 else:\n                     inFilesSection = False\n@@ -941,11 +954,11 @@ class P4Sync(Command):\n             path =  commit[\"depotFile%s\" % fnum]\n \n             if [p for p in self.cloneExclude\n-                if path.startswith (p)]:\n+                if p4PathStartsWith(path, p)]:\n                 found = False\n             else:\n                 found = [p for p in self.depotPaths\n-                         if path.startswith (p)]\n+                         if p4PathStartsWith(path, p)]\n             if not found:\n                 fnum = fnum + 1\n                 continue\n@@ -980,7 +993,7 @@ class P4Sync(Command):\n             prefixes = [re.sub(\"^(//[^/]+/).*\", r'\\1', prefixes[0])]\n \n         for p in prefixes:\n-            if path.startswith(p):\n+            if p4PathStartsWith(path, p):\n                 path = path[len(p):]\n \n         return path\n@@ -991,7 +1004,7 @@ class P4Sync(Command):\n         while commit.has_key(\"depotFile%s\" % fnum):\n             path =  commit[\"depotFile%s\" % fnum]\n             found = [p for p in self.depotPaths\n-                     if path.startswith (p)]\n+                     if p4PathStartsWith(path, p)]\n             if not found:\n                 fnum = fnum + 1\n                 continue\n@@ -1144,7 +1157,7 @@ class P4Sync(Command):\n         # create a commit.\n         new_files = []\n         for f in files:\n-            if [p for p in branchPrefixes if f['path'].startswith(p)]:\n+            if [p for p in branchPrefixes if p4PathStartsWith(f['path'], p)]:\n                 new_files.append (f)\n             else:\n                 sys.stderr.write(\"Ignoring file outside of prefix: %s\\n\" % path)\n@@ -1308,7 +1321,7 @@ class P4Sync(Command):\n                 source = paths[0]\n                 destination = paths[1]\n                 ## HACK\n-                if source.startswith(self.depotPaths[0]) and destination.startswith(self.depotPaths[0]):\n+                if p4PathStartsWith(source, self.depotPaths[0]) and p4PathStartsWith(destination, self.depotPaths[0]):\n                     source = source[len(self.depotPaths[0]):-4]\n                     destination = destination[len(self.depotPaths[0]):-4]\n \n-- \n1.7.3.1.68.g06779.dirty\n"},{"id":"163389","messageId":"1300190883-31833-3-git-send-email-torarvid@gmail.com","threadId":"26739","inReplyTo":"1300190883-31833-1-git-send-email-torarvid@gmail.com","subject":"[PATCH 3/3] git-p4: Fix error message crash in P4Sync.commit.","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2011-03-15T12:08:03Z","receivedAt":"2011-03-15T12:08:03Z","isPatch":true,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"There is an error message that crashes the script because of an invalid ref\nto the non-existing \"path\" variable. It is almost never printed, which\nwould explain why nobody encountered this problem before... But anyway,\nthis oneliner fixes it.\n\nSigned-off-by: Tor Arvid Lund <torarvid@gmail.com>\n---\n contrib/fast-import/git-p4 |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex d47596f..47ba7ad 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -1160,7 +1160,7 @@ class P4Sync(Command):\n             if [p for p in branchPrefixes if p4PathStartsWith(f['path'], p)]:\n                 new_files.append (f)\n             else:\n-                sys.stderr.write(\"Ignoring file outside of prefix: %s\\n\" % path)\n+                sys.stderr.write(\"Ignoring file outside of prefix: %s\\n\" % f['path'])\n \n         self.gitStream.write(\"commit %s\\n\" % branch)\n #        gitStream.write(\"mark :%s\\n\" % details[\"change\"])\n-- \n1.7.3.1.68.g06779.dirty\n"},{"id":"163411","messageId":"20110315214440.GA17971@arf.padd.com","threadId":"26739","inReplyTo":"1300190883-31833-1-git-send-email-torarvid@gmail.com","subject":"Re: [PATCH 1/3] git-p4: Teach gitConfig method about arguments.","fromName":"Pete Wyckoff","fromEmail":"pw@padd.com","sentAt":"2011-03-15T21:44:40Z","receivedAt":"2011-03-15T21:44:40Z","isPatch":true,"sender":{"key":"pw@padd.com","avatar":null},"body":"All three patches in this series look good to me.  They passed\nt9800 tests too.\n\nAcked-By: Pete Wyckoff <pw@padd.com>\n"}]}