summaryrefslogtreecommitdiff
path: root/git-p4.py
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-12-27 00:11:42 -0800
committerJunio C Hamano <gitster@pobox.com>2016-12-27 00:11:42 -0800
commitf723df581075ae70252a93ba91dcd017f338236e (patch)
treebbf75e7b9b949e2b6c2e0cfa8d0ab57b6319783a /git-p4.py
parent08721a056b0370e0de002162dfc5578548c0c116 (diff)
parentdf8a9e86db13f2b8becfde8ed69f80127ba14e20 (diff)
downloadgit-f723df581075ae70252a93ba91dcd017f338236e.tar.gz
Merge branch 'ld/p4-compare-dir-vs-symlink'
"git p4" misbehaved when swapping a directory and a symbolic link. * ld/p4-compare-dir-vs-symlink: git-p4: avoid crash adding symlinked directory
Diffstat (limited to 'git-p4.py')
-rwxr-xr-xgit-p4.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/git-p4.py b/git-p4.py
index 73f5fce4d6..16e3a18e73 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -25,6 +25,7 @@ import stat
import zipfile
import zlib
import ctypes
+import errno
try:
from subprocess import CalledProcessError
@@ -1571,7 +1572,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"])
@@ -1586,10 +1587,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')
@@ -1607,6 +1615,7 @@ class P4Submit(Command, P4UserMap):
filesToDelete = set()
editedFiles = set()
pureRenameCopy = set()
+ symlinks = set()
filesToChangeExecBit = {}
all_files = list()
@@ -1626,6 +1635,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:
@@ -1767,7 +1781,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")