From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH 2/2] Generate unique patch names
Date: Tue, 07 Nov 2006 07:59:31 +0100 [thread overview]
Message-ID: <20061107065931.10728.66377.stgit@localhost> (raw)
In-Reply-To: <20061107065710.10728.85618.stgit@localhost>
From: Karl Hasselström <kha@treskal.com>
"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>
---
stgit/commands/assimilate.py | 9 +--------
stgit/commands/common.py | 16 +++++++++++++++-
stgit/commands/imprt.py | 4 +---
stgit/commands/pick.py | 4 +---
stgit/commands/uncommit.py | 5 ++---
5 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/stgit/commands/assimilate.py b/stgit/commands/assimilate.py
index 0821024..a8b3bfe 100644
--- a/stgit/commands/assimilate.py
+++ b/stgit/commands/assimilate.py
@@ -73,14 +73,7 @@ def func(parser, options, args):
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
diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index 0e1bb44..d986711 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -284,7 +284,7 @@ def name_email_date(address):
return str_list[0]
-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."""
@@ -293,3 +293,17 @@ def make_patch_name(msg):
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
diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index c8cf42b..34cbf38 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -240,9 +240,7 @@ def __import_patch(patch, filename, opti
__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
diff --git a/stgit/commands/pick.py b/stgit/commands/pick.py
index f8f3577..996e789 100644
--- a/stgit/commands/pick.py
+++ b/stgit/commands/pick.py
@@ -71,9 +71,7 @@ def func(parser, options, args):
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)
diff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py
index 45a2087..9798f19 100644
--- a/stgit/commands/uncommit.py
+++ b/stgit/commands/uncommit.py
@@ -97,9 +97,8 @@ def func(parser, options, args):
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 = T
prev parent reply other threads:[~2006-11-07 6:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-07 6:57 [PATCH 0/2] Generate saner automatic patch names Karl Hasselström
2006-11-07 6:59 ` [PATCH 1/2] Generate shorter " Karl Hasselström
2006-11-07 6:59 ` Karl Hasselström [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061107065931.10728.66377.stgit@localhost \
--to=kha@treskal.com \
--cc=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).