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

Re: [PATCH RFC] cherry: support --abbrev option

From
Erik Faye-Lund <kusmabite@googlemail.com>
Date
Mar 15, 2010, 22:30 UTC
Message-ID
<40aa078e1003151530y19f10bf1l852a0e5230b11cb6@mail.gmail.com>
In-Reply-To
<4B9E69A4.2080304@lsrfire.ath.cx>

On Mon, Mar 15, 2010 at 6:08 PM, René Scharfe <rene.scharfe@lsrfire.ath.cx> wrote:

Show 52 quoted lines
> Am 15.03.2010 17:03, schrieb Erik Faye-Lund:
>> Switch to parse-options API while we're at it.
>>
>> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
>> ---
>>
>> I sometimes find it useful to look at the commit-subject together with
>> the SHA-1s. Using --abbrev increases the chance that the lines fits on
>> an 80 character wide terminal, making the output easier to read.
>>
>>  builtin/log.c |   40 ++++++++++++++++++++++------------------
>>  1 files changed, 22 insertions(+), 18 deletions(-)
>>
>> diff --git a/builtin/log.c b/builtin/log.c
>> index b70d0f7..020d618 100644
>> --- a/builtin/log.c
>> +++ b/builtin/log.c
>> @@ -1286,8 +1286,11 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
>>       return -1;
>>  }
>>
>> -static const char cherry_usage[] =
>> -"git cherry [-v] [<upstream> [<head> [<limit>]]]";
>> +static const char * const cherry_usage[] = {
>> +     "git cherry [-v] [<upstream> [<head> [<limit>]]]",
>> +     NULL
>> +};
>> +
>>  int cmd_cherry(int argc, const char **argv, const char *prefix)
>>  {
>>       struct rev_info revs;
>> @@ -1298,26 +1301,26 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
>>       const char *upstream;
>>       const char *head = "HEAD";
>>       const char *limit = NULL;
>> -     int verbose = 0;
>> +     int verbose = 0, abbrev = 40;
>>
>> -     if (argc > 1 && !strcmp(argv[1], "-v")) {
>> -             verbose = 1;
>> -             argc--;
>> -             argv++;
>> -     }
>> +     struct option options[] = {
>> +             OPT__ABBREV(&abbrev),
>> +             OPT__VERBOSE(&verbose),
>> +             OPT_END()
>> +     };
>
> If I use --no-abbrev, do I get 0 or 40 hash chars?  I didn't actually
> test it, but I suspect an "if (!abbrev) abbrev = 40;" is needed somewhere.
>

"abbrev" is initialized to 40 when declared, so you get the same behavior as before by default.

Show 10 quoted lines
>> -     if (argc > 1 && !strcmp(argv[1], "-h"))
>> -             usage(cherry_usage);
>> +     argc = parse_options(argc, argv, prefix, options, cherry_usage,
>> +         PARSE_OPT_KEEP_UNKNOWN);
>
> Why do you use PARSE_OPT_KEEP_UNKNOWN here? I think the old option
> parsing code lazily relied on invalid options being found out by
> add_pending_commit() later. We can be lazy again by leaving invalid
> option handling to parse_options(); sure, it changes the error message,
> but for the better.
Actually, It's a mistake, thanks for pointing it out :)
Yeah, I think your suggestion is better. Corrected.
-- 
Erik "kusma" Faye-Lund
Previous: René ScharfeNext: René Scharfe
Message 3 of 10 in “cherry: support --abbrev option”
  1. cherry: support --abbrev optionErik Faye-Lund, Mar 15, 2010
  2. René ScharfeMar 15, 2010
  3. Erik Faye-LundMar 15, 2010
  4. René ScharfeMar 15, 2010
  5. Erik Faye-LundMar 15, 2010
  6. René ScharfeMar 16, 2010
  7. Erik Faye-LundMar 16, 2010
  8. Junio C HamanoMar 16, 2010
  9. Junio C HamanoMar 15, 2010
  10. Erik Faye-LundMar 15, 2010

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.