{"thread":{"id":"44614","subject":"[PATCH v1] git-p4: fix empty file processing for large file system backend GitLFS","startedAt":"2016-12-04T16:03:40Z","lastAt":"2016-12-04T16:03:40Z","messageCount":1,"participants":["larsxschneider@gmail.com"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"306895","messageId":"20161204160337.41493-1-larsxschneider@gmail.com","threadId":"44614","inReplyTo":null,"subject":"[PATCH v1] git-p4: fix empty file processing for large file system backend GitLFS","fromName":"","fromEmail":"larsxschneider@gmail.com","sentAt":"2016-12-04T16:03:37Z","receivedAt":"2016-12-04T16:03:40Z","isPatch":true,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"From: Lars Schneider <lars.schneider@autodesk.com>\n\nIf git-p4 tried to store an empty file in GitLFS then it crashed while\nparsing the pointer file:\n\n  oid = re.search(r'^oid \\w+:(\\w+)', pointerFile, re.MULTILINE).group(1)\n  AttributeError: 'NoneType' object has no attribute 'group'\n\nThis happens because GitLFS does not create a pointer file for an empty\nfile. Teach git-p4 this behavior to fix the problem and add a test case.\n\nSigned-off-by: Lars Schneider <larsxschneider@gmail.com>\n---\n\nNotes:\n    Base Commit: 454cb6b (v2.11.0)\n    Diff on Web: https://github.com/git/git/compare/454cb6b...larsxschneider:b717fde\n    Checkout:    git fetch https://github.com/larsxschneider/git git-p4/empty-files-v1 && git checkout b717fde\n\n git-p4.py                 | 29 +++++++++++++++++------------\n t/t9824-git-p4-git-lfs.sh |  2 ++\n 2 files changed, 19 insertions(+), 12 deletions(-)\n\ndiff --git a/git-p4.py b/git-p4.py\nindex fd5ca52462..ccfb68105f 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -1005,18 +1005,20 @@ class LargeFileSystem(object):\n            steps.\"\"\"\n         if self.exceedsLargeFileThreshold(relPath, contents) or self.hasLargeFileExtension(relPath):\n             contentTempFile = self.generateTempFile(contents)\n-            (git_mode, contents, localLargeFile) = self.generatePointer(contentTempFile)\n-\n-            # Move temp file to final location in large file system\n-            largeFileDir = os.path.dirname(localLargeFile)\n-            if not os.path.isdir(largeFileDir):\n-                os.makedirs(largeFileDir)\n-            shutil.move(contentTempFile, localLargeFile)\n-            self.addLargeFile(relPath)\n-            if gitConfigBool('git-p4.largeFilePush'):\n-                self.pushFile(localLargeFile)\n-            if verbose:\n-                sys.stderr.write(\"%s moved to large file system (%s)\\n\" % (relPath, localLargeFile))\n+            (pointer_git_mode, contents, localLargeFile) = self.generatePointer(contentTempFile)\n+            if pointer_git_mode:\n+                git_mode = pointer_git_mode\n+            if localLargeFile:\n+                # Move temp file to final location in large file system\n+                largeFileDir = os.path.dirname(localLargeFile)\n+                if not os.path.isdir(largeFileDir):\n+                    os.makedirs(largeFileDir)\n+                shutil.move(contentTempFile, localLargeFile)\n+                self.addLargeFile(relPath)\n+                if gitConfigBool('git-p4.largeFilePush'):\n+                    self.pushFile(localLargeFile)\n+                if verbose:\n+                    sys.stderr.write(\"%s moved to large file system (%s)\\n\" % (relPath, localLargeFile))\n         return (git_mode, contents)\n \n class MockLFS(LargeFileSystem):\n@@ -1056,6 +1058,9 @@ class GitLFS(LargeFileSystem):\n            the actual content. Return also the new location of the actual\n            content.\n            \"\"\"\n+        if os.path.getsize(contentFile) == 0:\n+            return (None, '', None)\n+\n         pointerProcess = subprocess.Popen(\n             ['git', 'lfs', 'pointer', '--file=' + contentFile],\n             stdout=subprocess.PIPE\ndiff --git a/t/t9824-git-p4-git-lfs.sh b/t/t9824-git-p4-git-lfs.sh\nindex 110a7e7924..734b8db4cb 100755\n--- a/t/t9824-git-p4-git-lfs.sh\n+++ b/t/t9824-git-p4-git-lfs.sh\n@@ -42,6 +42,8 @@ test_expect_success 'Create repo with binary files' '\n \t(\n \t\tcd \"$cli\" &&\n \n+\t\t>file0.dat &&\n+\t\tp4 add file0.dat &&\n \t\techo \"content 1 txt 23 bytes\" >file1.txt &&\n \t\tp4 add file1.txt &&\n \t\techo \"content 2-3 bin 25 bytes\" >file2.dat &&\n-- \n2.11.0\n\n"}]}