From d679e110f3641569dcf8562e9b378c671e86ae2d Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Fri, 7 Dec 2007 21:19:24 +0000 Subject: [PATCH] Allow 'show' and 'id' to work on non-StGIT branches (bug #10011) Some clean-up to only access the current series object if needed. Signed-off-by: Catalin Marinas --- stgit/commands/common.py | 13 ++++++++++++- stgit/commands/show.py | 18 ++++++++---------- t/t2400-diff.sh | 4 ++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/stgit/commands/common.py b/stgit/commands/common.py index bf804e6..78a364f 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -77,6 +77,14 @@ def git_id(crt_series, rev): """ if not rev: return None + + # try a GIT revision first + try: + return git.rev_parse(rev + '^{commit}') + except git.GitException: + pass + + # try an StGIT patch name try: patch, branch, patch_id = parse_rev(rev) if branch == None: @@ -103,7 +111,10 @@ def git_id(crt_series, rev): return series.get_base() except RevParseException: pass - return git.rev_parse(rev + '^{commit}') + except stack.StackException: + pass + + raise CmdException, 'Unknown patch or revision: %s' % rev def check_local_changes(): if git.local_changes(): diff --git a/stgit/commands/show.py b/stgit/commands/show.py index e6814d3..72d1be3 100644 --- a/stgit/commands/show.py +++ b/stgit/commands/show.py @@ -46,23 +46,21 @@ options = [make_option('-b', '--branch', def func(parser, options, args): """Show commit log and diff """ - applied = crt_series.get_applied() - unapplied = crt_series.get_unapplied() - if options.applied: - patches = applied + patches = crt_series.get_applied() elif options.unapplied: - patches = unapplied + patches = crt_series.get_unapplied() elif len(args) == 0: patches = ['HEAD'] else: - if len(args) == 1 and args[0].find('..') == -1 \ - and not crt_series.patch_exists(args[0]): - # it might be just a commit id + if len(args) == 1 and args[0].find('..') == -1: + # single patch or commit id patches = args else: - patches = parse_patches(args, applied + unapplied +\ - crt_series.get_hidden(), len(applied)) + applied = crt_series.get_applied() + unapplied = crt_series.get_unapplied() + patches = parse_patches(args, applied + unapplied + \ + crt_series.get_hidden(), len(applied)) if options.show_opts: show_flags = options.show_opts.split() diff --git a/t/t2400-diff.sh b/t/t2400-diff.sh index 6d9ed98..fbcefe1 100755 --- a/t/t2400-diff.sh +++ b/t/t2400-diff.sh @@ -4,7 +4,7 @@ test_description='Run "stg diff"' . ./test-lib.sh -test_expect_failure 'Diff with no StGit data' ' +test_expect_success 'Diff with no StGit data' ' stg diff ' @@ -13,7 +13,7 @@ test_expect_success 'Make some local changes' ' git add foo.txt ' -test_expect_failure 'Diff with some local changes' ' +test_expect_success 'Diff with some local changes' ' stg diff ' -- 2.11.4.GIT