Re: [PATCH v2] add --abbrev to 'git cherry'
- From
Markus Heidelberg <markus.heidelberg@web.de>
- Date
- May 30, 2009, 16:26 UTC
- Message-ID
- <200905301826.11924.markus.heidelberg@web.de>
- In-Reply-To
- <20090530140349.GA25265@unpythonic.net>
Jeff Epler, 30.05.2009:
> Documentation/git-cherry.txt | 5 ++++- > builtin-log.c | 24 +++++++++++++++++++----- > 2 files changed, 23 insertions(+), 6 deletions(-)
You could also add --abbrev= to the bash completion.
Show 10 quoted lines
> diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt > index 7deefda..5c03da0 100644 > --- a/Documentation/git-cherry.txt > +++ b/Documentation/git-cherry.txt > @@ -49,6 +49,9 @@ OPTIONS > -v:: > Verbose. > > +--abbrev[=<n>]:: > + Abbreviate commit ids to the given number of characters
The full stop is missing :) And you could add "The default value is 7." as in the git-branch docs. Or even copy the whole description from there for consistency, it also mentions that this sets the minimum length, the displayed SHA1 may be longer, but more about this below.
Show 18 quoted lines
> diff --git a/builtin-log.c b/builtin-log.c
> index f10cfeb..1f3093e 100644
> --- a/builtin-log.c
> +++ b/builtin-log.c
> @@ -1218,12 +1232,12 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
> struct strbuf buf = STRBUF_INIT;
> pretty_print_commit(CMIT_FMT_ONELINE, commit,
> &buf, 0, NULL, NULL, 0, 0);
> - printf("%c %s %s\n", sign,
> + printf("%c %.*s %s\n", sign, abbrev,
> sha1_to_hex(commit->object.sha1), buf.buf);
> strbuf_release(&buf);
> }
> else {
> - printf("%c %s\n", sign,
> + printf("%c %.*s\n", sign, abbrev,
> sha1_to_hex(commit->object.sha1));
> }There is no test for unique ids. "git cherry --abbrev=4" always prints 4 chars per SHA1, so "git show" on these SHA1s mostly gives "error: short SHA1 xxxx is ambiguous." in git.git.
find_unique_abbrev() will help.
Markus