Skip to contentSkip to conversation

stg refresh -e/--edit

PATCH In review Karl Hasselström 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover stg refresh -e/--edit

Jakub, this one's for you. ;-)

These live in my experimental branch for a little while yet, but the plan is to include them in v0.15 -- and release that reasonably soon.

---

Karl Hasselström (2):

      Implement "stg refresh --edit" again
      Refactor stgit.commands.edit
 stgit/commands/coalesce.py |    2 -
 stgit/commands/common.py   |    9 +++-
 stgit/commands/edit.py     |   82 ++++++------------------------------
 stgit/commands/imprt.py    |    2 -
 stgit/commands/new.py      |    3 +
 stgit/commands/refresh.py  |   44 +++++++++++++++-----
 stgit/lib/edit.py          |   99 ++++++++++++++++++++++++++++++++++++++++++++
 stgit/utils.py             |   18 +++++---
 8 files changed, 167 insertions(+), 92 deletions(-)
 create mode 100644 stgit/lib/edit.py
Signature · 2 lines
Karl Hasselström, [email protected]
      www.treskal.com/kalle
#1 lore raw

PATCH 1/2 Refactor stgit.commands.edit

Reorganize a few existing functions, and break out stuff from the main function into subroutines.

While we're at it, move one of the old and all of the new functions to stgit.lib.edit, so that we can use them in a later patch to implement "stg refresh --edit".

---

 stgit/commands/common.py |    9 +++-
 stgit/commands/edit.py   |   79 +++++--------------------------------
 stgit/commands/imprt.py  |    2 -
 stgit/lib/edit.py        |   99 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 117 insertions(+), 72 deletions(-)
 create mode 100644 stgit/lib/edit.py
stgit/commands/common.py +6 -3
index 2689a42..c92554d 100644
@@ -453,12 +453,15 @@ def parse_mail(msg):
 
     return (descr, authname, authemail, authdate, diff)
 
-def parse_patch(text):
+def parse_patch(text, contains_diff):
     """Parse the input text and return (description, authname,
     authemail, authdate, diff)
     """
-    descr, diff = __split_descr_diff(text)
-    descr, authname, authemail, authdate = __parse_description(descr)
+    if contains_diff:
+        (text, diff) = __split_descr_diff(text)
+    else:
+        diff = None
+    (descr, authname, authemail, authdate) = __parse_description(text)
 
     # we don't yet have an agreed place for the creation date.
     # Just return None
stgit/commands/edit.py +11 -68

107 lines not on this page · raw message

stgit/commands/imprt.py +1 -1
index 5fb4da3..b958412 100644
@@ -220,7 +220,7 @@ def __import_file(filename, options, patch = None):
                  parse_mail(msg)
     else:
         message, author_name, author_email, author_date, diff = \
-                 parse_patch(f.read())
+                 parse_patch(f.read(), contains_diff = True)
 
     if filename:
         f.close()
stgit/lib/edit.py new file +99 -0

99 lines not on this page · raw message

#2 lore raw

PATCH 2/2 Implement "stg refresh --edit" again

In reply to Karl Hasselström

The -e/--edit flag to "stg refresh" was dropped between v0.13 and v0.14, causing severe user dissatisfaction. This patch restores it, along with -m/--message, -f/--file, --sign, --ack, --author, --authname, --authemail, and --authdate.

I omitted the --committer options on purpose; I think they are a mistake. Falsifying the committer info is not a common operation, and if one wishes to do it for some reason, one can always set the GIT_COMMITTER_* environment variables.

---

 stgit/commands/coalesce.py |    2 +-
 stgit/commands/edit.py     |    3 ++-
 stgit/commands/new.py      |    3 ++-
 stgit/commands/refresh.py  |   44 +++++++++++++++++++++++++++++++++-----------
 stgit/utils.py             |   18 ++++++++++++------
 5 files changed, 50 insertions(+), 20 deletions(-)
stgit/commands/coalesce.py +1 -1
index 1a34934..f3954ce 100644
@@ -35,7 +35,7 @@ done a sequence of pushes and pops yourself."""
 
 directory = common.DirectoryHasRepositoryLib()
 options = [make_option('-n', '--name', help = 'name of coalesced patch')
-           ] + utils.make_message_options()
+           ] + utils.make_message_options(save_template = True)
 
 class SaveTemplateDone(Exception):
     pass
stgit/commands/edit.py +2 -1
index a9e8991..a83ec9c 100644
@@ -60,7 +60,8 @@ options = [make_option('-d', '--diff',
                        action = 'store_true'),
            make_option('-e', '--edit', action = 'store_true',
                        help = 'invoke interactive editor'),
-           ] + (utils.make_sign_options() + utils.make_message_options()
+           ] + (utils.make_sign_options()
+                + utils.make_message_options(save_template = True)
                 + utils.make_author_committer_options()
                 + utils.make_diff_opts_option())
 
stgit/commands/new.py +2 -1
index c4ee4e1..f468ab0 100644
@@ -38,7 +38,8 @@ line of the commit message."""
 
 directory = common.DirectoryHasRepositoryLib()
 options = (utils.make_author_committer_options()
-           + utils.make_message_options() + utils.make_sign_options())
+           + utils.make_message_options(save_template = True)
+           + utils.make_sign_options())
 
 def func(parser, options, args):
     """Create a new patch."""
stgit/commands/refresh.py +33 -11

96 lines not on this page · raw message

stgit/utils.py +12 -6
index 2983ea8..c40e666 100644
@@ -264,13 +264,13 @@ def add_sign_line(desc, sign_str, name, email):
         desc = desc + '\n'
     return '%s\n%s\n' % (desc, sign_str)
 
-def make_message_options():
+def make_message_options(save_template):
     def no_dup(parser):
         if parser.values.message != None:
             raise optparse.OptionValueError(
                 'Cannot give more than one --message or --file')
     def no_combine(parser):
-        if (parser.values.message != None
+        if (save_template and parser.values.message != None
             and parser.values.save_template != None):
             raise optparse.OptionValueError(
                 'Cannot give both --message/--file and --save-template')
@@ -299,15 +299,18 @@ def make_message_options():
         parser.values.save_template = w
         no_combine(parser)
     m = optparse.make_option
-    return [m('-m', '--message', action = 'callback', callback = msg_callback,
+    opts = [m('-m', '--message', action = 'callback', callback = msg_callback,
               dest = 'message', type = 'string',
               help = 'use MESSAGE instead of invoking the editor'),
             m('-f', '--file', action = 'callback', callback = file_callback,
               dest = 'message', type = 'string', metavar = 'FILE',
-              help = 'use FILE instead of invoking the editor'),
+              help = 'use FILE instead of invoking the editor')]
+    if save_template:
+        opts.append(
             m('--save-template', action = 'callback', callback = templ_callback,
               metavar = 'FILE', dest = 'save_template', type = 'string',
-              help = 'save the message template to FILE and exit')]
+              help = 'save the message template to FILE and exit'))
+    return opts
 
 def make_diff_opts_option():
     def diff_opts_callback(option, opt_str, value, parser):
@@ -368,8 +371,11 @@ def make_person_options(person, short):
                 callback_args = (f,), help = 'set the %s %s' % (person, f))
                for f in ['name', 'email', 'date']])
 
+def make_author_options():
+    return make_person_options('author', 'auth')
+
 def make_author_committer_options():
-    return (make_person_options('author', 'auth')
+    return (make_author_options()
             + make_person_options('committer', 'comm'))
 
 # Exit codes.
#3 lore raw

Re: [StGit PATCH 2/2] Implement "stg refresh --edit" again

Quoted 2 lines · Karl Hasselström

The -e/--edit flag to "stg refresh" was dropped between v0.13 and v0.14, causing severe user dissatisfaction. This patch restores it

Thanks a lot!

Signature · 2 lines
Jakub Narebski
Poland
#4 lore raw

Re: [StGit PATCH 2/2] Implement "stg refresh --edit" again

In reply to Karl Hasselström

2008/7/4 Karl Hasselström <[email protected]>:

Quoted 4 lines

The -e/--edit flag to "stg refresh" was dropped between v0.13 and v0.14, causing severe user dissatisfaction. This patch restores it, along with -m/--message, -f/--file, --sign, --ack, --author, --authname, --authemail, and --authdate.

Thanks.

Quoted 4 lines

I omitted the --committer options on purpose; I think they are a mistake. Falsifying the committer info is not a common operation, and if one wishes to do it for some reason, one can always set the GIT_COMMITTER_* environment variables.

I agree.

Signature · 1 line
Catalin