[PATCH v2] git-p4: fix fast import when empty commit is first

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Alisha Kim <pril@xxxxxxx>

When executing p4 sync by specifying an excluded path, an empty commit
will be created if there is only a change in the excluded path in
revision.
If git-p4.keepEmptyCommits is turned off and an empty commit is the
first, fast-import will fail. Change the return type of the commit
function from void to bool and return whether a commit has been
created. This failure was prevented by modifying initialParent
to be initialized only when a commit was actually created.

Signed-off-by: Alisha Kim <pril@xxxxxxx>
---
    git-p4: fix fast import when empty commit is first
    
    When executing p4 sync by specifying an excluded path, an empty commit
    will be created if there is only a change in the excluded path in
    revision. If git-p4.keepEmptyCommits is turned off and an empty commit
    is the first, fast-import will fail. Change the return type of the
    commit function from void to bool and return whether a commit has been
    created. This failure was prevented by modifying initialParent to be
    initialized only when a commit was actually created.
    
    The error log is as follows Ignoring revision 14035 as it would produce
    an empty commit. fast-import failed: warning: Not updating
    refs/heads/p4/master (new tip new commit hash does not contain parent
    commit hash) fast-import statistics: ...

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1609%2Fdaebo01%2Fgit-p4-pr-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1609/daebo01/git-p4-pr-v2
Pull-Request: https://github.com/git/git/pull/1609

Range-diff vs v1:

 1:  f7c4fa18c4c ! 1:  1de9ac6dbf8 git-p4: fix fast import when empty commit is first
     @@ Commit message
          will be created if there is only a change in the excluded path in
          revision.
          If git-p4.keepEmptyCommits is turned off and an empty commit is the
     -    first, fast-import will fail.
     +    first, fast-import will fail. Change the return type of the commit
     +    function from void to bool and return whether a commit has been
     +    created. This failure was prevented by modifying initialParent
     +    to be initialized only when a commit was actually created.
      
          Signed-off-by: Alisha Kim <pril@xxxxxxx>
      
     @@ git-p4.py: class P4Sync(Command, P4UserMap):
                       else:
                           files = self.extractFilesFromCommit(description)
      -                    self.commit(description, files, self.branch,
     -+                    isCommitted = self.commit(description, files, self.branch,
     ++                    haveCommitted = self.commit(description, files, self.branch,
                                       self.initialParent)
                           # only needed once, to connect to the previous commit
      -                    self.initialParent = ""
     -+                    if isCommitted:
     ++                    if haveCommitted:
      +                        self.initialParent = ""
      +
                   except IOError:


 git-p4.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index 0eb3bb4c47d..1e3c0e815f0 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3466,7 +3466,7 @@ class P4Sync(Command, P4UserMap):
         if not files and not allow_empty:
             print('Ignoring revision {0} as it would produce an empty commit.'
                 .format(details['change']))
-            return
+            return False
 
         self.gitStream.write("commit %s\n" % branch)
         self.gitStream.write("mark :%s\n" % details["change"])
@@ -3533,6 +3533,8 @@ class P4Sync(Command, P4UserMap):
                     print("Tag %s does not match with change %s: file count is different."
                            % (labelDetails["label"], change))
 
+        return True
+
     def getLabels(self):
         """Build a dictionary of changelists and labels, for "detect-labels"
            option.
@@ -3876,10 +3878,12 @@ class P4Sync(Command, P4UserMap):
                             self.commit(description, filesForCommit, branch, parent)
                 else:
                     files = self.extractFilesFromCommit(description)
-                    self.commit(description, files, self.branch,
+                    haveCommitted = self.commit(description, files, self.branch,
                                 self.initialParent)
                     # only needed once, to connect to the previous commit
-                    self.initialParent = ""
+                    if haveCommitted:
+                        self.initialParent = ""
+
             except IOError:
                 print(self.gitError.read())
                 sys.exit(1)

base-commit: cfb8a6e9a93adbe81efca66e6110c9b4d2e57169
-- 
gitgitgadget




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux