Miscellaneous fixes and improvements
cover Miscellaneous fixes and improvements
Also available from
git://repo.or.cz/stgit/kha.git safe
---
Karl Hasselström (8):
Remove the --force flag to "stg rebase" and "stg pull" Discard stderr output from git-rev-parse Simplify debug level error checking
Make a common superclass for all StGit exceptions Don't split long and short description in "stg edit" Fix up the help text for "stg edit"
New test: "stg pop --keep"
Add --ack/--sign options to "stg new"
stgit/commands/common.py | 14 ++++---------- stgit/commands/edit.py | 33 +++++++++++++++----------------- stgit/commands/new.py | 6 ++++-- stgit/commands/pull.py | 5 +---- stgit/commands/rebase.py | 5 +---- stgit/config.py | 3 ++- stgit/exception.py | 3 +++ stgit/git.py | 6 ++++-- stgit/gitmergeonefile.py | 3 ++- stgit/main.py | 15 ++++----------- stgit/run.py | 5 +++-- stgit/stack.py | 14 +++++++++----- stgit/utils.py | 3 ++- t/t1204-pop-keep.sh | 42 +++++++++++++++++++++++++++++++++++++++++ t/t2100-pull-policy-fetch.sh | 14 -------------- t/t2102-pull-policy-rebase.sh | 24 ----------------------- 16 files changed, 96 insertions(+), 99 deletions(-) create mode 100644 stgit/exception.py create mode 100755 t/t1204-pop-keep.sh
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/8 Add --ack/--sign options to "stg new"
---
stgit/commands/new.py | 6 ++++-- stgit/stack.py | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-)
stgit/commands/new.py +4 -2
@@ -54,7 +54,8 @@ options = [make_option('-m', '--message', make_option('--commname', help = 'use COMMNAME as the committer name'), make_option('--commemail', - help = 'use COMMEMAIL as the committer e-mail')] + help = 'use COMMEMAIL as the committer e-mail') + ] + make_sign_options() def func(parser, options, args):
@@ -79,4 +80,5 @@ def func(parser, options, args): author_email = options.authemail, author_date = options.authdate, committer_name = options.commname, - committer_email = options.commemail) + committer_email = options.commemail, + sign_str = options.sign_str)
stgit/stack.py +7 -3
@@ -847,7 +847,7 @@ class Series(PatchSet): top = None, bottom = None, commit = True, author_name = None, author_email = None, author_date = None, committer_name = None, committer_email = None, - before_existing = False): + before_existing = False, sign_str = None): """Creates a new patch, either pointing to an existing commit object, or by creating a new commit object. """
@@ -865,13 +865,17 @@ class Series(PatchSet): # TODO: move this out of the stgit.stack module, it is really # for higher level commands to handle the user interaction + def sign(msg): + return add_sign_line(msg, sign_str, + committer_name or git.committer().name, + committer_email or git.committer().email) if not message and can_edit: descr = edit_file( - self, None, + self, sign(''), 'Please enter the description for the patch above.', show_patch) else: - descr = message + descr = sign(message) head = git.get_head()
PATCH 2/8 New test: "stg pop --keep"
In reply to Karl Hasselström---
t/t1204-pop-keep.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) create mode 100755 t/t1204-pop-keep.sh
t/t1204-pop-keep.sh new file +42 -0
@@ -0,0 +1,42 @@ +#!/bin/sh + +test_description='Test "stg pop -keep"' +. ./test-lib.sh +stg init + +test_expect_success 'Create a few patches' ' + for i in 0 1 2; do + stg new p$i -m p$i && + echo "patch$i" >> patch$i.txt && + stg add patch$i.txt && + stg refresh + done && + [ "$(echo $(stg applied))" = "p0 p1 p2" ] && + [ "$(echo $(stg unapplied))" = "" ] +' + +test_expect_success 'Make some non-conflicting local changes' ' + echo "local" >> patch0.txt +' + +test_expect_success 'Pop two patches, keeping local changes' ' + stg pop -n 2 --keep && + [ "$(echo $(stg applied))" = "p0" ] && + [ "$(echo $(stg unapplied))" = "p1 p2" ] && + [ "$(echo $(ls patch?.txt))" = "patch0.txt" ] && + [ "$(echo $(cat patch0.txt))" = "patch0 local" ] +' + +test_expect_success 'Reset and push patches again' ' + git reset --hard && + stg push -a +' + +test_expect_success 'Pop a patch without local changes' ' + stg pop --keep && + [ "$(echo $(stg applied))" = "p0 p1" ] && + [ "$(echo $(stg unapplied))" = "p2" ] && + [ "$(echo $(ls patch?.txt))" = "patch0.txt patch1.txt" ] +' + +test_done
PATCH 3/8 Fix up the help text for "stg edit"
In reply to Karl HasselströmThe sentence structure was strange, and the example format was somewhat misleading (StGit doesn't care about sign-off lines, for example).
---
stgit/commands/edit.py | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-)
stgit/commands/edit.py +15 -9
@@ -30,19 +30,25 @@ from stgit import stack, git help = 'edit a patch description or diff' usage = """%prog [options] [<patch>] -Edit the given patch (defaulting to the current one) description, -author information or its diff (if the '--diff' option is -passed). Without any other option, the command invokes the editor with -the patch description and diff in the form below: +Edit the description and author information of the given patch (or the +current patch if no patch name was given). With --diff, also edit the +diff. - Subject line +The editor is invoked with the following contents: - From: author information + Patch short description + + From: A U Thor <[email protected]> Date: creation date - Patch description + Patch long description + +If --diff was specified, the diff appears at the bottom, after a +separator: + + --- - Signed-off-by: author + Diff text Command-line options can be used to modify specific information without invoking the editor.
@@ -54,7 +60,7 @@ these files using the '--file' and '--diff' options. """ options = [make_option('-d', '--diff', - help = 'allow the editing of the patch diff', + help = 'edit the patch diff', action = 'store_true'), make_option('-f', '--file', help = 'use FILE instead of invoking the editor'),
PATCH 4/8 Don't split long and short description in "stg edit"
In reply to Karl Hasselström"stg edit" used to present the patch information like this:
Short description
From: ...
Date: ...
Long description
If the project follows the git convention with a single-line short description and follwed by a blank line and the rest of the description, this merely looks a little odd. However, for projects that don't follow that convention, presenting the first line separately is actively inconvenient; for example, it breaks emacs's fill-paragraph command.
---
stgit/commands/edit.py | 17 ++++------------- 1 files changed, 4 insertions(+), 13 deletions(-)
stgit/commands/edit.py +4 -13
@@ -36,12 +36,10 @@ diff. The editor is invoked with the following contents: - Patch short description - From: A U Thor <[email protected]> Date: creation date - Patch long description + Patch description If --diff was specified, the diff appears at the bottom, after a separator:
@@ -135,22 +133,15 @@ def __edit_update_patch(pname, options): # generate the file to be edited descr = patch.get_description().strip() - descr_lines = descr.split('\n') authdate = patch.get_authdate() - short_descr = descr_lines[0].rstrip() - long_descr = reduce(lambda x, y: x + '\n' + y, - descr_lines[1:], '').strip() - - tmpl = '%(shortdescr)s\n\n' \ - 'From: %(authname)s <%(authemail)s>\n' + tmpl = 'From: %(authname)s <%(authemail)s>\n' if authdate: tmpl += 'Date: %(authdate)s\n' - tmpl += '\n%(longdescr)s\n' + tmpl += '\n%(descr)s\n' tmpl_dict = { - 'shortdescr': short_descr, - 'longdescr': long_descr, + 'descr': descr, 'authname': patch.get_authname(), 'authemail': patch.get_authemail(), 'authdate': patch.get_authdate()
Re: [StGit PATCH 4/8] Don't split long and short description in "stg edit"
Quoted 7 lines · Karl Hasselström
"stg edit" used to present the patch information like this:
Short description
From: ...
Date: ...
Quoted 8 lines
Long description
If the project follows the git convention with a single-line short description and follwed by a blank line and the rest of the description, this merely looks a little odd. However, for projects that don't follow that convention, presenting the first line separately is actively inconvenient; for example, it breaks emacs's fill-paragraph command.
I think this fix is better to begin with. I found it especially confusing when there was only a single line commit message. Now the header looks like a header :-)
David
Re: [StGit PATCH 4/8] Don't split long and short description in "stg edit"
Quoted 7 lines · David Brown
Quoted 1 line · Karl Hasselström
"stg edit" used to present the patch information like this:
I think this fix is better to begin with. I found it especially confusing when there was only a single line commit message. Now the header looks like a header :-)
Yes, that case was confusing too.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 5/8 Make a common superclass for all StGit exceptions
In reply to Karl HasselströmThis makes it easier to catch them all. (Indeed, the very long list of exceptions to catch in main.py was missing some of the exceptions.)
---
stgit/commands/common.py | 5 +++-- stgit/config.py | 3 ++- stgit/exception.py | 3 +++ stgit/git.py | 3 ++- stgit/gitmergeonefile.py | 3 ++- stgit/main.py | 11 +++-------- stgit/run.py | 5 +++-- stgit/stack.py | 3 ++- stgit/utils.py | 3 ++- 9 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 stgit/exception.py
stgit/commands/common.py +3 -2
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys, os, os.path, re from optparse import OptionParser, make_option +from stgit.exception import * from stgit.utils import * from stgit.out import * from stgit import stack, git, basedir
@@ -30,11 +31,11 @@ crt_series = None # Command exception class -class CmdException(Exception): +class CmdException(StgException): pass # Utility functions -class RevParseException(Exception): +class RevParseException(StgException): """Revision spec parse error.""" pass
stgit/config.py +2 -1
@@ -20,9 +20,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os, re from stgit import basedir +from stgit.exception import * from stgit.run import * -class GitConfigException(Exception): +class GitConfigException(StgException): pass class GitConfig:
stgit/exception.py new file +3 -0
@@ -0,0 +1,3 @@ +class StgException(Exception): + """Base class for all StGit exceptions.""" + pass
stgit/git.py +2 -1
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys, os, re, gitmergeonefile from shutil import copyfile +from stgit.exception import * from stgit import basedir from stgit.utils import * from stgit.out import *
@@ -28,7 +29,7 @@ from stgit.run import * from stgit.config import config # git exception class -class GitException(Exception): +class GitException(StgException): pass # When a subprocess has a problem, we want the exception to be a
stgit/gitmergeonefile.py +2 -1
@@ -19,13 +19,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import sys, os +from stgit.exception import * from stgit import basedir from stgit.config import config, file_extensions, ConfigOption from stgit.utils import append_string from stgit.out import * from stgit.run import * -class GitMergeException(Exception): +class GitMergeException(StgException): pass
stgit/main.py +3 -8
@@ -255,13 +255,10 @@ def main(): # These modules are only used from this point onwards and do not # need to be imported earlier + from stgit.exception import StgException from stgit.config import config_setup from ConfigParser import ParsingError, NoSectionError - from stgit.stack import Series, StackException - from stgit.git import GitException - from stgit.commands.common import CmdException - from stgit.gitmergeonefile import GitMergeException - from stgit.utils import EditorException + from stgit.stack import Series try: debug_level = int(os.environ['STGIT_DEBUG_LEVEL'])
@@ -284,9 +281,7 @@ def main(): stgit.commands.common.crt_series = command.crt_series command.func(parser, options, args) - except (IOError, ParsingError, NoSectionError, CmdException, - StackException, GitException, GitMergeException, - EditorException), err: + except (StgException, IOError, ParsingError, NoSectionError), err: print >> sys.stderr, '%s %s: %s' % (prog, cmd, err) if debug_level > 0: raise
stgit/run.py +3 -2
@@ -19,9 +19,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import datetime, os, subprocess -from stgit.out import * +from stgit.exception import * +from stgit.out import * -class RunException(Exception): +class RunException(StgException): """Thrown when something bad happened when we tried to run the subprocess.""" pass
stgit/stack.py +2 -1
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys, os, re from email.Utils import formatdate +from stgit.exception import * from stgit.utils import * from stgit.out import * from stgit.run import *
@@ -30,7 +31,7 @@ from shutil import copyfile # stack exception class -class StackException(Exception): +class StackException(StgException): pass class FilterUntil:
stgit/utils.py +2 -1
@@ -2,6 +2,7 @@ """ import errno, optparse, os, os.path, re, sys +from stgit.exception import * from stgit.config import config from stgit.out import *
@@ -166,7 +167,7 @@ def rename(basedir, file1, file2): # file1's parent dir may not be empty after move pass -class EditorException(Exception): +class EditorException(StgException): pass def call_editor(filename):
PATCH 6/8 Simplify debug level error checking
In reply to Karl Hasselström---
stgit/main.py | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
stgit/main.py +1 -3
@@ -261,9 +261,7 @@ def main(): from stgit.stack import Series try: - debug_level = int(os.environ['STGIT_DEBUG_LEVEL']) - except KeyError: - debug_level = 0 + debug_level = int(os.environ.get('STGIT_DEBUG_LEVEL', 0)) except ValueError: out.error('Invalid STGIT_DEBUG_LEVEL environment variable') sys.exit(1)
PATCH 7/8 Discard stderr output from git-rev-parse
In reply to Karl HasselströmThis gets rid of the annoying "fatal: Needed a single revision" messages that were printed in addition to StGit's own error message.
---
stgit/git.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
stgit/git.py +2 -1
@@ -301,7 +301,8 @@ def rev_parse(git_id): """Parse the string and return a verified SHA1 id """ try: - return GRun('git-rev-parse', '--verify', git_id).output_one_line() + return GRun('git-rev-parse', '--verify', git_id + ).discard_stderr().output_one_line() except GitRunException: raise GitException, 'Unknown revision: %s' % git_id
PATCH 8/8 Remove the --force flag to "stg rebase" and "stg pull"
In reply to Karl HasselströmInstead, always behave as if the force flag was given; that is, don't check if rebasing would leave a dangling commit behind. Reasons:
* The check for this was very strict and caused a lot of false positives.
* Everything is recorded in the reflog, so we can't actually lose commits.
This fixes bug 9181.
---
stgit/commands/common.py | 9 +-------- stgit/commands/pull.py | 5 +---- stgit/commands/rebase.py | 5 +---- stgit/stack.py | 1 - t/t2100-pull-policy-fetch.sh | 14 -------------- t/t2102-pull-policy-rebase.sh | 24 ------------------------ 6 files changed, 3 insertions(+), 55 deletions(-)
stgit/commands/common.py +1 -8
@@ -318,14 +318,7 @@ def address_or_alias(addr_str): for addr in addr_str.split(',')] return ', '.join([addr for addr in addr_list if addr]) -def prepare_rebase(force=None): - if not force: - # Be sure we won't loose results of stg-(un)commit by error. - # Do not require an existing orig-base for compatibility with 0.12 and earlier. - origbase = crt_series._get_field('orig-base') - if origbase and crt_series.get_base() != origbase: - raise CmdException, 'Rebasing would possibly lose data' - +def prepare_rebase(): # pop all patches applied = crt_series.get_applied() if len(applied) > 0:
stgit/commands/pull.py +1 -4
@@ -43,9 +43,6 @@ options = [make_option('-n', '--nopush', action = 'store_true'), make_option('-m', '--merged', help = 'check for patches merged upstream', - action = 'store_true'), - make_option('--force', - help = 'force rebase even if the stack based was moved by (un)commits', action = 'store_true')] def func(parser, options, args):
@@ -81,7 +78,7 @@ def func(parser, options, args): if policy not in ['pull', 'fetch-rebase', 'rebase']: raise GitConfigException, 'Unsupported pull-policy "%s"' % policy - applied = prepare_rebase(force=options.force) + applied = prepare_rebase() # pull the remote changes if policy == 'pull':
stgit/commands/rebase.py +1 -4
@@ -34,9 +34,6 @@ options = [make_option('-n', '--nopush', action = 'store_true'), make_option('-m', '--merged', help = 'check for patches merged upstream', - action = 'store_true'), - make_option('--force', - help = 'force rebase even if the stack based was moved by (un)commits', action = 'store_true')] def func(parser, options, args):
@@ -56,7 +53,7 @@ def func(parser, options, args): if git_id(args[0]) == None: raise GitException, 'Unknown revision: %s' % args[0] - applied = prepare_rebase(force=options.force) + applied = prepare_rebase() rebase(args[0]) post_rebase(applied, options.nopush, options.merged)
stgit/stack.py +0 -1
@@ -623,7 +623,6 @@ class Series(PatchSet): self.create_empty_field('applied') self.create_empty_field('unapplied') - self._set_field('orig-base', git.get_head()) config.set(self.format_version_key(), str(FORMAT_VERSION))
t/t2100-pull-policy-fetch.sh +0 -14
@@ -55,18 +55,4 @@ test_expect_success \ test `wc -l <clone/file2` = 3 ' -# this one exercises the guard against commits -# (use a new file to avoid mistaking a conflict for a success) -test_expect_success \ - 'New upstream commit and commit a patch in clone' \ - ' - (cd upstream && stg new u2 -m u2 && - echo a > file3 && stg add file3 && stg refresh) && - (cd clone && stg commit && stg new c2 -m c2 && - echo a >> file && stg refresh) - ' -test_expect_success \ - 'Try to and commit a patch in clone' \ - '(cd clone && ! stg pull)' - test_done
t/t2102-pull-policy-rebase.sh +0 -24
@@ -36,28 +36,4 @@ test_expect_success \ test `wc -l <file2` = 2 ' -# this one exercises the guard against commits -# (use a new file to avoid mistaking a conflict for a success) -test_expect_success \ - 'New commit in parent and commit a patch in stack' \ - ' - stg branch parent && stg new u2 -m u2 && - echo c > file3 && stg add file3 && stg refresh && - stg branch stack && stg commit && stg new c2 -m c2 && - echo a >> file && stg refresh - ' -test_expect_success \ - 'Try to pull/rebase now that stack base has moved' \ - '! stg pull' - -test_expect_success \ - 'Force the pull/rebase, but do not push yet' \ - 'stg pull --force --nopush' -test_expect_success \ - '...check we lost the committed patch' \ - '! test -e file' -test_expect_success \ - '...and check we get a conflict while pushing' \ - '! stg push' - test_done