From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
This series fixes problems in git-p4, and its tests, so that
git-p4 works on the cygwin platform.
See the wiki for info on how to get started on cygwin:
https://git.wiki.kernel.org/index.php/GitP4
Testing by people who use cygwin would be appreciated. It would
be good to support cygwin more regularly. Anyone who had time
to contribute to testing on cygwin, and reporting problems, would
be welcome.
There's more work requried to support msysgit. Those patches
are not in good enough shape to ship out yet, but a lot of what
is in this series is required for msysgit too.
These patches:
- fix bugs in git-p4 related to issues found on cygwin
- cleanup some ugly code in git-p4 observed in error paths while
getting tests to work on cygwin
- simplify and refactor code and tests to make cygwin changes easier
- handle newline and path issues for cygwin platform
- speed up some aspects of git-p4 by removing extra shell invocations
Pete Wyckoff (21):
git p4: temp branch name should use / even on windows
git p4: remove unused imports
git p4: generate better error message for bad depot path
git p4: fix error message when "describe -s" fails
git p4 test: use client_view to build the initial client
git p4 test: use client_view in t9806
git p4 test: start p4d inside its db dir
git p4 test: translate windows paths for cygwin
git p4: remove unreachable windows \r\n conversion code
git p4: scrub crlf for utf16 files on windows
git p4 test: newline handling
git p4 test: use LineEnd unix in windows tests too
git p4 test: avoid wildcard * in windows
git p4: cygwin p4 client does not mark read-only
git p4 test: disable chmod test for cygwin
git p4: disable read-only attribute before deleting
git p4: avoid shell when mapping users
git p4: avoid shell when invoking git rev-list
git p4: avoid shell when invoking git config --get-all
git p4: avoid shell when calling git config
git p4: introduce gitConfigBool
git-p4.py | 122 ++++++++++++++++++++++++++++--------------
t/lib-git-p4.sh | 60 +++++++++++++++------
t/t9800-git-p4-basic.sh | 5 ++
t/t9802-git-p4-filetype.sh | 117 ++++++++++++++++++++++++++++++++++++++++
t/t9806-git-p4-options.sh | 50 ++++++++---------
t/t9807-git-p4-submit.sh | 14 ++++-
t/t9809-git-p4-client-view.sh | 14 +++--
t/t9812-git-p4-wildcards.sh | 37 ++++++++++---
t/t9815-git-p4-submit-fail.sh | 4 +-
t/test-lib.sh | 3 ++
10 files changed, 330 insertions(+), 96 deletions(-)
--
1.7.12.1.403.g28165e1
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Commit fed2369 (git-p4: Search for parent commit on branch creation,
2012-01-25) uses temporary branches to help find the parent of a
new p4 branch. The temp branches are of the form "git-p4-tmp/%d"
for some p4 change number. Mistakenly, this string was made
using os.path.join() instead of just string concatenation. On
windows, this turns into a backslash (\), which is not allowed in
git branch names.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Found by "pyflakes" checker tool.
Modules shelve, getopt were unused.
Module os.path is exported by os.
Reformat one-per-line as is PEP008 suggested style.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Depot paths must start with //. Exit with a better explanation
when a bad depot path is supplied.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 1 +
t/t9800-git-p4-basic.sh | 5 +++++
2 files changed, 6 insertions(+)
@@ -3035,6 +3035,7 @@ class P4Clone(P4Sync):self.cloneExclude=["/"+pforpinself.cloneExclude]forpindepotPaths:ifnotp.startswith("//"):+sys.stderr.write('Depot paths must start with "//": %s\n'%p)returnFalseifnotself.cloneDestination:
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
The output was a bit nonsensical, including a bare %d. Fix it
to make it easier to understand.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -2679,7 +2679,8 @@ class P4Sync(Command, P4UserMap):ifr.has_key('time'):newestTime=int(r['time'])ifnewestTimeisNone:-die("\"describe -s\" on newest change %d did not give a time")+die("Output from \"describe -s\" on newest change %d did not give a time"%+newestRevision)details["time"]=newestTimeself.updateOptionDict(details)
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Simplify the code a bit by using an existing function.
Signed-off-by: Pete Wyckoff <redacted>
---
t/lib-git-p4.sh | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Use the standard client_view function from lib-git-p4.sh
instead of building one by hand. This requires a bit of
rework, using the current value of $P4CLIENT for the client
name. It also reorganizes the test to isolate changes to
$P4CLIENT and $cli in a subshell.
Signed-off-by: Pete Wyckoff <redacted>
---
t/lib-git-p4.sh | 4 ++--
t/t9806-git-p4-options.sh | 50 ++++++++++++++++++++++-------------------------
2 files changed, 25 insertions(+), 29 deletions(-)
@@ -126,37 +126,33 @@ test_expect_success 'clone --use-client-spec' 'exec>/dev/null&&test_must_failgitp4clone--dest="$git"--use-client-spec)&&-cli2=$(test-path-utilsreal_path"$TRASH_DIRECTORY/cli2")&&+# build a different client+cli2="$TRASH_DIRECTORY/cli2"&&mkdir-p"$cli2"&&test_when_finished"rmdir \"$cli2\""&&-(-cd"$cli2"&&-p4client-i<<-EOF-Client:client2-Description:client2-Root:$cli2-View://depot/sub/...//client2/bus/...-EOF-)&&-P4CLIENT=client2&&test_when_finishedcleanup_git&&-gitp4clone--dest="$git"--use-client-spec//depot/...&&-(-cd"$git"&&-test_path_is_filebus/dir/f4&&-test_path_is_missingfile1-)&&-cleanup_git&&--# same thing again, this time with variable instead of option(-cd"$git"&&-gitinit&&-gitconfiggit-p4.useClientSpectrue&&-gitp4sync//depot/...&&-gitcheckout-bmasterp4/master&&-test_path_is_filebus/dir/f4&&-test_path_is_missingfile1+# group P4CLIENT and cli changes in a sub-shell+P4CLIENT=client2&&+cli="$cli2"&&+client_view"//depot/sub/... //client2/bus/..."&&+gitp4clone--dest="$git"--use-client-spec//depot/...&&+(+cd"$git"&&+test_path_is_filebus/dir/f4&&+test_path_is_missingfile1+)&&+cleanup_git&&+# same thing again, this time with variable instead of option+(+cd"$git"&&+gitinit&&+gitconfiggit-p4.useClientSpectrue&&+gitp4sync//depot/...&&+gitcheckout-bmasterp4/master&&+test_path_is_filebus/dir/f4&&+test_path_is_missingfile1+))'
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
This will avoid having to do native path conversion for
windows. Also may be a bit cleaner always to know that p4d
has that working directory, instead of wherever the function
was called from.
Signed-off-by: Pete Wyckoff <redacted>
---
t/lib-git-p4.sh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
@@ -40,8 +40,11 @@ start_p4d() {mkdir-p"$db""$cli""$git"&&rm-f"$pidfile"&&(-p4d-q-r"$db"-p$P4DPORT&-echo$!>"$pidfile"+cd"$db"&&+{+p4d-q-p$P4DPORT&+echo$!>"$pidfile"+})&&# This gives p4d a long time to start up, as it can be
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Native windows binaries do not understand posix-like
path mapping offered by cygwin. Convert paths to native
using "cygpath --windows" before presenting them to p4d.
This is done using the AltRoots mechanism of p4. Both the
posix and windows forms are put in the client specification,
allowing p4 to find its location by native path even though
the environment reports a different PWD.
Shell operations in tests will use the normal form of $cli,
which will look like a posix path in cygwin, while p4 will
use AltRoots to match against the windows form of the working
directory.
Thanks-to: Sebastian Schuberth [off-list ref]
Thanks-to: Johannes Sixt [off-list ref]
Signed-off-by: Pete Wyckoff <redacted>
---
t/lib-git-p4.sh | 24 ++++++++++++++++++++++--
t/test-lib.sh | 3 +++
2 files changed, 25 insertions(+), 2 deletions(-)
@@ -17,6 +18,24 @@ fitest_done}+# On cygwin, the NT version of Perforce can be used. When giving+# it paths, either on the command-line or in client specifications,+# be sure to use the native windows form.+#+# Older versions of perforce were available compiled natively for+# cygwin. Those do not accept native windows paths, so make sure+# not to convert for them.+native_path(){+path="$1"&&+iftest_have_prereqCYGWIN&&!p4-V|grep-qCYGWIN+then+path=$(cygpath--windows"$path")+else+path=$(test-path-utilsreal_path"$path")+fi&&+echo"$path"+}+# Try to pick a unique port: guess a large number, then hope# no more than one of each test is running.#
@@ -624,12 +624,14 @@ case $(uname -s) in# backslashes in pathspec are converted to '/'# exec does not inherit the PIDtest_set_prereqMINGW+test_set_prereqNOT_CYGWINtest_set_prereqSED_STRIPS_CR;; *CYGWIN*)test_set_prereqPOSIXPERMtest_set_prereqEXECKEEPSPIDtest_set_prereqNOT_MINGW+test_set_prereqCYGWINtest_set_prereqSED_STRIPS_CR;; *)
@@ -637,6 +639,7 @@ case $(uname -s) intest_set_prereqBSLASHPSPECtest_set_prereqEXECKEEPSPIDtest_set_prereqNOT_MINGW+test_set_prereqNOT_CYGWIN;;esac
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Replacing \r\n with \n on windows was added in c1f9197 (Replace
\r\n with \n when importing from p4 on Windows, 2007-05-24), to
work around an oddity with "p4 print" on windows. Text files
are printed with "\r\r\n" endings, regardless of whether they
were created on unix or windows, and regardless of the client
LineEnd setting.
As of d2c6dd3 (use p4CmdList() to get file contents in Python
dicts. This is more robust., 2007-05-23), git-p4 uses "p4 -G
print", which generates files in a raw format. As the native
line ending format if p4 is \n, there will be no \r\n in the
raw text.
Actually, it is possible to generate a text file so that the
p4 representation includes embedded \r\n, even though this is not
normal on either windows or unix. In that case the code would
have mistakenly stripped them out, but now they will be left
intact.
More information on how p4 deals with line endings is here:
http://kb.perforce.com/article/63
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 9 ---------
1 file changed, 9 deletions(-)
@@ -2064,15 +2064,6 @@ class P4Sync(Command, P4UserMap):print"\nIgnoring apple filetype file %s"%file['depotFile']return-# Perhaps windows wants unicode, utf16 newlines translated too;-# but this is not doing it.-ifself.isWindowsandtype_base=="text":-mangled=[]-fordataincontents:-data=data.replace("\r\n","\n")-mangled.append(data)-contents=mangled-# Note that we do not try to de-mangle keywords on utf16 files,# even though in theory somebody may want that.pattern=p4_keywords_regexp_for_type(type_base,type_mods)
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Files of type utf16 are handled with "p4 print" instead of the
normal "p4 -G print" interface due to how the latter does not
produce correct output. See 55aa571 (git-p4: handle utf16
filetype properly, 2011-09-17) for details.
On windows, though, "p4 print" can not be told which line
endings to use, as there is no underlying client, and always
chooses crlf, even for utf16 files. Convert the \r\n into \n
when importing utf16 files.
The fix for this is complex, in that the problem is a property
of the NT version of p4. There are old versions of p4 that
were compiled directly for cygwin that should not be subjected
to text replacement. The right check here, then, is to look
at the p4 version, not the OS version. Note also that on cygwin,
platform.system() is "CYGWIN_NT-5.1" or similar, not "Windows".
Add a function to memoize the p4 version string and use it to
check for "/NT", indicating the Windows build of p4.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
@@ -147,6 +147,22 @@ def p4_system(cmd):expand=isinstance(real_cmd,basestring)subprocess.check_call(real_cmd,shell=expand)+_p4_version_string=None+defp4_version_string():+"""Read the version string, showing just the last line, which+hopefullyistheinterestingversionbit.++$p4-V+Perforce-TheFastSoftwareConfigurationManagementSystem.+Copyright1995-2011PerforceSoftware.Allrightsreserved.+Rev.P4/NTX86/2011.1/393975(2011/12/16).+"""+global_p4_version_string+ifnot_p4_version_string:+a=p4_read_pipe_lines(["-V"])+_p4_version_string=a[-1].rstrip()+return_p4_version_string+defp4_integrate(src,dest):p4_system(["integrate","-Dt",wildcard_encode(src),wildcard_encode(dest)])
@@ -1903,7 +1919,6 @@ class P4Sync(Command, P4UserMap):self.syncWithOrigin=Trueself.importIntoRemotes=Trueself.maxChanges=""-self.isWindows=(platform.system()=="Windows")self.keepRepoPath=Falseself.depotPaths=Noneself.p4BranchesInGit=[]
@@ -2048,7 +2063,14 @@ class P4Sync(Command, P4UserMap):# operations. utf16 is converted to ascii or utf8, perhaps.# But ascii text saved as -t utf16 is completely mangled.# Invoke print -o to get the real contents.+#+# On windows, the newlines will always be mangled by print, so put+# them back too. This is not needed to the cygwin windows version,+# just the native "NT" type.+#text=p4_read_pipe(['print','-q','-o','-',file['depotFile']])+ifp4_version_string().find("/NT")>=0:+text=text.replace("\r\n","\n")contents=[text]iftype_base=="apple":
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
P4 stores newlines in the depos as \n. By default, git does this
too, both on unix and windows. Test to make sure that this stays
true.
Both git and p4 have mechanisms to use \r\n in the working
directory. Exercise these.
Signed-off-by: Pete Wyckoff <redacted>
---
t/t9802-git-p4-filetype.sh | 117 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 117 insertions(+)
@@ -8,6 +8,123 @@ test_expect_success 'start p4d' 'start_p4d'+#+# This series of tests checks newline handling Both p4 and+# git store newlines as \n, and have options to choose how+# newlines appear in checked-out files.+#+test_expect_success'p4 client newlines, unix''+(+cd"$cli"&&+p4client-o|sed"/LineEnd/s/:.*/:unix/"|p4client-i&&+printf"unix\ncrlf\n">f-unix&&+printf"unix\r\ncrlf\r\n">f-unix-as-crlf&&+p4add-ttextf-unix&&+p4submit-df-unix&&++# LineEnd: unix; should be no change after sync+cpf-unixf-unix-orig&&+p4sync-f&&+test_cmpf-unix-origf-unix&&++# make sure stored in repo as unix newlines+# use sed to eat python-appened newline+p4-Gprint//depot/f-unix|marshal_dumpdata2|\+sed\$d>f-unix-p4-print&&+test_cmpf-unix-origf-unix-p4-print&&++# switch to win, make sure lf -> crlf+p4client-o|sed"/LineEnd/s/:.*/:win/"|p4client-i&&+p4sync-f&&+test_cmpf-unix-as-crlff-unix+)+'++test_expect_success'p4 client newlines, win''+(+cd"$cli"&&+p4client-o|sed"/LineEnd/s/:.*/:win/"|p4client-i&&+printf"win\r\ncrlf\r\n">f-win&&+printf"win\ncrlf\n">f-win-as-lf&&+p4add-ttextf-win&&+p4submit-df-win&&++# LineEnd: win; should be no change after sync+cpf-winf-win-orig&&+p4sync-f&&+test_cmpf-win-origf-win&&++# make sure stored in repo as unix newlines+# use sed to eat python-appened newline+p4-Gprint//depot/f-win|marshal_dumpdata2|\+sed\$d>f-win-p4-print&&+test_cmpf-win-as-lff-win-p4-print&&++# switch to unix, make sure lf -> crlf+p4client-o|sed"/LineEnd/s/:.*/:unix/"|p4client-i&&+p4sync-f&&+test_cmpf-win-as-lff-win+)+'++test_expect_success'ensure blobs store only lf newlines''+test_when_finishedcleanup_git&&+(+cd"$git"&&+gitinit&&+gitp4sync//depot@all&&++# verify the files in .git are stored only with newlines+o=$(gitls-treep4/master--f-unix|cut-f1|cut-d\ -f3)&&+gitcat-fileblob$o>f-unix-blob&&+test_cmp"$cli"/f-unix-origf-unix-blob&&++o=$(gitls-treep4/master--f-win|cut-f1|cut-d\ -f3)&&+gitcat-fileblob$o>f-win-blob&&+test_cmp"$cli"/f-win-as-lff-win-blob&&++rmf-unix-blobf-win-blob+)+'++test_expect_success'gitattributes setting eol=lf produces lf newlines''+test_when_finishedcleanup_git&&+(+# checkout the files and make sure core.eol works as planned+cd"$git"&&+gitinit&&+echo"* eol=lf">.gitattributes&&+gitp4sync//depot@all&&+gitcheckoutmaster&&+test_cmp"$cli"/f-unix-origf-unix&&+test_cmp"$cli"/f-win-as-lff-win+)+'++test_expect_success'gitattributes setting eol=crlf produces crlf newlines''+test_when_finishedcleanup_git&&+(+# checkout the files and make sure core.eol works as planned+cd"$git"&&+gitinit&&+echo"* eol=crlf">.gitattributes&&+gitp4sync//depot@all&&+gitcheckoutmaster&&+test_cmp"$cli"/f-unix-as-crlff-unix&&+test_cmp"$cli"/f-win-origf-win+)+'++test_expect_success'crlf cleanup''+(+cd"$cli"&&+rmf-unix-origf-unix-as-crlf&&+rmf-win-origf-win-as-lf&&+p4client-o|sed"/LineEnd/s/:.*/:unix/"|p4client-i&&+p4sync-f+)+'+ test_expect_success'utf-16 file create''(cd"$cli"&&
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
In all clients, even those created on windows, use unix line
endings. This makes it possible to verify file contents without
doing OS-specific comparisons in all the tests.
Tests in t9802-git-p4-filetype.sh are used to make sure that
the other LineEnd options continue to work.
Signed-off-by: Pete Wyckoff <redacted>
---
t/lib-git-p4.sh | 1 +
1 file changed, 1 insertion(+)
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
This character is not valid in windows filenames, even though
it can appear in p4 depot paths. Avoid using it in tests on
windows, both mingw and cygwin.
Signed-off-by: Pete Wyckoff <redacted>
---
t/t9809-git-p4-client-view.sh | 10 ++++++++--
t/t9812-git-p4-wildcards.sh | 37 +++++++++++++++++++++++++++++--------
2 files changed, 37 insertions(+), 10 deletions(-)
@@ -14,7 +14,10 @@ test_expect_success 'add p4 files with wildcards in the names' 'printf"file2\nhas\nsome\nrandom\ntext\n">file2&&p4addfile2&&echofile-wild-hash>file-wild#hash&&-echofile-wild-star>file-wild\*star&&+iftest_have_prereqNOT_MINGWNOT_CYGWIN+then+echofile-wild-star>file-wild\*star+fi&&echofile-wild-at>file-wild@at&&echofile-wild-percent>file-wild%percent&&p4add-ffile-wild*&&
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
There are some old version of p4, compiled for cygwin, that
treat read-only files differently.
Normally, a file that is not open is read-only, meaning that
"test -w" on the file is false. This works on unix, and it works
on windows using the NT version of p4. The cygwin version
of p4, though, changes the permissions, but does not set the
windows read-only attribute, so "test -w" returns false.
Notice this oddity and make the tests work, even on cygiwn.
Signed-off-by: Pete Wyckoff <redacted>
---
t/lib-git-p4.sh | 13 +++++++++++++
t/t9807-git-p4-submit.sh | 14 ++++++++++++--
t/t9809-git-p4-client-view.sh | 4 ++--
3 files changed, 27 insertions(+), 4 deletions(-)
@@ -150,3 +150,16 @@ client_view() {done)|p4client-i}++is_cli_file_writeable(){+# cygwin version of p4 does not set read-only attr,+# will be marked 444 but -w is true+file="$1"&&+iftest_have_prereqCYGWIN&&p4-V|grep-qCYGWIN+then+stat=$(stat--format=%a"$file")&&+test$stat=644+else+test-w"$file"+fi+}
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
It does not notice chmod +x or -x; there is nothing
for this test to do.
Signed-off-by: Pete Wyckoff <redacted>
---
t/t9815-git-p4-submit-fail.sh | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
@@ -400,7 +400,9 @@ test_expect_success 'cleanup rename after submit cancel' ')'-test_expect_success'cleanup chmod after submit cancel''+# chmods are not recognized in cygwin; git has nothing+# to commit+test_expect_successNOT_CYGWIN'cleanup chmod after submit cancel''test_when_finishedcleanup_git&&gitp4clone--dest="$git"//depot&&(
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
On windows, p4 marks un-edited files as read-only. Not only are
they read-only, but also they cannot be deleted. Remove the
read-only attribute before deleting in both the copy and rename
cases.
This also happens in the RCS cleanup code, where a file is marked
to be deleted, but must first be edited to remove adjust the
keyword lines. Make sure it is editable before patching.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 10 ++++++++++
1 file changed, 10 insertions(+)
@@ -1163,6 +1164,9 @@ class P4Submit(Command, P4UserMap):p4_edit(dest)pureRenameCopy.discard(dest)filesToChangeExecBit[dest]=diff['dst_mode']+ifself.isWindows:+# turn off read-only attribute+os.chmod(dest,stat.S_IWRITE)os.unlink(dest)editedFiles.add(dest)elifmodifier=="R":
@@ -1181,6 +1185,8 @@ class P4Submit(Command, P4UserMap):p4_edit(dest)# with move: already open, writablefilesToChangeExecBit[dest]=diff['dst_mode']ifnotself.p4HasMoveCommand:+ifself.isWindows:+os.chmod(dest,stat.S_IWRITE)os.unlink(dest)filesToDelete.add(src)editedFiles.add(dest)
@@ -1221,6 +1227,10 @@ class P4Submit(Command, P4UserMap):forfileinkwfiles:ifverbose:print"zapping %s with %s"%(line,pattern)+# File is being deleted, so not open in p4. Must+# disable the read-only bit on windows.+ifself.isWindowsandfilenotineditedFiles:+os.chmod(file,stat.S_IWRITE)self.patchRCSKeywords(file,kwfiles[file])fixed_rcs_keywords=True
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
The extra quoting and double-% are unneeded, just to work
around the shell. Instead, avoid the shell indirection.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -982,7 +982,8 @@ class P4Submit(Command, P4UserMap):defp4UserForCommit(self,id):# Return the tuple (perforce user,git email) for a given git commit idself.getUserMapFromPerforceServer()-gitEmail=read_pipe("git log --max-count=1 --format='%%ae' %s"%id)+gitEmail=read_pipe(["git","log","--max-count=1",+"--format=%ae",id])gitEmail=gitEmail.strip()ifnotself.emails.has_key(gitEmail):return(None,gitEmail)
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Invoke git rev-list directly, avoiding the shell, in
P4Submit and P4Sync. The overhead of starting extra
processes is significant in cygwin; this speeds things
up on that platform.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
@@ -514,13 +514,16 @@ def gitBranchExists(branch):returnproc.wait()==0;_gitConfig={}-defgitConfig(key,args=None):# set args to "--bool", for instance++defgitConfig(key,args=None):# set args to "--bool", for instanceifnot_gitConfig.has_key(key):-argsFilter=""-ifargs!=None:-argsFilter="%s "%args-cmd="git config %s%s"%(argsFilter,key)-_gitConfig[key]=read_pipe(cmd,ignore_error=True).strip()+cmd=["git","config"]+ifargs:+assert(args=="--bool")+cmd.append(args)+cmd.append(key)+s=read_pipe(cmd,ignore_error=True)+_gitConfig[key]=s.strip()return_gitConfig[key]defgitConfigList(key):
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:54:53
Make the intent of "--bool" more obvious by returning a direct True
or False value. Convert a couple non-bool users with obvious bool
intent.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 45 ++++++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 19 deletions(-)
@@ -515,17 +515,25 @@ def gitBranchExists(branch):_gitConfig={}-defgitConfig(key,args=None):# set args to "--bool", for instance+defgitConfig(key):ifnot_gitConfig.has_key(key):-cmd=["git","config"]-ifargs:-assert(args=="--bool")-cmd.append(args)-cmd.append(key)+cmd=["git","config",key]s=read_pipe(cmd,ignore_error=True)_gitConfig[key]=s.strip()return_gitConfig[key]+defgitConfigBool(key):+"""Return a bool, using git config --bool. It is True only if the+variableissettotrue,andFalseifsettofalseornotpresent+intheconfig."""++ifnot_gitConfig.has_key(key):+cmd=["git","config","--bool",key]+s=read_pipe(cmd,ignore_error=True)+v=s.strip()+_gitConfig[key]=v=="true"+return_gitConfig[key]+defgitConfigList(key):ifnot_gitConfig.has_key(key):s=read_pipe(["git","config","--get-all",key],ignore_error=True)
@@ -656,8 +664,7 @@ def p4PathStartsWith(path, prefix):## we may or may not have a problem. If you have core.ignorecase=true,# we treat DirA and dira as the same directory-ignorecase=gitConfig("core.ignorecase","--bool")=="true"-ifignorecase:+ifgitConfigBool("core.ignorecase"):returnpath.lower().startswith(prefix.lower())returnpath.startswith(prefix)
@@ -892,7 +899,7 @@ class P4Submit(Command, P4UserMap):self.usage+=" [name of git branch to submit into perforce depot]"self.origin=""self.detectRenames=False-self.preserveUser=gitConfig("git-p4.preserveUser").lower()=="true"+self.preserveUser=gitConfigBool("git-p4.preserveUser")self.dry_run=Falseself.prepare_p4_only=Falseself.conflict_behavior=None
@@ -1000,7 +1007,7 @@ class P4Submit(Command, P4UserMap):(user,email)=self.p4UserForCommit(id)ifnotuser:msg="Cannot find p4 user for email %s in commit %s."%(email,id)-ifgitConfig('git-p4.allowMissingP4Users').lower()=="true":+ifgitConfigBool("git-p4.allowMissingP4Users"):print"%s"%msgelse:die("Error: %s\nSet git-p4.allowMissingP4Users to true to allow this."%msg)
@@ -1095,7 +1102,7 @@ class P4Submit(Command, P4UserMap):message.Returntrueifokaytocontinuewiththesubmit."""# if configured to skip the editing part, just submit-ifgitConfig("git-p4.skipSubmitEdit")=="true":+ifgitConfigBool("git-p4.skipSubmitEdit"):returnTrue# look at the modification time, to check later if the user saved
@@ -1111,7 +1118,7 @@ class P4Submit(Command, P4UserMap):# If the file was not saved, prompt to see if this patch should# be skipped. But skip this verification step if configured so.-ifgitConfig("git-p4.skipSubmitEditCheck")=="true":+ifgitConfigBool("git-p4.skipSubmitEditCheck"):returnTrue# modification time updated means user saved the file
@@ -1211,7 +1218,7 @@ class P4Submit(Command, P4UserMap):# Patch failed, maybe it's just RCS keyword woes. Look through# the patch to see if that's possible.-ifgitConfig("git-p4.attemptRCSCleanup","--bool")=="true":+ifgitConfigBool("git-p4.attemptRCSCleanup"):file=Nonepattern=Nonekwfiles={}
@@ -1506,7 +1513,7 @@ class P4Submit(Command, P4UserMap):sys.exit(128)self.useClientSpec=False-ifgitConfig("git-p4.useclientspec","--bool")=="true":+ifgitConfigBool("git-p4.useclientspec"):self.useClientSpec=Trueifself.useClientSpec:self.clientSpecDirs=getClientSpec()
@@ -1546,7 +1553,7 @@ class P4Submit(Command, P4UserMap):commits.append(line.strip())commits.reverse()-ifself.preserveUseror(gitConfig("git-p4.skipUserNameCheck")=="true"):+ifself.preserveUserorgitConfigBool("git-p4.skipUserNameCheck"):self.checkAuthorship=Falseelse:self.checkAuthorship=True
@@ -1582,7 +1589,7 @@ class P4Submit(Command, P4UserMap):else:self.diffOpts+=" -C%s"%detectCopies-ifgitConfig("git-p4.detectCopiesHarder","--bool")=="true":+ifgitConfigBool("git-p4.detectCopiesHarder"):self.diffOpts+=" --find-copies-harder"#
@@ -1664,7 +1671,7 @@ class P4Submit(Command, P4UserMap):"--format=format:%h %s",c])print"You will have to do 'git p4 sync' and rebase."-ifgitConfig("git-p4.exportLabels","--bool")=="true":+ifgitConfigBool("git-p4.exportLabels"):self.exportLabels=Trueifself.exportLabels:
@@ -2757,7 +2764,7 @@ class P4Sync(Command, P4UserMap):# will use this after clone to set the variableself.useClientSpec_from_options=Trueelse:-ifgitConfig("git-p4.useclientspec","--bool")=="true":+ifgitConfigBool("git-p4.useclientspec"):self.useClientSpec=Trueifself.useClientSpec:self.clientSpecDirs=getClientSpec()
@@ -2954,7 +2961,7 @@ class P4Sync(Command, P4UserMap):sys.stdout.write("%s "%b)sys.stdout.write("\n")-ifgitConfig("git-p4.importLabels","--bool")=="true":+ifgitConfigBool("git-p4.importLabels"):self.importLabels=Trueifself.importLabels:
From: Junio C Hamano <hidden> Date: 2016-06-15 22:54:53
Pete Wyckoff [off-list ref] writes:
quoted hunk
Use the standard client_view function from lib-git-p4.sh
instead of building one by hand. This requires a bit of
rework, using the current value of $P4CLIENT for the client
name. It also reorganizes the test to isolate changes to
$P4CLIENT and $cli in a subshell.
Signed-off-by: Pete Wyckoff <redacted>
---
t/lib-git-p4.sh | 4 ++--
t/t9806-git-p4-options.sh | 50 ++++++++++++++++++++++-------------------------
2 files changed, 25 insertions(+), 29 deletions(-)
From: Junio C Hamano <hidden> Date: 2016-06-15 22:54:53
Pete Wyckoff [off-list ref] writes:
quoted hunk
Simplify the code a bit by using an existing function.
Signed-off-by: Pete Wyckoff <redacted>
---
t/lib-git-p4.sh | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
@@ -74,15 +74,8 @@ start_p4d() {fi# build a client-(-cd"$cli"&&-p4client-i<<-EOF-Client:client-Description:client-Root:$cli-View://depot/...//client/...-EOF-)+client_view"//depot/... //client/..."&&+return0}
Assuming that writing //depot/... //client/... on the next line
indented by a tab is equivalent to writing it on View: line (which I
think it is), this looks like an obviously good reuse of the code.
I have to wonder if the use of printf in client_view implementation
should be tighted up, though.
From: Junio C Hamano <hidden> Date: 2016-06-15 22:54:53
Pete Wyckoff [off-list ref] writes:
quoted hunk
Depot paths must start with //. Exit with a better explanation
when a bad depot path is supplied.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 1 +
t/t9800-git-p4-basic.sh | 5 +++++
2 files changed, 6 insertions(+)
@@ -3035,6 +3035,7 @@ class P4Clone(P4Sync):self.cloneExclude=["/"+pforpinself.cloneExclude]forpindepotPaths:ifnotp.startswith("//"):+sys.stderr.write('Depot paths must start with "//": %s\n'%p)returnFalseifnotself.cloneDestination:
From: Junio C Hamano <hidden> Date: 2016-06-15 22:54:53
Pete Wyckoff [off-list ref] writes:
quoted hunk
The output was a bit nonsensical, including a bare %d. Fix it
to make it easier to understand.
Signed-off-by: Pete Wyckoff <redacted>
---
git-p4.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -2679,7 +2679,8 @@ class P4Sync(Command, P4UserMap):ifr.has_key('time'):newestTime=int(r['time'])ifnewestTimeisNone:-die("\"describe -s\" on newest change %d did not give a time")+die("Output from \"describe -s\" on newest change %d did not give a time"%+newestRevision)
From: Johannes Sixt <hidden> Date: 2016-06-15 22:54:53
Am 28.09.2012 14:04, schrieb Pete Wyckoff:
quoted hunk
It does not notice chmod +x or -x; there is nothing
for this test to do.
Signed-off-by: Pete Wyckoff <redacted>
---
t/t9815-git-p4-submit-fail.sh | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
@@ -400,7 +400,9 @@ test_expect_success 'cleanup rename after submit cancel' ')'-test_expect_success'cleanup chmod after submit cancel''+# chmods are not recognized in cygwin; git has nothing+# to commit+test_expect_successNOT_CYGWIN'cleanup chmod after submit cancel''test_when_finishedcleanup_git&&gitp4clone--dest="$git"//depot&&(
In the git part, you could use test_chmod to change the executable bit.
But if you cannot test it in the p4 part later on, it is probably not
worth it.
-- Hannes
From: Pete Wyckoff <hidden> Date: 2016-06-15 22:55:54
Yes, this really is four months later. Somehow I forgot all
about this series.
gitster@pobox.com wrote on Fri, 28 Sep 2012 12:11 -0700:
Pete Wyckoff [off-list ref] writes:
quoted
Use the standard client_view function from lib-git-p4.sh
instead of building one by hand. This requires a bit of
rework, using the current value of $P4CLIENT for the client
name. It also reorganizes the test to isolate changes to
$P4CLIENT and $cli in a subshell.
Signed-off-by: Pete Wyckoff <redacted>
---
t/lib-git-p4.sh | 4 ++--
t/t9806-git-p4-options.sh | 50 ++++++++++++++++++++++-------------------------
2 files changed, 25 insertions(+), 29 deletions(-)
@@ -126,37 +126,33 @@ test_expect_success 'clone --use-client-spec' 'exec>/dev/null&&test_must_failgitp4clone--dest="$git"--use-client-spec)&&-cli2=$(test-path-utilsreal_path"$TRASH_DIRECTORY/cli2")&&+# build a different client+cli2="$TRASH_DIRECTORY/cli2"&&mkdir-p"$cli2"&&test_when_finished"rmdir \"$cli2\""&&test_when_finishedcleanup_git&&
...
- # same thing again, this time with variable instead of option
(
...
+ # group P4CLIENT and cli changes in a sub-shell
+ P4CLIENT=client2 &&
+ cli="$cli2" &&
+ client_view "//depot/sub/... //client2/bus/..." &&
+ git p4 clone --dest="$git" --use-client-spec //depot/... &&
+ (
+ cd "$git" &&
+ test_path_is_file bus/dir/f4 &&
+ test_path_is_missing file1
+ ) &&
+ cleanup_git &&
Hmm, the use of "test-path-utils real_path" to form cli2 in the
original was not necessary at all?
Thanks, I will make this removal more explicit, putting it in
with 8/21 where it belongs, with explanation.
quoted
+ # same thing again, this time with variable instead of option
+ (
+ cd "$git" &&
+ git init &&
+ git config git-p4.useClientSpec true &&
+ git p4 sync //depot/... &&
+ git checkout -b master p4/master &&
+ test_path_is_file bus/dir/f4 &&
+ test_path_is_missing file1
+ )
Do you need a separate sub-shell inside a sub-shell we are already
in that you called client_view in?
quoted
)
'
The first subshell is to hide P4CLIENT and cli variable changes
from the rest of the tests.
The second is to keep the "cd $git" from changing behavior of the
following "cleanup_git" call. That does "rm -rf $git" which
would fail on some file systems if cwd is still in there. With
just one subshell it would look like:
(
P4CLIENT=client2 &&
git p4 clone .. &&
cd "$git" &&
... do test
cd "$TRASH_DIRECTORY" &&
cleanup_git &&
cd "$git" &&
... more test
)
It's a bit easier to understand with an extra level of shell,
and sticks to the pattern used in the rest of the t98*.
-- Pete