Re: [PATCH v3] add --abbrev to 'git cherry'
- From
Stephen Boyd <bebarino@gmail.com>
- Date
- May 30, 2009, 21:13 UTC
- Message-ID
- <780e0a6b0905301413o2686fe34qaa076209c26c0b55@mail.gmail.com>
- In-Reply-To
- <20090530165306.GA1142@unpythonic.net>
On Sat, May 30, 2009 at 9:53 AM, Jeff Epler <jepler@unpythonic.net> wrote:
Show 21 quoted lines
> @@ -1142,9 +1142,23 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
> const char *head = "HEAD";
> const char *limit = NULL;
> int verbose = 0;
> + int abbrev = 40;
> +
> + while(argc > 1 && argv[1][0] == '-') {
> + if (!strcmp(argv[1], "-v")) {
> + verbose = 1;
> + } else if(!strcmp(argv[1], "--abbrev")) {
> + abbrev = DEFAULT_ABBREV;
> + } else if(!prefixcmp(argv[1], "--abbrev=")) {
> + abbrev = strtol(argv[1] + 9, NULL, 10);
> + if(abbrev < MINIMUM_ABBREV)
> + abbrev = MINIMUM_ABBREV;
> + else if(abbrev > 40)
> + abbrev = 40;
> + } else {
> + die("unrecognized argument: %s", argv[1]);
> + }
>You might want to look at using the parse options API. It has options for verbose and abbrev builtin, so you don't have to do any extra work. Plus you get a nice usage message for free. See Documentation/technical/api-parse-options.txt for more info.
Show 18 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index c84d765..536a769 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -804,7 +804,15 @@ _git_checkout ()
>
> _git_cherry ()
> {
> - __gitcomp "$(__git_refs)"
> + local cur="${COMP_WORDS[COMP_CWORD]}"
> + case "$cur" in
> + -*)
> + __gitcomp "-v --abbrev --abbrev="
> + ;;
> + *)
> + __gitcomp "$(__git_refs)"
> + ;;
> + esacCompletion doesn't include short options (-v). This also means that --* is used instead of -*
Finally, you'll want to Cc Shawn (Shawn O. Pearce <spearce@spearce.org>) on bash completion.