git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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)"
> +               ;;
> +       esac

Completion 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.

Previous: Jeff EplerNext: Junio C Hamano
Message 4 of 9 in “add --abbrev to 'git cherry'”
  1. add --abbrev to 'git cherry'Jeff Epler, May 30, 2009
  2. Markus HeidelbergMay 30, 2009
  3. add --abbrev to 'git cherry'Jeff Epler, May 30, 2009
  4. Stephen BoydMay 30, 2009
  5. Junio C HamanoMay 30, 2009
  6. Markus HeidelbergMay 30, 2009
  7. Junio C HamanoMay 31, 2009
  8. Stephen BoydMay 31, 2009
  9. Jeff EplerJun 1, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.