Browse Source

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 <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Luke Diamand 13 years ago committed by Junio C Hamano
parent
commit
c8942a223d
  1. 20
      Documentation/git-p4.txt
  2. 24
      git-p4.py
  3. 4
      t/t9811-git-p4-label-import.sh

20
Documentation/git-p4.txt

@ -267,7 +267,7 @@ These options can be used to modify 'git p4 submit' behavior. @@ -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.

@ -442,6 +442,11 @@ git-p4.branchList:: @@ -442,6 +442,11 @@ 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.
@ -449,14 +454,9 @@ git-p4.ignoredP4Labels:: @@ -449,14 +454,9 @@ git-p4.ignoredP4Labels::
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
@ -515,9 +515,9 @@ git-p4.attemptRCSCleanup: @@ -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
----------------------

24
git-p4.py

@ -15,7 +15,7 @@ import re, shutil @@ -15,7 +15,7 @@ import re, shutil
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.
@ -1255,11 +1255,10 @@ class P4Submit(Command, P4UserMap): @@ -1255,11 +1255,10 @@ class P4Submit(Command, P4UserMap):
# 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:

@ -1269,17 +1268,16 @@ class P4Submit(Command, P4UserMap): @@ -1269,17 +1268,16 @@ class P4Submit(Command, P4UserMap):
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
@ -2076,7 +2074,7 @@ class P4Sync(Command, P4UserMap): @@ -2076,7 +2074,7 @@ class P4Sync(Command, P4UserMap):
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)

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

@ -30,7 +30,7 @@ test_expect_success 'basic p4 labels' ' @@ -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 &&
@ -50,7 +50,7 @@ test_expect_success 'basic p4 labels' ' @@ -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 &&

Loading…
Cancel
Save