Skip to content

Commit 523f0a2

Browse files
committed
Merge branch 'pw/git-p4'
Various "git p4" updates. * pw/git-p4: git p4 doc: use two-line style for options with multiple spellings git p4 test: examine behavior with locked (+l) files git p4: fix an error message when "p4 where" fails git p4: handle files with wildcards when doing RCS scrubbing git p4 test: do not pollute /tmp git p4 test: run as user "author" git p4 test: is_cli_file_writeable succeeds git p4 test: explicitly check p4 wildcard delete git p4: work around p4 bug that causes empty symlinks git p4 test: ensure p4 symlink parsing works git p4 test: wildcards are supported
2 parents 33d4669 + f84cb68 commit 523f0a2

10 files changed

+342
-44
lines changed

Documentation/git-p4.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ All commands except clone accept these options.
168168
--git-dir <dir>::
169169
Set the 'GIT_DIR' environment variable. See linkgit:git[1].
170170

171-
--verbose, -v::
171+
-v::
172+
--verbose::
172173
Provide more progress information.
173174

174175
Sync options
@@ -279,7 +280,8 @@ These options can be used to modify 'git p4 submit' behavior.
279280
Export tags from Git as p4 labels. Tags found in Git are applied
280281
to the perforce working directory.
281282

282-
--dry-run, -n::
283+
-n::
284+
--dry-run::
283285
Show just what commits would be submitted to p4; do not change
284286
state in Git or p4.
285287

git-p4.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ def split_p4_type(p4type):
310310
#
311311
# return the raw p4 type of a file (text, text+ko, etc)
312312
#
313-
def p4_type(file):
314-
results = p4CmdList(["fstat", "-T", "headType", file])
313+
def p4_type(f):
314+
results = p4CmdList(["fstat", "-T", "headType", wildcard_encode(f)])
315315
return results[0]['headType']
316316

317317
#
@@ -1220,7 +1220,7 @@ def edit_template(self, template_file):
12201220
editor = os.environ.get("P4EDITOR")
12211221
else:
12221222
editor = read_pipe("git var GIT_EDITOR").strip()
1223-
system(editor + " " + template_file)
1223+
system([editor, template_file])
12241224

12251225
# If the file was not saved, prompt to see if this patch should
12261226
# be skipped. But skip this verification step if configured so.
@@ -1871,7 +1871,7 @@ def update_client_spec_path_cache(self, files):
18711871
# assume error is "... file(s) not in client view"
18721872
continue
18731873
if "clientFile" not in res:
1874-
die("No clientFile from 'p4 where %s'" % depot_path)
1874+
die("No clientFile in 'p4 where' output")
18751875
if "unmap" in res:
18761876
# it will list all of them, but only one not unmap-ped
18771877
continue
@@ -2075,7 +2075,14 @@ def streamOneP4File(self, file, contents):
20752075
# p4 print on a symlink sometimes contains "target\n";
20762076
# if it does, remove the newline
20772077
data = ''.join(contents)
2078-
if data[-1] == '\n':
2078+
if not data:
2079+
# Some version of p4 allowed creating a symlink that pointed
2080+
# to nothing. This causes p4 errors when checking out such
2081+
# a change, and errors here too. Work around it by ignoring
2082+
# the bad symlink; hopefully a future change fixes it.
2083+
print "\nIgnoring empty symlink in %s" % file['depotFile']
2084+
return
2085+
elif data[-1] == '\n':
20792086
contents = [data[:-1]]
20802087
else:
20812088
contents = [data]

t/lib-git-p4.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,22 @@ P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
4747

4848
P4PORT=localhost:$P4DPORT
4949
P4CLIENT=client
50-
P4EDITOR=:
50+
P4USER=author
51+
P4EDITOR=true
5152
unset P4CHARSET
52-
export P4PORT P4CLIENT P4EDITOR P4CHARSET
53+
export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET
5354

5455
db="$TRASH_DIRECTORY/db"
5556
cli="$TRASH_DIRECTORY/cli"
5657
git="$TRASH_DIRECTORY/git"
5758
pidfile="$TRASH_DIRECTORY/p4d.pid"
5859

60+
# git p4 submit generates a temp file, which will
61+
# not get cleaned up if the submission fails. Don't
62+
# clutter up /tmp on the test machine.
63+
TMPDIR="$TRASH_DIRECTORY"
64+
export TMPDIR
65+
5966
start_p4d() {
6067
mkdir -p "$db" "$cli" "$git" &&
6168
rm -f "$pidfile" &&
@@ -96,12 +103,24 @@ start_p4d() {
96103
return 1
97104
fi
98105

106+
# build a p4 user so [email protected] has an entry
107+
p4_add_user author
108+
99109
# build a client
100110
client_view "//depot/... //client/..." &&
101111

102112
return 0
103113
}
104114

115+
p4_add_user() {
116+
name=$1 &&
117+
p4 user -f -i <<-EOF
118+
User: $name
119+
Email: $name@example.com
120+
FullName: Dr. $name
121+
EOF
122+
}
123+
105124
kill_p4d() {
106125
pid=$(cat "$pidfile")
107126
# it had better exist for the first kill

t/t9802-git-p4-filetype.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,89 @@ test_expect_success 'ignore apple' '
250250
)
251251
'
252252

253+
test_expect_success SYMLINKS 'create p4 symlink' '
254+
cd "$cli" &&
255+
ln -s symlink-target symlink &&
256+
p4 add symlink &&
257+
p4 submit -d "add symlink"
258+
'
259+
260+
test_expect_success SYMLINKS 'ensure p4 symlink parsed correctly' '
261+
test_when_finished cleanup_git &&
262+
git p4 clone --dest="$git" //depot@all &&
263+
(
264+
cd "$git" &&
265+
test -L symlink &&
266+
test $(readlink symlink) = symlink-target
267+
)
268+
'
269+
270+
test_expect_success SYMLINKS 'empty symlink target' '
271+
(
272+
# first create the file as a file
273+
cd "$cli" &&
274+
>empty-symlink &&
275+
p4 add empty-symlink &&
276+
p4 submit -d "add empty-symlink as a file"
277+
) &&
278+
(
279+
# now change it to be a symlink to "target1"
280+
cd "$cli" &&
281+
p4 edit empty-symlink &&
282+
p4 reopen -t symlink empty-symlink &&
283+
rm empty-symlink &&
284+
ln -s target1 empty-symlink &&
285+
p4 add empty-symlink &&
286+
p4 submit -d "make empty-symlink point to target1"
287+
) &&
288+
(
289+
# Hack the p4 depot to make the symlink point to nothing;
290+
# this should not happen in reality, but shows up
291+
# in p4 repos in the wild.
292+
#
293+
# The sed expression changes this:
294+
# @@
295+
# text
296+
# @target1
297+
# @
298+
# to this:
299+
# @@
300+
# text
301+
# @@
302+
#
303+
cd "$db/depot" &&
304+
sed "/@target1/{; s/target1/@/; n; d; }" \
305+
empty-symlink,v >empty-symlink,v.tmp &&
306+
mv empty-symlink,v.tmp empty-symlink,v
307+
) &&
308+
(
309+
# Make sure symlink really is empty. Asking
310+
# p4 to sync here will make it generate errors.
311+
cd "$cli" &&
312+
p4 print -q //depot/empty-symlink#2 >out &&
313+
test ! -s out
314+
) &&
315+
test_when_finished cleanup_git &&
316+
317+
# make sure git p4 handles it without error
318+
git p4 clone --dest="$git" //depot@all &&
319+
320+
# fix the symlink, make it point to "target2"
321+
(
322+
cd "$cli" &&
323+
p4 open empty-symlink &&
324+
rm empty-symlink &&
325+
ln -s target2 empty-symlink &&
326+
p4 submit -d "make empty-symlink point to target2"
327+
) &&
328+
cleanup_git &&
329+
git p4 clone --dest="$git" //depot@all &&
330+
(
331+
cd "$git" &&
332+
test $(readlink empty-symlink) = target2
333+
)
334+
'
335+
253336
test_expect_success 'kill p4d' '
254337
kill_p4d
255338
'

t/t9805-git-p4-skip-submit-edit.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test_expect_success 'init depot' '
1717
)
1818
'
1919

20-
# this works because EDITOR is set to :
20+
# this works because P4EDITOR is set to true
2121
test_expect_success 'no config, unedited, say yes' '
2222
git p4 clone --dest="$git" //depot &&
2323
test_when_finished cleanup_git &&
@@ -90,7 +90,9 @@ test_expect_success 'no config, edited' '
9090
cd "$git" &&
9191
echo line >>file1 &&
9292
git commit -a -m "change 5" &&
93-
P4EDITOR="" EDITOR="\"$TRASH_DIRECTORY/ed.sh\"" git p4 submit &&
93+
P4EDITOR="$TRASH_DIRECTORY/ed.sh" &&
94+
export P4EDITOR &&
95+
git p4 submit &&
9496
p4 changes //depot/... >wc &&
9597
test_line_count = 5 wc
9698
)

t/t9807-git-p4-submit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test_expect_success 'init depot' '
1717
)
1818
'
1919

20-
test_expect_failure 'is_cli_file_writeable function' '
20+
test_expect_success 'is_cli_file_writeable function' '
2121
(
2222
cd "$cli" &&
2323
echo a >a &&

t/t9809-git-p4-client-view.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,28 @@ test_expect_success 'init depot' '
7676
'
7777

7878
# double % for printf
79-
test_expect_success 'unsupported view wildcard %%n' '
79+
test_expect_success 'view wildcard %%n' '
8080
client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
8181
test_when_finished cleanup_git &&
82-
test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
82+
git p4 clone --use-client-spec --dest="$git" //depot
8383
'
8484

85-
test_expect_success 'unsupported view wildcard *' '
85+
test_expect_success 'view wildcard *' '
8686
client_view "//depot/*/bar/... //client/*/bar/..." &&
8787
test_when_finished cleanup_git &&
88-
test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
88+
git p4 clone --use-client-spec --dest="$git" //depot
8989
'
9090

91-
test_expect_success 'wildcard ... only supported at end of spec 1' '
91+
test_expect_success 'wildcard ... in the middle' '
9292
client_view "//depot/.../file11 //client/.../file11" &&
9393
test_when_finished cleanup_git &&
94-
test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
94+
git p4 clone --use-client-spec --dest="$git" //depot
9595
'
9696

97-
test_expect_success 'wildcard ... only supported at end of spec 2' '
97+
test_expect_success 'wildcard ... in the middle and at the end' '
9898
client_view "//depot/.../a/... //client/.../a/..." &&
9999
test_when_finished cleanup_git &&
100-
test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
100+
git p4 clone --use-client-spec --dest="$git" //depot
101101
'
102102

103103
test_expect_success 'basic map' '

t/t9812-git-p4-wildcards.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,56 @@ test_expect_success 'wildcard files submit back to p4, delete' '
161161
)
162162
'
163163

164+
test_expect_success 'p4 deleted a wildcard file' '
165+
(
166+
cd "$cli" &&
167+
echo "wild delete test" >wild@delete &&
168+
p4 add -f wild@delete &&
169+
p4 submit -d "add wild@delete"
170+
) &&
171+
test_when_finished cleanup_git &&
172+
git p4 clone --dest="$git" //depot &&
173+
(
174+
cd "$git" &&
175+
test_path_is_file wild@delete
176+
) &&
177+
(
178+
cd "$cli" &&
179+
# must use its encoded name
180+
p4 delete wild%40delete &&
181+
p4 submit -d "delete wild@delete"
182+
) &&
183+
(
184+
cd "$git" &&
185+
git p4 sync &&
186+
git merge --ff-only p4/master &&
187+
test_path_is_missing wild@delete
188+
)
189+
'
190+
191+
test_expect_success 'wildcard files requiring keyword scrub' '
192+
(
193+
cd "$cli" &&
194+
cat <<-\EOF >scrub@wild &&
195+
$Id$
196+
line2
197+
EOF
198+
p4 add -t text+k -f scrub@wild &&
199+
p4 submit -d "scrub at wild"
200+
) &&
201+
test_when_finished cleanup_git &&
202+
git p4 clone --dest="$git" //depot &&
203+
(
204+
cd "$git" &&
205+
git config git-p4.skipSubmitEdit true &&
206+
git config git-p4.attemptRCSCleanup true &&
207+
sed "s/^line2/line2 edit/" <scrub@wild >[email protected] &&
208+
mv -f [email protected] scrub@wild &&
209+
git commit -m "scrub at wild line2 edit" scrub@wild &&
210+
git p4 submit
211+
)
212+
'
213+
164214
test_expect_success 'kill p4d' '
165215
kill_p4d
166216
'

0 commit comments

Comments
 (0)