Hi list, Here are several patches to enhance stgit.
Sorry that I can't use 'stgit' to send right now for improper network configuration here, so I attached them. Please help review, and hopefully can be accepted. Thanks! -- Guanqun
From 3b618e66cd72d4ccea405f02f645b393a4072cb4 Mon Sep 17 00:00:00 2001 From: Lu Guanqun <[email protected]> Date: Tue, 9 Aug 2011 09:33:52 +0800 Subject: [PATCH 1/6] fix typo in examples/gitconfig Signed-off-by: Lu Guanqun <[email protected]> --- examples/gitconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/examples/gitconfig b/examples/gitconfig index f6aab37..d0c0ebc 100644 --- a/examples/gitconfig +++ b/examples/gitconfig @@ -76,7 +76,7 @@ #shortnr = 5 # The maximum length of an automatically generated patch name - #namelenth = 30 + #namelength = 30 # Extra options to pass to "git diff" (extend/override with # -O/--diff-opts). For example, -M turns on rename detection. -- 1.7.6
From 12e845bad8d57c5c51afefca4b8f415416f99c43 Mon Sep 17 00:00:00 2001 From: Lu Guanqun <[email protected]> Date: Sun, 28 Aug 2011 22:26:38 +0800 Subject: [PATCH 2/6] implement numeric shortcuts Signed-off-by: Lu Guanqun <[email protected]> --- TODO | 1 - stgit/main.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletions(-) diff --git a/TODO b/TODO index a01daef..0f5790d 100644 --- a/TODO +++ b/TODO @@ -28,5 +28,4 @@ The future, when time allows or if someone else does them: - multiple heads in a patch - useful for forking a patch, synchronising with other patches (diff format or in other repositories) -- numeric shortcuts for naming patches near top (eg. +1, -2) - (config?) parameter for number of patches included by "series -s" diff --git a/stgit/main.py b/stgit/main.py index d5be70b..ca2f0be 100644 --- a/stgit/main.py +++ b/stgit/main.py @@ -144,6 +144,18 @@ def _main(): if cmd in ['copyright']: print __copyright__ sys.exit(utils.STGIT_SUCCESS) + try: + patches_nr = int(cmd) + if patches_nr >= 0: + cmd = 'push' + else: + cmd = 'pop' + patches_nr = -patches_nr + sys.argv[1] = cmd + del sys.argv[2:] + sys.argv += ['-n', str(patches_nr)] + except: + pass # re-build the command line arguments cmd = commands.canonical_cmd(cmd) -- 1.7.6
From 703cf61fbf1776a6ee7005249b4c9054baddeac3 Mon Sep 17 00:00:00 2001 From: Lu Guanqun <[email protected]> Date: Sun, 28 Aug 2011 22:59:08 +0800 Subject: [PATCH 3/6] remove obseleted TODO item This TODO item was done with this commit, so remove it. c6f366f6b7452e24edf5bff06da8b69c500899a4 Author: Catalin Marinas <[email protected]> Date: Fri Jan 26 22:29:10 2007 +0000 Make the 'series --short' length configurable The 'shortnr' config option was added so that one can set a different length than the default 5. Signed-off-by: Catalin Marinas <[email protected]> Signed-off-by: Lu Guanqun <[email protected]> --- TODO | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/TODO b/TODO index 0f5790d..17670f6 100644 --- a/TODO +++ b/TODO @@ -28,4 +28,3 @@ The future, when time allows or if someone else does them: - multiple heads in a patch - useful for forking a patch, synchronising with other patches (diff format or in other repositories) -- (config?) parameter for number of patches included by "series -s" -- 1.7.6
From f92b36009a6515ccf74af45072bb5344167255b2 Mon Sep 17 00:00:00 2001 From: Lu Guanqun <[email protected]> Date: Mon, 5 Sep 2011 23:33:21 +0800 Subject: [PATCH 4/6] add color to series command The ANSI escape sequence chart is got from http://pypi.python.org/pypi/colorama The example file is updated as well to show how to specify the colors. Signed-off-by: Lu Guanqun <[email protected]> --- examples/gitconfig | 7 +++++++ stgit/commands/series.py | 46 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/examples/gitconfig b/examples/gitconfig index d0c0ebc..48a4246 100644 --- a/examples/gitconfig +++ b/examples/gitconfig @@ -92,3 +92,10 @@ [mail "alias"] # E-mail aliases used with the 'mail' command git = [email protected] + +[stgit "color"] + # Specify output colors for series commands + applied = green_foreground + current = red_foreground + unapplied = white_foreground + hidden = cyan_foreground diff --git a/stgit/commands/series.py b/stgit/commands/series.py index f3d3f83..1fa9c20 100644 --- a/stgit/commands/series.py +++ b/stgit/commands/series.py @@ -86,7 +86,32 @@ def __get_author(stack, patch): cd = stack.patches.get(patch).commit.data return cd.author.name -def __print_patch(stack, patch, branch_str, prefix, length, options): +def __render_text(text, effects): + _effects = { 'none' : 0, + 'bright' : 1, + 'dim' : 2, + 'black_foreground' : 30, + 'red_foreground' : 31, + 'green_foreground' : 32, + 'yellow_foreground' : 33, + 'blue_foreground' : 34, + 'magenta_foreground' : 35, + 'cyan_foreground' : 36, + 'white_foreground' : 37, + 'black_background' : 40, + 'red_background' : 41, + 'green_background' : 42, + 'yellow_background' : 44, + 'blue_background' : 44, + 'magenta_background' : 45, + 'cyan_background' : 46, + 'white_background' : 47 } + start = [str(_effects[e]) for e in effects.split() if e in _effects] + start = '\033[' + ';'.join(start) + 'm' + stop = '\033[' + str(_effects['none']) + 'm' + return ''.join([start, text, stop]) + +def __print_patch(stack, patch, branch_str, prefix, length, options, effects): """Print a patch name, description and various markers. """ if options.noprefix: @@ -103,11 +128,15 @@ def __print_patch(stack, patch, branch_str, prefix, length, options): patch_str = patch_str.ljust(length) if options.description: - out.stdout(prefix + patch_str + ' # ' + __get_description(stack, patch)) + output = prefix + patch_str + ' # ' + __get_description(stack, patch) elif options.author: - out.stdout(prefix + patch_str + ' # ' + __get_author(stack, patch)) + output = prefix + patch_str + ' # ' + __get_author(stack, patch) else: - out.stdout(prefix + patch_str) + output = prefix + patch_str + if not effects: + out.stdout(output) + else: + out.stdout(__render_text(output, effects)) def func(parser, options, args): """Show the patch series @@ -190,12 +219,11 @@ def func(parser, options, args): if applied: for p in applied[:-1]: - __print_patch(stack, p, branch_str, '+ ', max_len, options) - __print_patch(stack, applied[-1], branch_str, '> ', max_len, - options) + __print_patch(stack, p, branch_str, '+ ', max_len, options, config.get("stgit.color.applied")) + __print_patch(stack, applied[-1], branch_str, '> ', max_len, options, config.get("stgit.color.current")) for p in unapplied: - __print_patch(stack, p, branch_str, '- ', max_len, options) + __print_patch(stack, p, branch_str, '- ', max_len, options, config.get("stgit.color.unapplied")) for p in hidden: - __print_patch(stack, p, branch_str, '! ', max_len, options) + __print_patch(stack, p, branch_str, '! ', max_len, options, config.get("stgit.color.hidden")) -- 1.7.6
From 8da2095cea36a6eae6c99662076ab30bcbd6d38a Mon Sep 17 00:00:00 2001 From: Lu Guanqun <[email protected]> Date: Mon, 5 Sep 2011 23:34:01 +0800 Subject: [PATCH 5/6] add a new config called 'aliasesfile' It will take an mutt alias file into the consideration. However, stgit provides another way to specify the alias which is the stgit.mail.alias section, this section take predences over the mutt aliases, i.e. if you both have an alias called 'foo', the full name specified in mail.alias section will be used, the mutt aliases part is simply ignored. Signed-off-by: Lu Guanqun <[email protected]> --- examples/gitconfig | 3 +++ stgit/config.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/examples/gitconfig b/examples/gitconfig index 48a4246..4d7e26d 100644 --- a/examples/gitconfig +++ b/examples/gitconfig @@ -85,6 +85,9 @@ # Behave as if the --keep option is always passed #autokeep = no + # Mutt aliases file + #aliasesfile = ~/.mutt/aliases + [stgit "alias"] # Command aliases. #add = git add diff --git a/stgit/config.py b/stgit/config.py index dd194d3..83b310b 100644 --- a/stgit/config.py +++ b/stgit/config.py @@ -103,6 +103,9 @@ class GitConfig: Run('git', 'config', name, value).run() self.__cache[name] = value + def insert_head(self, key, value): + self.__cache.setdefault(key, []).insert(0, value) + def unset(self, name): Run('git', 'config', '--unset', name).run() self.__cache[name] = [None] @@ -127,6 +130,21 @@ class GitConfig: config=GitConfig() +def append_aliases(config): + try: + aliasfile = config.get('stgit.aliasesfile') + if not aliasfile: + return + f = open(os.path.expanduser(aliasfile)) + for line in f.readlines(): + words = line.split() + if len(words) >= 3 and words[0] == 'alias': + value = ' '.join(words[2:]).decode('string_escape') + config.insert_head(words[1], value) + f.close() + except IOError: + pass + def config_setup(): global config @@ -134,6 +152,8 @@ def config_setup(): os.environ.setdefault('LESS', '-FRSX') # FIXME: handle EDITOR the same way ? + append_aliases(config) + class ConfigOption: """Delayed cached reading of a configuration option. """ -- 1.7.6
From 6359aaf0e9cc67c57e677c17d5044ddce5ec0a6b Mon Sep 17 00:00:00 2001 From: Lu Guanqun <[email protected]> Date: Tue, 6 Sep 2011 09:45:12 +0800 Subject: [PATCH 6/6] add fuzzy patch name lookup support for 'goto' command With this patch, we can now specify part of a long patch name, and it will try to match the correct one. Signed-off-by: Lu Guanqun <[email protected]> --- stgit/commands/common.py | 10 ++++++++++ stgit/commands/goto.py | 12 +++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 2c525ba..dae524c 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -192,6 +192,16 @@ def pop_patches(crt_series, patches, keep = False): crt_series.pop_patch(p, keep) out.done() +def get_patch_from_list(part_name, patch_list): + candidates = [full for full in patch_list if str.find(full, part_name) != -1] + if len(candidates) >= 2: + out.info('Possible patches:\n %s' % '\n '.join(candidates)) + raise CmdException, 'ambiguous patch name: %s' % part_name + elif len(candidates) == 1: + return candidates[0] + else: + return None + def parse_patches(patch_args, patch_list, boundary = 0, ordered = False): """Parse patch_args list for patch names in patch_list and return a list. The names can be individual patches and/or in the diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py index d201a91..153aff2 100644 --- a/stgit/commands/goto.py +++ b/stgit/commands/goto.py @@ -42,6 +42,14 @@ def func(parser, options, args): clean_iw = (not options.keep and iw) or None trans = transaction.StackTransaction(stack, 'goto', check_clean_iw = clean_iw) + + all_patches = trans.applied + trans.unapplied + trans.hidden + if not patch in all_patches: + candidate = common.get_patch_from_list(patch, all_patches) + if candidate is None: + raise common.CmdException('Patch "%s" does not exist' % patch) + patch = candidate + if patch in trans.applied: to_pop = set(trans.applied[trans.applied.index(patch)+1:]) assert not trans.pop_patches(lambda pn: pn in to_pop) @@ -57,8 +65,6 @@ def func(parser, options, args): already_merged = pn in merged) except transaction.TransactionHalted: pass - elif patch in trans.hidden: - raise common.CmdException('Cannot goto a hidden patch') else: - raise common.CmdException('Patch "%s" does not exist' % patch) + raise common.CmdException('Cannot goto a hidden patch') return trans.run(iw) -- 1.7.6
_______________________________________________ stgit-users mailing list [email protected] https://mail.gna.org/listinfo/stgit-users
