From: Junio C Hamano Date: Tue, 17 Jan 2017 23:19:02 +0000 (-0800) Subject: Merge branch 'gv/p4-multi-path-commit-fix' into maint X-Git-Tag: v2.11.1~38 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/1d5cb4596db9b4c5c9e8bd25700ecde83dfd18bd?ds=inline;hp=-c Merge branch 'gv/p4-multi-path-commit-fix' into maint "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 --- 1d5cb4596db9b4c5c9e8bd25700ecde83dfd18bd diff --combined git-p4.py index 85e8a149cc,9c5ceed4d1..f427bf6299 --- a/git-p4.py +++ 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. @@@ -842,7 -841,7 +842,7 @@@ # 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"]) @@@ -1559,17 -1553,10 +1559,17 @@@ 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') @@@ -1587,7 -1574,6 +1587,7 @@@ filesToDelete = set() editedFiles = set() pureRenameCopy = set() + symlinks = set() filesToChangeExecBit = {} for line in diff: @@@ -1604,11 -1590,6 +1604,11 @@@ 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: @@@ -1746,7 -1727,7 +1746,7 @@@ 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") @@@ -1953,7 -1934,7 +1953,7 @@@ 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'):