Merge branch 'gv/p4-multi-path-commit-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 17 Jan 2017 23:19:02 +0000 (15:19 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Jan 2017 23:19:02 +0000 (15:19 -0800)
"git p4" that tracks multile p4 paths imported a single changelist
that touches files in these multiple paths as one commit, followed
by many empty commits. This has been fixed.

* gv/p4-multi-path-commit-fix:
git-p4: fix multi-path changelist empty commits

1  2 
git-p4.py
diff --combined git-p4.py
index 85e8a149cc257e3d42cc75dd77079a55292e46a5,9c5ceed4d13ef51a199698328b0102479ea81510..f427bf6299ed3239ce4e73b674dbb2273dc5e086
+++ b/git-p4.py
@@@ -25,7 -25,6 +25,7 @@@ import sta
  import zipfile
  import zlib
  import ctypes
 +import errno
  
  try:
      from subprocess import CalledProcessError
@@@ -823,7 -822,7 +823,7 @@@ def p4ChangesForPaths(depotPaths, chang
                  die("cannot use --changes-block-size with non-numeric revisions")
              block_size = None
  
-     changes = []
+     changes = set()
  
      # Retrieve changes a block at a time, to prevent running
      # into a MaxResults/MaxScanRows error from the server.
  
          # Insert changes in chronological order
          for line in reversed(p4_read_pipe_lines(cmd)):
-             changes.append(int(line.split(" ")[1]))
+             changes.add(int(line.split(" ")[1]))
  
          if not block_size:
              break
@@@ -1006,20 -1005,18 +1006,20 @@@ class LargeFileSystem(object)
             steps."""
          if self.exceedsLargeFileThreshold(relPath, contents) or self.hasLargeFileExtension(relPath):
              contentTempFile = self.generateTempFile(contents)
 -            (git_mode, contents, localLargeFile) = self.generatePointer(contentTempFile)
 -
 -            # Move temp file to final location in large file system
 -            largeFileDir = os.path.dirname(localLargeFile)
 -            if not os.path.isdir(largeFileDir):
 -                os.makedirs(largeFileDir)
 -            shutil.move(contentTempFile, localLargeFile)
 -            self.addLargeFile(relPath)
 -            if gitConfigBool('git-p4.largeFilePush'):
 -                self.pushFile(localLargeFile)
 -            if verbose:
 -                sys.stderr.write("%s moved to large file system (%s)\n" % (relPath, localLargeFile))
 +            (pointer_git_mode, contents, localLargeFile) = self.generatePointer(contentTempFile)
 +            if pointer_git_mode:
 +                git_mode = pointer_git_mode
 +            if localLargeFile:
 +                # Move temp file to final location in large file system
 +                largeFileDir = os.path.dirname(localLargeFile)
 +                if not os.path.isdir(largeFileDir):
 +                    os.makedirs(largeFileDir)
 +                shutil.move(contentTempFile, localLargeFile)
 +                self.addLargeFile(relPath)
 +                if gitConfigBool('git-p4.largeFilePush'):
 +                    self.pushFile(localLargeFile)
 +                if verbose:
 +                    sys.stderr.write("%s moved to large file system (%s)\n" % (relPath, localLargeFile))
          return (git_mode, contents)
  
  class MockLFS(LargeFileSystem):
@@@ -1059,9 -1056,6 +1059,9 @@@ class GitLFS(LargeFileSystem)
             the actual content. Return also the new location of the actual
             content.
             """
 +        if os.path.getsize(contentFile) == 0:
 +            return (None, '', None)
 +
          pointerProcess = subprocess.Popen(
              ['git', 'lfs', 'pointer', '--file=' + contentFile],
              stdout=subprocess.PIPE
@@@ -1544,7 -1538,7 +1544,7 @@@ class P4Submit(Command, P4UserMap)
              if response == 'n':
                  return False
  
 -    def get_diff_description(self, editedFiles, filesToAdd):
 +    def get_diff_description(self, editedFiles, filesToAdd, symlinks):
          # diff
          if os.environ.has_key("P4DIFF"):
              del(os.environ["P4DIFF"])
              newdiff += "==== new file ====\n"
              newdiff += "--- /dev/null\n"
              newdiff += "+++ %s\n" % newFile
 -            f = open(newFile, "r")
 -            for line in f.readlines():
 -                newdiff += "+" + line
 -            f.close()
 +
 +            is_link = os.path.islink(newFile)
 +            expect_link = newFile in symlinks
 +
 +            if is_link and expect_link:
 +                newdiff += "+%s\n" % os.readlink(newFile)
 +            else:
 +                f = open(newFile, "r")
 +                for line in f.readlines():
 +                    newdiff += "+" + line
 +                f.close()
  
          return (diff + newdiff).replace('\r\n', '\n')
  
          filesToDelete = set()
          editedFiles = set()
          pureRenameCopy = set()
 +        symlinks = set()
          filesToChangeExecBit = {}
  
          for line in diff:
                  filesToChangeExecBit[path] = diff['dst_mode']
                  if path in filesToDelete:
                      filesToDelete.remove(path)
 +
 +                dst_mode = int(diff['dst_mode'], 8)
 +                if dst_mode == 0120000:
 +                    symlinks.add(path)
 +
              elif modifier == "D":
                  filesToDelete.add(path)
                  if path in filesToAdd:
          separatorLine = "######## everything below this line is just the diff #######\n"
          if not self.prepare_p4_only:
              submitTemplate += separatorLine
 -            submitTemplate += self.get_diff_description(editedFiles, filesToAdd)
 +            submitTemplate += self.get_diff_description(editedFiles, filesToAdd, symlinks)
  
          (handle, fileName) = tempfile.mkstemp()
          tmpFile = os.fdopen(handle, "w+b")
          if self.useClientSpec:
              self.clientSpecDirs = getClientSpec()
  
 -        # Check for the existance of P4 branches
 +        # Check for the existence of P4 branches
          branchesDetected = (len(p4BranchesInGit().keys()) > 1)
  
          if self.useClientSpec and not branchesDetected:
@@@ -2293,7 -2274,7 +2293,7 @@@ class P4Sync(Command, P4UserMap)
          self.useClientSpec_from_options = False
          self.clientSpecDirs = None
          self.tempBranches = []
 -        self.tempBranchLocation = "git-p4-tmp"
 +        self.tempBranchLocation = "refs/git-p4-tmp"
          self.largeFileSystem = None
  
          if gitConfig('git-p4.largeFileSystem'):