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

Re: [PATCH] combine-diff: honor --relative when printing paths

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 7, 2026, 14:45 UTC
Message-ID
<xmqqld89bmd1.fsf@gitster.g>
In-Reply-To
<20261007051734.62590-1-dilsheddilu123@gmail.com>
Muhammed Dilshad A <dilsheddilu123@gmail.com> writes:
Show 7 quoted lines
> +static const char *strip_relative_prefix(const struct diff_options *opt,
> +					const char *path)
> +{
> +	if (opt->prefix && skip_prefix(path, opt->prefix, &path) && *path == '/')
> +		path++;
> +	return path;
> +}

That's quite a long line. Read about coding guidelines in our Documentation/ directory.

Also, do callers guarantee that path may have only up to one trailing slashes and never two or more?

Show 22 quoted lines
> @@ -932,6 +940,7 @@ static void show_combined_header(struct combine_diff_path *elem,
>  	const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
>  	const char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO);
>  	const char *c_reset = diff_get_color_opt(opt, DIFF_RESET);
> +	const char *name = strip_relative_prefix(opt, elem->path);
>  	const char *abb;
>  	int added = 0;
>  	int deleted = 0;
> @@ -942,7 +951,7 @@ static void show_combined_header(struct combine_diff_path *elem,
>  		show_log(rev);
>  
>  	dump_quoted_path(dense ? "diff --cc " : "diff --combined ",
> -			 "", elem->path, line_prefix, c_meta, c_reset);
> +			 "", name, line_prefix, c_meta, c_reset);
>  	printf("%s%sindex ", line_prefix, c_meta);
>  	for (i = 0; i < num_parent; i++) {
>  		abb = repo_find_unique_abbrev(the_repository,
> @@ -987,6 +996,7 @@ static void show_combined_header(struct combine_diff_path *elem,
>  			const char *path = elem->parent[i].path ?
>  					   elem->parent[i].path :
>  					   elem->path;
> +			path = strip_relative_prefix(opt, path);

When a rename is involved (e.g., originally the contents was in here/file we have made our changes in place, while the other side moved the file to there/file and made changes there, these were matched up and are shown as a merge into here/file. Wouldn't a elem->parent[].path point at here/file while another points at there/file in such a case? What should happen when our prefix is in "here/"? I know "here/file" should become "file", but what about "there/file" that they bring into the picture?

Not striping anything does give consistent result and would not mislead the readers as long as they understand --relative is ignored. Contrasting to that, "we strip if the path is inside our prefix, but otherwise we give full path" would give ambiguous output, wouldn't it?

Previous: Muhammed Dilshad ANext: Muhammed Dilshad A
Message 2 of 6 in “combine-diff: honor --relative when printing paths”
  1. combine-diff: honor --relative when printing pathsMuhammed Dilshad A, Oct 7, 2026
  2. Junio C HamanoOct 7, 2026
  3. 0/2 combine-diff: honor relative paths consistentlyMuhammed Dilshad A, Oct 7, 2026
  4. 1/2 combine-diff: honor --relative when printing pathsMuhammed Dilshad A, Oct 7, 2026
  5. 2/2 combine-diff: filter the fast scan by the relative prefixMuhammed Dilshad A, Oct 7, 2026
  6. Junio C HamanoOct 7, 2026

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.