summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
f9a2b5d)
"stg assimilate" was already making sure that automatically generated
patch names were non-empty and unique, by suffixing them with a dash
and a number if necessary. This patch moves that functionality into
the autogeneration function itself, so that all its callers can
benefit from it (and the user can benefit from uniform behavior from
all stgit commands).
As an added bonus, this permits the removal of a number of checks that
would abort with an error if the automatically generated name was
empty.
Signed-off-by: Karl Hasselström <kha@treskal.com>
return name in name2patch or crt_series.patch_exists(name)
for victim in victims:
return name in name2patch or crt_series.patch_exists(name)
for victim in victims:
- patchname = make_patch_name(victim.get_log())
- if not patchname:
- patchname = 'patch'
- if name_taken(patchname):
- suffix = 0
- while name_taken('%s-%d' % (patchname, suffix)):
- suffix += 1
- patchname = '%s-%d' % (patchname, suffix)
+ patchname = make_patch_name(victim.get_log(), name_taken)
patch2name[victim] = patchname
name2patch[patchname] = victim
patch2name[victim] = patchname
name2patch[patchname] = victim
-def make_patch_name(msg):
+def patch_name_from_msg(msg):
"""Return a string to be used as a patch name. This is generated
from the first 30 characters of the top line of the string passed
as argument."""
"""Return a string to be used as a patch name. This is generated
from the first 30 characters of the top line of the string passed
as argument."""
subject_line = msg[:30].lstrip().split('\n', 1)[0].lower()
return re.sub('[\W]+', '-', subject_line).strip('-')
subject_line = msg[:30].lstrip().split('\n', 1)[0].lower()
return re.sub('[\W]+', '-', subject_line).strip('-')
+
+def make_patch_name(msg, unacceptable, default_name = 'patch'):
+ """Return a patch name generated from the given commit message,
+ guaranteed to make unacceptable(name) be false. If the commit
+ message is empty, base the name on default_name instead."""
+ patchname = patch_name_from_msg(msg)
+ if not patchname:
+ patchname = 'patch'
+ if unacceptable(patchname):
+ suffix = 0
+ while unacceptable('%s-%d' % (patchname, suffix)):
+ suffix += 1
+ patchname = '%s-%d' % (patchname, suffix)
+ return patchname
__parse_patch(filename)
if not patch:
__parse_patch(filename)
if not patch:
- patch = make_patch_name(message)
- if not patch:
- raise CmdException, 'Unknown patch name'
+ patch = make_patch_name(message, crt_series.patch_exists)
# refresh_patch() will invoke the editor in this case, with correct
# patch content
# refresh_patch() will invoke the editor in this case, with correct
# patch content
elif len(patch_branch) == 2:
patch = patch_branch[0]
else:
elif len(patch_branch) == 2:
patch = patch_branch[0]
else:
- patch = make_patch_name(commit.get_log())
- if not patch:
- raise CmdException, 'Unknown patch name'
+ patch = make_patch_name(commit.get_log(), crt_series.patch_exists)
if options.parent:
parent = git_id(options.parent)
if options.parent:
parent = git_id(options.parent)
if patchnames:
patchname = patchnames[n]
else:
if patchnames:
patchname = patchnames[n]
else:
- patchname = make_patch_name(commit.get_log())
- if not patchname:
- raise CmdException, 'Unknown patch name for commit %s' % commit_id
+ patchname = make_patch_name(commit.get_log(),
+ crt_series.patch_exists)
crt_series.new_patch(patchname,
can_edit = False, before_existing = True,
crt_series.new_patch(patchname,
can_edit = False, before_existing = True,