From 40f846c35c504a1c2303be5dcca6db069a17b856 Mon Sep 17 00:00:00 2001 From: Pete Wyckoff Date: Tue, 21 Jan 2014 18:16:40 -0500 Subject: git p4: work around p4 bug that causes empty symlinks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Damien Gérard highlights an interesting problem. Some p4 repositories end up with symlinks that have an empty target. It is not possible to create this with current p4, but they do indeed exist. The effect in git p4 is that "p4 print" on the symlink returns an empty string, confusing the curret symlink-handling code. Such broken repositories cause problems in p4 as well, even with no git involved. In p4, syncing to a change that includes a bogus symlink causes errors: //depot/empty-symlink - updating /home/me/p4/empty-symlink rename: /home/me/p4/empty-symlink: No such file or directory and leaves no symlink. In git, replicate the p4 behavior by ignoring these bad symlinks. If, in a later p4 revision, the symlink happens to point to something non-null, the symlink will be replaced properly. Add a big test for all this too. This happens to be a regression introduced by 1292df1 (git-p4: Fix occasional truncation of symlink contents., 2013-08-08) and appeared first in 1.8.5. But it shows up only in p4 repositories of dubious character, so can wait for a proper release. Tested-by: Damien Gérard Signed-off-by: Pete Wyckoff Signed-off-by: Junio C Hamano --- git-p4.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'git-p4.py') diff --git a/git-p4.py b/git-p4.py index 5ea8bb8fc2..e798ecf48c 100755 --- a/git-p4.py +++ b/git-p4.py @@ -2075,7 +2075,14 @@ class P4Sync(Command, P4UserMap): # p4 print on a symlink sometimes contains "target\n"; # if it does, remove the newline data = ''.join(contents) - if data[-1] == '\n': + if not data: + # Some version of p4 allowed creating a symlink that pointed + # to nothing. This causes p4 errors when checking out such + # a change, and errors here too. Work around it by ignoring + # the bad symlink; hopefully a future change fixes it. + print "\nIgnoring empty symlink in %s" % file['depotFile'] + return + elif data[-1] == '\n': contents = [data[:-1]] else: contents = [data] -- cgit v1.2.1 From 0cf1b72a38e6190a7e614bbc53fbb81704a3d4af Mon Sep 17 00:00:00 2001 From: Pete Wyckoff Date: Tue, 21 Jan 2014 18:16:44 -0500 Subject: git p4 test: do not pollute /tmp Generating the submit template for p4 uses tempfile.mkstemp(), which by default puts files in /tmp. For a test that fails, possibly on purpose, this is not cleaned up. Run with TMPDIR pointing into the trash directory so the temp files go away with the test results. To do this required some other minor changes. First, the editor is launched using system(editor + " " + template_file), using shell expansion to build the command string. This doesn't work if editor has a space in it. And is generally unwise as it's easy to fool the shell into doing extra work. Exec the args directly, without shell expansion. Second, without shell expansion, the trick of "P4EDITOR=:" used in the tests doesn't work. Use a real command, true, as the non-interactive editor for testing. Signed-off-by: Pete Wyckoff Signed-off-by: Junio C Hamano --- git-p4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-p4.py') diff --git a/git-p4.py b/git-p4.py index e798ecf48c..a4414b58b9 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1220,7 +1220,7 @@ class P4Submit(Command, P4UserMap): editor = os.environ.get("P4EDITOR") else: editor = read_pipe("git var GIT_EDITOR").strip() - system(editor + " " + template_file) + system([editor, template_file]) # If the file was not saved, prompt to see if this patch should # be skipped. But skip this verification step if configured so. -- cgit v1.2.1 From 79467e61aa30342d7fb17232624ec5ade4cbbe6a Mon Sep 17 00:00:00 2001 From: Pete Wyckoff Date: Tue, 21 Jan 2014 18:16:45 -0500 Subject: git p4: handle files with wildcards when doing RCS scrubbing Commit 9d7d446 (git p4: submit files with wildcards, 2012-04-29) fixed problems with handling files that had p4 wildcard characters, like "@" and "*". But it missed one case, that of RCS keyword scrubbing, which uses "p4 fstat" to extract type information. Fix it by calling wildcard_encode() on the raw filename. Signed-off-by: Pete Wyckoff Signed-off-by: Junio C Hamano --- git-p4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git-p4.py') diff --git a/git-p4.py b/git-p4.py index a4414b58b9..26b874fec9 100755 --- a/git-p4.py +++ b/git-p4.py @@ -310,8 +310,8 @@ def split_p4_type(p4type): # # return the raw p4 type of a file (text, text+ko, etc) # -def p4_type(file): - results = p4CmdList(["fstat", "-T", "headType", file]) +def p4_type(f): + results = p4CmdList(["fstat", "-T", "headType", wildcard_encode(f)]) return results[0]['headType'] # -- cgit v1.2.1 From 2000544330d5b047074d8043042f7cc66157f8f5 Mon Sep 17 00:00:00 2001 From: Pete Wyckoff Date: Tue, 21 Jan 2014 18:16:46 -0500 Subject: git p4: fix an error message when "p4 where" fails When "p4 where" fails, for whatever reason, the error message tries to show an undefined variable. This minor bug applies only when using a client spec, and was introduced recently in 9d57c4a (git p4: implement view spec wildcards with "p4 where", 2013-08-30). Signed-off-by: Pete Wyckoff Signed-off-by: Junio C Hamano --- git-p4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-p4.py') diff --git a/git-p4.py b/git-p4.py index 26b874fec9..cdfa2df5d8 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1871,7 +1871,7 @@ class View(object): # assume error is "... file(s) not in client view" continue if "clientFile" not in res: - die("No clientFile from 'p4 where %s'" % depot_path) + die("No clientFile in 'p4 where' output") if "unmap" in res: # it will list all of them, but only one not unmap-ped continue -- cgit v1.2.1