Skip to content

Commit c8942a2

Browse files
luked99gitster
authored andcommitted
git p4: fix-up "import/export of labels to/from p4"
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 06804c7 commit c8942a2

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

Documentation/git-p4.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ These options can be used to modify 'git p4 submit' behavior.
267267
Re-author p4 changes before submitting to p4. This option
268268
requires p4 admin privileges.
269269

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

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

445+
-------------
446+
git config git-p4.branchList main:branchA
447+
git config --add git-p4.branchList main:branchB
448+
-------------
449+
445450
git-p4.ignoredP4Labels::
446451
List of p4 labels to ignore. This is built automatically as
447452
unimportable labels are discovered.
448453

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

452-
git-p4.validLabelRegexp::
457+
git-p4.labelImportRegexp::
453458
Only p4 labels matching this regular expression will be imported. The
454-
default value is '[A-Z0-9_\-.]+$'.
455-
456-
-------------
457-
git config git-p4.branchList main:branchA
458-
git config --add git-p4.branchList main:branchB
459-
-------------
459+
default value is '[a-zA-Z0-9_\-.]+$'.
460460

461461
git-p4.useClientSpec::
462462
Specify that the p4 client spec should be used to identify p4
@@ -515,9 +515,9 @@ git-p4.attemptRCSCleanup:
515515
git-p4.exportLabels::
516516
Export git tags to p4 labels, as per --export-labels.
517517

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

522522
IMPLEMENTATION DETAILS
523523
----------------------

git-p4.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
verbose = False
1616

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

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

12641263
for name in gitTags:
12651264

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

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

1278-
if not changelist:
1274+
if not values.has_key('change'):
12791275
# a tag pointing to something not sent to p4; ignore
12801276
if verbose:
12811277
print "git tag %s does not give a p4 commit" % name
12821278
continue
1279+
else:
1280+
changelist = values['change']
12831281

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

20782076
ignoredP4Labels = gitConfigList("git-p4.ignoredP4Labels")
2079-
validLabelRegexp = gitConfig("git-p4.validLabelRegexp")
2077+
validLabelRegexp = gitConfig("git-p4.labelImportRegexp")
20802078
if len(validLabelRegexp) == 0:
20812079
validLabelRegexp = defaultLabelRegexp
20822080
m = re.compile(validLabelRegexp)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test_expect_success 'basic p4 labels' '
3030
3131
p4 tag -l TAG_F1_ONLY main/f1 &&
3232
p4 tag -l TAG_WITH\$_SHELL_CHAR main/... &&
33-
p4 tag -l this_tag_will_be_skipped main/... &&
33+
p4 tag -l this_tag_will_be\ skipped main/... &&
3434
3535
echo f4 >main/f4 &&
3636
p4 add main/f4 &&
@@ -50,7 +50,7 @@ test_expect_success 'basic p4 labels' '
5050
5151
git p4 clone --dest="$git" //depot@all &&
5252
cd "$git" &&
53-
git config git-p4.validLabelRegexp ".*TAG.*" &&
53+
git config git-p4.labelImportRegexp ".*TAG.*" &&
5454
git p4 sync --import-labels --verbose &&
5555
5656
git tag &&

0 commit comments

Comments
 (0)