git-p4: handle symlinked directories
PATCH v2 1/1 git-p4: handle symlinked directories
This is an updated version of my earlier git-p4 symlink fix.
This one now treats addition of all symlinks in the same way, rather than displaying the target file if linking to a file, or just the link target name if it's a directory.
That makes the git-p4 summary behave more like normal git commands (which also treat symlinks uniformaly).
This is a very slight change in behaviour, but I don't think it can break anything since it is only when generating the summary that goes after the P4 change template.
Luke Diamand (1):
git-p4: avoid crash adding symlinked directory
git-p4.py | 26 ++++++++++++++++++++------ t/t9830-git-p4-symlink-dir.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 t/t9830-git-p4-symlink-dir.sh
Signature · 1 line
2.8.2.703.g78b384c.dirty
PATCH v2 1/1 git-p4: avoid crash adding symlinked directory
When submitting to P4, if git-p4 came across a symlinked directory, then during the generation of the submit diff, it would try to open it as a normal file and fail.
Spot symlinks (of any type) and output a description of the symlink instead.
Add a test case.
--- git-p4.py | 26 ++++++++++++++++++++------ t/t9830-git-p4-symlink-dir.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 t/t9830-git-p4-symlink-dir.sh
git-p4.py +20 -6
@@ -25,6 +25,7 @@ import stat import zipfile import zlib import ctypes +import errno try: from subprocess import CalledProcessError
@@ -1538,7 +1539,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"])
@@ -1553,10 +1554,17 @@ class P4Submit(Command, P4UserMap): 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')
@@ -1574,6 +1582,7 @@ class P4Submit(Command, P4UserMap): filesToDelete = set() editedFiles = set() pureRenameCopy = set() + symlinks = set() filesToChangeExecBit = {} for line in diff:
@@ -1590,6 +1599,11 @@ class P4Submit(Command, P4UserMap): 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:
@@ -1727,7 +1741,7 @@ class P4Submit(Command, P4UserMap): 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")
t/t9830-git-p4-symlink-dir.sh new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.8.2.703.g78b384c.dirty