{"thread":{"id":"12456","subject":"[PATCH] git-p4: Fix import of changesets with file deletions","startedAt":"2008-03-03T10:55:48Z","lastAt":"2008-03-03T10:55:48Z","messageCount":1,"participants":["Simon Hausmann"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"70769","messageId":"200803031155.51015.simon@lst.de","threadId":"12456","inReplyTo":null,"subject":"[PATCH] git-p4: Fix import of changesets with file deletions","fromName":"Simon Hausmann","fromEmail":"simon@lst.de","sentAt":"2008-03-03T10:55:48Z","receivedAt":"2008-03-03T10:55:48Z","isPatch":true,"sender":{"key":"hausmann@kde.org","avatar":"https://gravatar.com/avatar/bc9aad4fb31dce17eb66e690e7b51fe980c62da3c225c785da35dd806b8da778?d=mp&s=160"},"body":"Commit 3a70cdfa42199e16d2d047c286431c4274d65b1a made readP4Files abort quickly\nwhen the changeset only contains files that are marked for deletion with an empty return\nvalue, which caused the commit to not do anything.\n\nThis commit changes readP4Files to distinguish between files that need to be passed to p4\nprint and files that have no content (\"deleted\") and merge them in the returned\nlist.\n\nSigned-off-by: Simon Hausmann <simon@lst.de>\n---\n contrib/fast-import/git-p4 |   45 ++++++++++++++++++++++++-------------------\n 1 files changed, 25 insertions(+), 20 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex be96600..650ea34 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -850,29 +850,32 @@ class P4Sync(Command):\n \n     ## Should move this out, doesn't use SELF.\n     def readP4Files(self, files):\n+        filesForCommit = []\n+        filesToRead = []\n+\n         for f in files:\n+            includeFile = True\n             for val in self.clientSpecDirs:\n                 if f['path'].startswith(val[0]):\n-                    if val[1] > 0:\n-                        f['include'] = True\n-                    else:\n-                        f['include'] = False\n+                    if val[1] <= 0:\n+                        includeFile = False\n                     break\n \n-        files = [f for f in files\n-                 if f['action'] != 'delete' and\n-                 (f.has_key('include') == False or f['include'] == True)]\n+            if includeFile:\n+                filesForCommit.append(f)\n+                if f['action'] != 'delete':\n+                    filesToRead.append(f)\n \n-        if not files:\n-            return []\n+        filedata = []\n+        if len(filesToRead) > 0:\n+            filedata = p4CmdList('-x - print',\n+                                 stdin='\\n'.join(['%s#%s' % (f['path'], f['rev'])\n+                                                  for f in filesToRead]),\n+                                 stdin_mode='w+')\n \n-        filedata = p4CmdList('-x - print',\n-                             stdin='\\n'.join(['%s#%s' % (f['path'], f['rev'])\n-                                              for f in files]),\n-                             stdin_mode='w+')\n-        if \"p4ExitCode\" in filedata[0]:\n-            die(\"Problems executing p4. Error: [%d].\"\n-                % (filedata[0]['p4ExitCode']));\n+            if \"p4ExitCode\" in filedata[0]:\n+                die(\"Problems executing p4. Error: [%d].\"\n+                    % (filedata[0]['p4ExitCode']));\n \n         j = 0;\n         contents = {}\n@@ -896,10 +899,12 @@ class P4Sync(Command):\n \n             contents[stat['depotFile']] = text\n \n-        for f in files:\n-            assert not f.has_key('data')\n-            f['data'] = contents[f['path']]\n-        return files\n+        for f in filesForCommit:\n+            path = f['path']\n+            if contents.has_key(path):\n+                f['data'] = contents[path]\n+\n+        return filesForCommit\n \n     def commit(self, details, files, branch, branchPrefixes, parent = \"\"):\n         epoch = details[\"time\"]\n-- \n1.5.4.3.325.g6d216\n\n"}]}