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

Re: [PATCH] diff: handle --no-abbrev outside of repository

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 28, 2016, 23:03 UTC
Message-ID
<xmqqbmwzi4wa.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20161128182508.10570-1-jack@nottheoilrig.com>
Jack Bates <bk874k@nottheoilrig.com> writes:
Show 5 quoted lines
> The "git diff --no-index" codepath doesn't handle the --no-abbrev
> option.
>
> Signed-off-by: Jack Bates <jack@nottheoilrig.com>
> ---

This patch also needs a new test to protect the fix from future breakages.

It is unfortunate that parsing of these options that are done in diff_opt_parse() are not used by most of the codepaths; they instead rely on revision.c parser to parse them into revs->abbrev and then copied to revs->diffopt.abbrev in setup_revisions(). We would want to rethink the structure of the code around this, and possibly move towards using setup_revisions() more when appropriate and removing diff_opt_parse() or something like that; the three-way fallback codepath in builtin/am.c is the only other caller of this function and it uses it to parse a fixed "--diff-filter=AM" option into rev_info.diffopt and manually sets up rev_info as if revision parser was given "diff --cached HEAD", which we should be able to replace with a call to setup_revisions() of "--diff-filter=AM --cached HEAD", I would suspect. But that is a much larger change.

In any case, for now, the fix in this patch is a single best step that moves us forward.

Thanks.
Show 26 quoted lines
>  diff.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/diff.c b/diff.c
> index ec87283..0447eff 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -3106,7 +3106,8 @@ static const char *diff_abbrev_oid(const struct object_id *oid, int abbrev)
>  			abbrev = FALLBACK_DEFAULT_ABBREV;
>  		if (abbrev > GIT_SHA1_HEXSZ)
>  			die("BUG: oid abbreviation out of range: %d", abbrev);
> -		hex[abbrev] = '\0';
> +		if (abbrev)
> +			hex[abbrev] = '\0';
>  		return hex;
>  	}
>  }
> @@ -4024,6 +4025,8 @@ int diff_opt_parse(struct diff_options *options,
>  			    offending, optarg);
>  		return argcount;
>  	}
> +	else if (!strcmp(arg, "--no-abbrev"))
> +		options->abbrev = 0;
>  	else if (!strcmp(arg, "--abbrev"))
>  		options->abbrev = DEFAULT_ABBREV;
>  	else if (skip_prefix(arg, "--abbrev=", &arg)) {
Previous: Jack BatesNext: Jeff King
Message 2 of 13 in “diff: handle --no-abbrev outside of repository”
  1. diff: handle --no-abbrev outside of repositoryJack Bates, Nov 28, 2016
  2. Junio C HamanoNov 28, 2016
  3. Jeff KingNov 29, 2016
  4. diff: handle --no-abbrev outside of repositoryJack Bates, Dec 2, 2016
  5. Jeff KingDec 5, 2016
  6. Jeff KingDec 5, 2016
  7. Jeff KingDec 5, 2016
  8. diff: handle --no-abbrev in no-index caseJack Bates, Dec 6, 2016
  9. diff: handle --no-abbrev in no-index caseJack Bates, Dec 6, 2016
  10. diff: handle --no-abbrev in no-index caseJack Bates, Dec 6, 2016
  11. Jack BatesDec 6, 2016
  12. Junio C HamanoDec 8, 2016
  13. Jack BatesDec 9, 2016

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.