From: Catalin Marinas Date: Wed, 22 Nov 2006 20:14:58 +0000 (+0000) Subject: Add a boundary to parse_patches() X-Git-Tag: v0.14.3~411 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/ceba3178f434c2a1fc4c839459efe15b9953fe7c Add a boundary to parse_patches() This is useful since specifying the ".." range would generate all the applied and unapplied patches for commands like "show" and "delete". With this patch, the boundary is crossed only if specifically asked (i.e. the first and last patch of the range are on each side of the boundary). Signed-off-by: Catalin Marinas --- diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 4e802bc..723fc5b 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -214,7 +214,7 @@ def pop_patches(patches, keep = False): print 'done' -def parse_patches(patch_args, patch_list): +def parse_patches(patch_args, patch_list, boundary = 0): """Parse patch_args list for patch names in patch_list and return a list. The names can be individual patches and/or in the patch1..patch2 format. @@ -236,12 +236,26 @@ def parse_patches(patch_args, patch_list): if pair[0]: first = patch_list.index(pair[0]) else: - first = 0 + first = -1 # exclusive boundary if pair[1]: last = patch_list.index(pair[1]) + 1 else: - last = len(patch_list) + last = -1 + + # only cross the boundary if explicitly asked + if not boundary: + boundary = len(patch_list) + if first < 0: + if last <= boundary: + first = 0 + else: + first = boundary + if last < 0: + if first < boundary: + last = boundary + else: + last = len(patch_list) if last > first: pl = patch_list[first:last] diff --git a/stgit/commands/delete.py b/stgit/commands/delete.py index 515f4b7..e1a70c9 100644 --- a/stgit/commands/delete.py +++ b/stgit/commands/delete.py @@ -46,7 +46,7 @@ def func(parser, options, args): all_patches = applied_patches + unapplied_patches if args: - patches = parse_patches(args, all_patches) + patches = parse_patches(args, all_patches, len(applied_patches)) else: parser.error('No patches specified') diff --git a/stgit/commands/show.py b/stgit/commands/show.py index 5c297c0..a270efd 100644 --- a/stgit/commands/show.py +++ b/stgit/commands/show.py @@ -41,10 +41,13 @@ options = [make_option('-a', '--applied', def func(parser, options, args): """Show commit log and diff """ + applied = crt_series.get_applied() + unapplied = crt_series.get_unapplied() + if options.applied: - patches = crt_series.get_applied() + patches = applied elif options.unapplied: - patches = crt_series.get_unapplied() + patches = unapplied elif len(args) == 0: patches = ['HEAD'] else: @@ -53,8 +56,7 @@ def func(parser, options, args): # it might be just a commit id patches = args else: - patches = parse_patches(args, crt_series.get_applied() - + crt_series.get_unapplied()) + patches = parse_patches(args, applied + unapplied, len(applied)) commit_ids = [git_id(patch) for patch in patches] commit_str = '\n'.join([git.pretty_commit(commit_id)