MCPcopy Index your code
hub / github.com/git/git / importP4Labels

Method importP4Labels

git-p4.py:3568–3636  ·  view source on GitHub ↗

Import p4 labels as git tags. A direct mapping does not exist, so assume that if all the files are at the same revision then we can use that, or it's something more complicated we should just ignore.

(self, stream, p4Labels)

Source from the content-addressed store, hash-verified

3566 print("Label changes: %s" % self.labels.keys())
3567
3568 def importP4Labels(self, stream, p4Labels):
3569 """Import p4 labels as git tags. A direct mapping does not exist, so
3570 assume that if all the files are at the same revision then we can
3571 use that, or it's something more complicated we should just ignore.
3572 """
3573
3574 if verbose:
3575 print("import p4 labels: " + ' '.join(p4Labels))
3576
3577 ignoredP4Labels = gitConfigList("git-p4.ignoredP4Labels")
3578 validLabelRegexp = gitConfig("git-p4.labelImportRegexp")
3579 if len(validLabelRegexp) == 0:
3580 validLabelRegexp = defaultLabelRegexp
3581 m = re.compile(validLabelRegexp)
3582
3583 for name in p4Labels:
3584 commitFound = False
3585
3586 if not m.match(name):
3587 if verbose:
3588 print("label %s does not match regexp %s" % (name, validLabelRegexp))
3589 continue
3590
3591 if name in ignoredP4Labels:
3592 continue
3593
3594 labelDetails = p4CmdList(['label', "-o", name])[0]
3595
3596 # get the most recent changelist for each file in this label
3597 change = p4Cmd(["changes", "-m", "1"] + ["%s...@%s" % (p, name)
3598 for p in self.depotPaths])
3599
3600 if 'change' in change:
3601 # find the corresponding git commit; take the oldest commit
3602 changelist = int(change['change'])
3603 if changelist in self.committedChanges:
3604 gitCommit = ":%d" % changelist # use a fast-import mark
3605 commitFound = True
3606 else:
3607 gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
3608 "--reverse", r":/\[git-p4:.*change = %d\]" % changelist], ignore_error=True)
3609 if len(gitCommit) == 0:
3610 print("importing label %s: could not find git commit for changelist %d" % (name, changelist))
3611 else:
3612 commitFound = True
3613 gitCommit = gitCommit.strip()
3614
3615 if commitFound:
3616 # Convert from p4 time format
3617 try:
3618 tmwhen = time.strptime(labelDetails['Update'], "%Y/%m/%d %H:%M:%S")
3619 except ValueError:
3620 print("Could not convert label time %s" % labelDetails['Update'])
3621 tmwhen = 1
3622
3623 when = int(time.mktime(tmwhen))
3624 self.streamTag(stream, name, labelDetails, gitCommit, when)
3625 if verbose:

Callers 1

runMethod · 0.95

Calls 7

streamTagMethod · 0.95
gitConfigListFunction · 0.85
gitConfigFunction · 0.85
p4CmdListFunction · 0.85
p4CmdFunction · 0.85
read_pipeFunction · 0.85
systemFunction · 0.85

Tested by

no test coverage detected