1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-07 23:36:32 +02:00

Merge branch 'ld/p4-import-labels' into maint

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
This commit is contained in:
Junio C Hamano 2015-11-03 15:32:27 -08:00
commit 04bba3a12b
2 changed files with 62 additions and 8 deletions

View File

@ -2329,8 +2329,11 @@ def make_email(self, userid):
else:
return "%s <a@b>" % userid
# Stream a p4 tag
def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
""" Stream a p4 tag.
commit is either a git commit, or a fast-import mark, ":<p4commit>"
"""
if verbose:
print "writing tag %s for commit %s" % (labelName, commit)
gitStream.write("tag %s\n" % labelName)
@ -2381,7 +2384,7 @@ def commit(self, details, files, branch, parent = ""):
self.clientSpecDirs.update_client_spec_path_cache(files)
self.gitStream.write("commit %s\n" % branch)
# gitStream.write("mark :%s\n" % details["change"])
self.gitStream.write("mark :%s\n" % details["change"])
self.committedChanges.add(int(details["change"]))
committer = ""
if author not in self.users:
@ -2500,13 +2503,19 @@ def importP4Labels(self, stream, p4Labels):
if change.has_key('change'):
# find the corresponding git commit; take the oldest commit
changelist = int(change['change'])
gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist])
if len(gitCommit) == 0:
print "could not find git commit for changelist %d" % changelist
else:
gitCommit = gitCommit.strip()
if changelist in self.committedChanges:
gitCommit = ":%d" % changelist # use a fast-import mark
commitFound = True
else:
gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist], ignore_error=True)
if len(gitCommit) == 0:
print "importing label %s: could not find git commit for changelist %d" % (name, changelist)
else:
commitFound = True
gitCommit = gitCommit.strip()
if commitFound:
# Convert from p4 time format
try:
tmwhen = time.strptime(labelDetails['Update'], "%Y/%m/%d %H:%M:%S")

View File

@ -214,6 +214,51 @@ test_expect_success 'use git config to enable import/export of tags' '
)
'
p4_head_revision() {
p4 changes -m 1 "$@" | awk '{print $2}'
}
# Importing a label that references a P4 commit that
# has not been seen. The presence of a label on a commit
# we haven't seen should not cause git-p4 to fail. It should
# merely skip that label, and still import other labels.
test_expect_success 'importing labels with missing revisions' '
test_when_finished cleanup_git &&
(
rm -fr "$cli" "$git" &&
mkdir "$cli" &&
P4CLIENT=missing-revision &&
client_view "//depot/missing-revision/... //missing-revision/..." &&
cd "$cli" &&
>f1 && p4 add f1 && p4 submit -d "start" &&
p4 tag -l TAG_S0 ... &&
>f2 && p4 add f2 && p4 submit -d "second" &&
startrev=$(p4_head_revision //depot/missing-revision/...) &&
>f3 && p4 add f3 && p4 submit -d "third" &&
p4 edit f2 && date >f2 && p4 submit -d "change" f2 &&
endrev=$(p4_head_revision //depot/missing-revision/...) &&
p4 tag -l TAG_S1 ... &&
# we should skip TAG_S0 since it is before our startpoint,
# but pick up TAG_S1.
git p4 clone --dest="$git" --import-labels -v \
//depot/missing-revision/...@$startrev,$endrev &&
(
cd "$git" &&
git rev-parse TAG_S1 &&
! git rev-parse TAG_S0
)
)
'
test_expect_success 'kill p4d' '
kill_p4d