Skip to content

Commit 5e1288a

Browse files
committed
Merge branch 'ld/p4-import-labels'
Correct "git p4 --detect-labels" so that it does not fail to create a tag that points at a commit that is also being imported. * ld/p4-import-labels: git-p4: fix P4 label import for unprocessed commits git-p4: do not terminate creating tag for unknown commit git-p4: failing test for ignoring invalid p4 labels
2 parents 22dd6eb + b43702a commit 5e1288a

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

git-p4.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,8 +2329,11 @@ def make_email(self, userid):
23292329
else:
23302330
return "%s <a@b>" % userid
23312331

2332-
# Stream a p4 tag
23332332
def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
2333+
""" Stream a p4 tag.
2334+
commit is either a git commit, or a fast-import mark, ":<p4commit>"
2335+
"""
2336+
23342337
if verbose:
23352338
print "writing tag %s for commit %s" % (labelName, commit)
23362339
gitStream.write("tag %s\n" % labelName)
@@ -2381,7 +2384,7 @@ def commit(self, details, files, branch, parent = ""):
23812384
self.clientSpecDirs.update_client_spec_path_cache(files)
23822385

23832386
self.gitStream.write("commit %s\n" % branch)
2384-
# gitStream.write("mark :%s\n" % details["change"])
2387+
self.gitStream.write("mark :%s\n" % details["change"])
23852388
self.committedChanges.add(int(details["change"]))
23862389
committer = ""
23872390
if author not in self.users:
@@ -2500,13 +2503,19 @@ def importP4Labels(self, stream, p4Labels):
25002503
if change.has_key('change'):
25012504
# find the corresponding git commit; take the oldest commit
25022505
changelist = int(change['change'])
2503-
gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
2504-
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist])
2505-
if len(gitCommit) == 0:
2506-
print "could not find git commit for changelist %d" % changelist
2507-
else:
2508-
gitCommit = gitCommit.strip()
2506+
if changelist in self.committedChanges:
2507+
gitCommit = ":%d" % changelist # use a fast-import mark
25092508
commitFound = True
2509+
else:
2510+
gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
2511+
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist], ignore_error=True)
2512+
if len(gitCommit) == 0:
2513+
print "importing label %s: could not find git commit for changelist %d" % (name, changelist)
2514+
else:
2515+
commitFound = True
2516+
gitCommit = gitCommit.strip()
2517+
2518+
if commitFound:
25102519
# Convert from p4 time format
25112520
try:
25122521
tmwhen = time.strptime(labelDetails['Update'], "%Y/%m/%d %H:%M:%S")

t/t9811-git-p4-label-import.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,51 @@ test_expect_success 'use git config to enable import/export of tags' '
214214
)
215215
'
216216

217+
p4_head_revision() {
218+
p4 changes -m 1 "$@" | awk '{print $2}'
219+
}
220+
221+
# Importing a label that references a P4 commit that
222+
# has not been seen. The presence of a label on a commit
223+
# we haven't seen should not cause git-p4 to fail. It should
224+
# merely skip that label, and still import other labels.
225+
test_expect_success 'importing labels with missing revisions' '
226+
test_when_finished cleanup_git &&
227+
(
228+
rm -fr "$cli" "$git" &&
229+
mkdir "$cli" &&
230+
P4CLIENT=missing-revision &&
231+
client_view "//depot/missing-revision/... //missing-revision/..." &&
232+
cd "$cli" &&
233+
>f1 && p4 add f1 && p4 submit -d "start" &&
234+
235+
p4 tag -l TAG_S0 ... &&
236+
237+
>f2 && p4 add f2 && p4 submit -d "second" &&
238+
239+
startrev=$(p4_head_revision //depot/missing-revision/...) &&
240+
241+
>f3 && p4 add f3 && p4 submit -d "third" &&
242+
243+
p4 edit f2 && date >f2 && p4 submit -d "change" f2 &&
244+
245+
endrev=$(p4_head_revision //depot/missing-revision/...) &&
246+
247+
p4 tag -l TAG_S1 ... &&
248+
249+
# we should skip TAG_S0 since it is before our startpoint,
250+
# but pick up TAG_S1.
251+
252+
git p4 clone --dest="$git" --import-labels -v \
253+
//depot/missing-revision/...@$startrev,$endrev &&
254+
(
255+
cd "$git" &&
256+
git rev-parse TAG_S1 &&
257+
! git rev-parse TAG_S0
258+
)
259+
)
260+
'
261+
217262

218263
test_expect_success 'kill p4d' '
219264
kill_p4d

0 commit comments

Comments
 (0)