git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <bebarino@gmail.com>
To: Jeff Epler <jepler@unpythonic.net>
Cc: git@vger.kernel.org, markus.heidelberg@web.de
Subject: Re: [PATCH v3] add --abbrev to 'git cherry'
Date: Sat, 30 May 2009 14:13:51 -0700	[thread overview]
Message-ID: <780e0a6b0905301413o2686fe34qaa076209c26c0b55@mail.gmail.com> (raw)
In-Reply-To: <20090530165306.GA1142@unpythonic.net>

On Sat, May 30, 2009 at 9:53 AM, Jeff Epler <jepler@unpythonic.net> wrote:
> @@ -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.

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

  reply	other threads:[~2009-05-30 21:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-30 14:03 [PATCH v2] add --abbrev to 'git cherry' Jeff Epler
2009-05-30 16:26 ` Markus Heidelberg
2009-05-30 16:53   ` [PATCH v3] " Jeff Epler
2009-05-30 21:13     ` Stephen Boyd [this message]
2009-05-30 23:08       ` Junio C Hamano
2009-05-30 23:44         ` Markus Heidelberg
2009-05-31  0:16           ` Junio C Hamano
2009-05-31  4:53         ` Stephen Boyd
     [not found]         ` <20090531133804.GB16770@unpythonic.net>
     [not found]           ` <7v8wkdrqys.fsf@alter.siamese.dyndns.org>
2009-06-01 11:54             ` Jeff Epler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=780e0a6b0905301413o2686fe34qaa076209c26c0b55@mail.gmail.com \
    --to=bebarino@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jepler@unpythonic.net \
    --cc=markus.heidelberg@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).