Re: [PATCH v5] diff: add config option relative
To
Đoàn Trần Công Danh
Cc
Laurent Arnoud
phillip.wood@dunelm.org.uk
brian m. carlson
git@vger.kernel.org
From
Junio C Hamano
See Also
Prev Ref 1 Ref 2 Ref 3 Ref 4 Ref 5 Ref 6
Date
2020-05-18 16:57:09 UTC
Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:

> I've written some test and concluded that we'll need this fix-up
> to make sure git-format-patch(1) doesn't generate broken patch:
>
> ----------------8<----------------
>  builtin/log.c            |  1 +
>  t/t4045-diff-relative.sh | 11 ++++++++---
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/log.c b/builtin/log.c
> index d104d5c688..5949a4883e 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -1744,6 +1744,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
>  	rev.diff = 1;
>  	rev.max_parents = 1;
>  	rev.diffopt.flags.recursive = 1;
> +	rev.diffopt.flags.relative_name = 0;
>  	rev.subject_prefix = fmt_patch_subject_prefix;
>  	memset(&s_r_opt, 0, sizeof(s_r_opt));
>  	s_r_opt.def = "HEAD";

Hmph, what do you exactly mean by "broken patch"?

I actually do not mind people who set "diff.relative" to do

    $ git config diff.relative true
    $ cd t && git format-patch -1 --stdout

to get an incomplete patch that covers only the t/ subdirectory, as
long as they can ask Git to optionally get the full view with

    $ cd t && git format-patch -1 --stdout --no-relative

Note: this is not limited to format-patch but all the commands in
the diff family like "log --stat", "show", etc.

Of course, diff.relative configuration would have no use for me
personally and I suspect it would be useless for many people, but
those who work inside a deeply nested project (java perhaps?) it
would be handy and it makes sense to match the default behaviour
between "diff", "show" and "format-patch" when the configuration is
active, as long as they have a way to contermand from the command
line.