Skip to content

Commit

Permalink
git p4: fix-up "import/export of labels to/from p4"
Browse files Browse the repository at this point in the history
The previous one is already in 'next' but was somewhat lacking.

The configuration "git-p4.validLabelRegexp" is now called
"labelExportRegexp", and its default covers lowercase alphabets as
well.

Signed-off-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Luke Diamand authored and Junio C Hamano committed Apr 24, 2012
1 parent 06804c7 commit c8942a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
20 changes: 10 additions & 10 deletions Documentation/git-p4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ These options can be used to modify 'git p4 submit' behavior.
Re-author p4 changes before submitting to p4. This option
requires p4 admin privileges.

--export-labels:
--export-labels::
Export tags from git as p4 labels. Tags found in git are applied
to the perforce working directory.

Expand Down Expand Up @@ -442,21 +442,21 @@ git-p4.branchList::
by a colon (:). This example declares that both branchA and
branchB were created from main:

-------------
git config git-p4.branchList main:branchA
git config --add git-p4.branchList main:branchB
-------------

git-p4.ignoredP4Labels::
List of p4 labels to ignore. This is built automatically as
unimportable labels are discovered.

git-p4.importLabels::
Import p4 labels into git, as per --import-labels.

git-p4.validLabelRegexp::
git-p4.labelImportRegexp::
Only p4 labels matching this regular expression will be imported. The
default value is '[A-Z0-9_\-.]+$'.

-------------
git config git-p4.branchList main:branchA
git config --add git-p4.branchList main:branchB
-------------
default value is '[a-zA-Z0-9_\-.]+$'.

git-p4.useClientSpec::
Specify that the p4 client spec should be used to identify p4
Expand Down Expand Up @@ -515,9 +515,9 @@ git-p4.attemptRCSCleanup:
git-p4.exportLabels::
Export git tags to p4 labels, as per --export-labels.

git-p4.validLabelRegexp::
git-p4.labelExportRegexp::
Only p4 labels matching this regular expression will be exported. The
default value is '[A-Z0-9_\-.]+$'.
default value is '[a-zA-Z0-9_\-.]+$'.

IMPLEMENTATION DETAILS
----------------------
Expand Down
24 changes: 11 additions & 13 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
verbose = False

# Only labels/tags matching this will be imported/exported
defaultLabelRegexp = r'[A-Z0-9_\-.]+$'
defaultLabelRegexp = r'[a-zA-Z0-9_\-.]+$'

def p4_build_cmd(cmd):
"""Build a suitable p4 command line.
Expand Down Expand Up @@ -1255,11 +1255,10 @@ def applyCommit(self, id):
# Export git tags as p4 labels. Create a p4 label and then tag
# with that.
def exportGitTags(self, gitTags):
validTagRegexp = gitConfig("git-p4.validTagRegexp")
if len(validTagRegexp) == 0:
validTagRegexp = defaultLabelRegexp
m = re.compile(validTagRegexp)
commit_re = re.compile(r'\s*\[git-p4:.*change = (\d+)\s*\]')
validLabelRegexp = gitConfig("git-p4.labelExportRegexp")
if len(validLabelRegexp) == 0:
validLabelRegexp = defaultLabelRegexp
m = re.compile(validLabelRegexp)

for name in gitTags:

Expand All @@ -1269,17 +1268,16 @@ def exportGitTags(self, gitTags):
continue

# Get the p4 commit this corresponds to
changelist = None
for l in read_pipe_lines(["git", "log", "--max-count=1", name]):
match = commit_re.match(l)
if match:
changelist = match.group(1)
logMessage = extractLogMessageFromGitCommit(name)
values = extractSettingsGitLog(logMessage)

if not changelist:
if not values.has_key('change'):
# a tag pointing to something not sent to p4; ignore
if verbose:
print "git tag %s does not give a p4 commit" % name
continue
else:
changelist = values['change']

# Get the tag details.
inHeader = True
Expand Down Expand Up @@ -2076,7 +2074,7 @@ def importP4Labels(self, stream, p4Labels):
print "import p4 labels: " + ' '.join(p4Labels)

ignoredP4Labels = gitConfigList("git-p4.ignoredP4Labels")
validLabelRegexp = gitConfig("git-p4.validLabelRegexp")
validLabelRegexp = gitConfig("git-p4.labelImportRegexp")
if len(validLabelRegexp) == 0:
validLabelRegexp = defaultLabelRegexp
m = re.compile(validLabelRegexp)
Expand Down
4 changes: 2 additions & 2 deletions t/t9811-git-p4-label-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_expect_success 'basic p4 labels' '
p4 tag -l TAG_F1_ONLY main/f1 &&
p4 tag -l TAG_WITH\$_SHELL_CHAR main/... &&
p4 tag -l this_tag_will_be_skipped main/... &&
p4 tag -l this_tag_will_be\ skipped main/... &&
echo f4 >main/f4 &&
p4 add main/f4 &&
Expand All @@ -50,7 +50,7 @@ test_expect_success 'basic p4 labels' '
git p4 clone --dest="$git" //depot@all &&
cd "$git" &&
git config git-p4.validLabelRegexp ".*TAG.*" &&
git config git-p4.labelImportRegexp ".*TAG.*" &&
git p4 sync --import-labels --verbose &&
git tag &&
Expand Down

0 comments on commit c8942a2

Please sign in to comment.