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
This commit is contained in:
commit
f723df5810
26
git-p4.py
26
git-p4.py
@ -25,6 +25,7 @@ import stat
|
|||||||
import zipfile
|
import zipfile
|
||||||
import zlib
|
import zlib
|
||||||
import ctypes
|
import ctypes
|
||||||
|
import errno
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
@ -1571,7 +1572,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
if response == 'n':
|
if response == 'n':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_diff_description(self, editedFiles, filesToAdd):
|
def get_diff_description(self, editedFiles, filesToAdd, symlinks):
|
||||||
# diff
|
# diff
|
||||||
if os.environ.has_key("P4DIFF"):
|
if os.environ.has_key("P4DIFF"):
|
||||||
del(os.environ["P4DIFF"])
|
del(os.environ["P4DIFF"])
|
||||||
@ -1586,10 +1587,17 @@ class P4Submit(Command, P4UserMap):
|
|||||||
newdiff += "==== new file ====\n"
|
newdiff += "==== new file ====\n"
|
||||||
newdiff += "--- /dev/null\n"
|
newdiff += "--- /dev/null\n"
|
||||||
newdiff += "+++ %s\n" % newFile
|
newdiff += "+++ %s\n" % newFile
|
||||||
f = open(newFile, "r")
|
|
||||||
for line in f.readlines():
|
is_link = os.path.islink(newFile)
|
||||||
newdiff += "+" + line
|
expect_link = newFile in symlinks
|
||||||
f.close()
|
|
||||||
|
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')
|
return (diff + newdiff).replace('\r\n', '\n')
|
||||||
|
|
||||||
@ -1607,6 +1615,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
filesToDelete = set()
|
filesToDelete = set()
|
||||||
editedFiles = set()
|
editedFiles = set()
|
||||||
pureRenameCopy = set()
|
pureRenameCopy = set()
|
||||||
|
symlinks = set()
|
||||||
filesToChangeExecBit = {}
|
filesToChangeExecBit = {}
|
||||||
all_files = list()
|
all_files = list()
|
||||||
|
|
||||||
@ -1626,6 +1635,11 @@ class P4Submit(Command, P4UserMap):
|
|||||||
filesToChangeExecBit[path] = diff['dst_mode']
|
filesToChangeExecBit[path] = diff['dst_mode']
|
||||||
if path in filesToDelete:
|
if path in filesToDelete:
|
||||||
filesToDelete.remove(path)
|
filesToDelete.remove(path)
|
||||||
|
|
||||||
|
dst_mode = int(diff['dst_mode'], 8)
|
||||||
|
if dst_mode == 0120000:
|
||||||
|
symlinks.add(path)
|
||||||
|
|
||||||
elif modifier == "D":
|
elif modifier == "D":
|
||||||
filesToDelete.add(path)
|
filesToDelete.add(path)
|
||||||
if path in filesToAdd:
|
if path in filesToAdd:
|
||||||
@ -1767,7 +1781,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
separatorLine = "######## everything below this line is just the diff #######\n"
|
separatorLine = "######## everything below this line is just the diff #######\n"
|
||||||
if not self.prepare_p4_only:
|
if not self.prepare_p4_only:
|
||||||
submitTemplate += separatorLine
|
submitTemplate += separatorLine
|
||||||
submitTemplate += self.get_diff_description(editedFiles, filesToAdd)
|
submitTemplate += self.get_diff_description(editedFiles, filesToAdd, symlinks)
|
||||||
|
|
||||||
(handle, fileName) = tempfile.mkstemp()
|
(handle, fileName) = tempfile.mkstemp()
|
||||||
tmpFile = os.fdopen(handle, "w+b")
|
tmpFile = os.fdopen(handle, "w+b")
|
||||||
|
43
t/t9830-git-p4-symlink-dir.sh
Executable file
43
t/t9830-git-p4-symlink-dir.sh
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='git p4 symlinked directories'
|
||||||
|
|
||||||
|
. ./lib-git-p4.sh
|
||||||
|
|
||||||
|
test_expect_success 'start p4d' '
|
||||||
|
start_p4d
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'symlinked directory' '
|
||||||
|
(
|
||||||
|
cd "$cli" &&
|
||||||
|
: >first_file.t &&
|
||||||
|
p4 add first_file.t &&
|
||||||
|
p4 submit -d "first change"
|
||||||
|
) &&
|
||||||
|
git p4 clone --dest "$git" //depot &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
mkdir -p some/sub/directory &&
|
||||||
|
mkdir -p other/subdir2 &&
|
||||||
|
: > other/subdir2/file.t &&
|
||||||
|
(cd some/sub/directory && ln -s ../../../other/subdir2 .) &&
|
||||||
|
git add some other &&
|
||||||
|
git commit -m "symlinks" &&
|
||||||
|
git config git-p4.skipSubmitEdit true &&
|
||||||
|
git p4 submit -v
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
cd "$cli" &&
|
||||||
|
p4 sync &&
|
||||||
|
test -L some/sub/directory/subdir2
|
||||||
|
test_path_is_file some/sub/directory/subdir2/file.t
|
||||||
|
)
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'kill p4d' '
|
||||||
|
kill_p4d
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in New Issue
Block a user