[PATCH] Keep git-external-diff usage text from executing

Поиск
Список
Период
Сортировка
Искать

[PATCH] Keep git-external-diff usage text from executing

От:
夏侯莯昍 <xiahoumuxuan@gmail.com>
Дата:
Вложения:
Hi,

src/tools/git-external-diff is a Bash script, but its usage text is enclosed
in the Perl POD markers =comment and =cut. Bash therefore tries to execute
the prose and the embedded git config/git diff examples on each invocation.

The attached patch changes only those two delimiters to a quoted no-op
here-document. This preserves the text literally, without executing it or
performing shell expansions, and leaves the actual diff code unchanged.

The patch was prepared against master at
3cde90ecc5f85e7c6cb9fba29d473b2f6dd40ee1.

Validation:
- bash -n and git diff --check pass.
- The attached standalone test passes all three cases with the patch;
  all three fail against the unmodified master file. It records Git calls
  rather than allowing the documentation examples to change configuration
  or invoke another diff. It covers unchanged content, context diffs with
  spaced paths, and custom DIFF_OPTS=-u.
- A separate integration check using real Git in an isolated temporary
  repository produces the expected context diff and leaves configuration
  unchanged.

Run the standalone test with an explicit path to the file under test:
python3 test_git_external_diff.py /path/to/postgres/src/tools/git-external-diff

This was originally proposed to IvorySQL; its maintainers asked that this
inherited tool change be sent upstream first:
https://github.com/IvorySQL/IvorySQL/pull/2510

AI assistance was used to prepare the patch, tests, and this message.
The reported validation results are from actual local runs.

Regards,
zmuxuny

Re: [PATCH] Keep git-external-diff usage text from executing

От:
Chao Li <li.evan.chao@gmail.com>
Дата:


> On Oct 21, 2026, at 12:16, 夏侯莯昍  wrote:
> 
> Hi,
> 
> src/tools/git-external-diff is a Bash script, but its usage text is enclosed
> in the Perl POD markers =comment and =cut. Bash therefore tries to execute
> the prose and the embedded git config/git diff examples on each invocation.
> 
> The attached patch changes only those two delimiters to a quoted no-op
> here-document. This preserves the text literally, without executing it or
> performing shell expansions, and leaves the actual diff code unchanged.
> 
> The patch was prepared against master at
> 3cde90ecc5f85e7c6cb9fba29d473b2f6dd40ee1.
> 
> Validation:
> - bash -n and git diff --check pass.
> - The attached standalone test passes all three cases with the patch;
>  all three fail against the unmodified master file. It records Git calls
>  rather than allowing the documentation examples to change configuration
>  or invoke another diff. It covers unchanged content, context diffs with
>  spaced paths, and custom DIFF_OPTS=-u.
> - A separate integration check using real Git in an isolated temporary
>  repository produces the expected context diff and leaves configuration
>  unchanged.
> 
> Run the standalone test with an explicit path to the file under test:
> python3 test_git_external_diff.py /path/to/postgres/src/tools/git-external-diff
> 
> This was originally proposed to IvorySQL; its maintainers asked that this
> inherited tool change be sent upstream first:
> https://github.com/IvorySQL/IvorySQL/pull/2510
> 
> AI assistance was used to prepare the patch, tests, and this message.
> The reported validation results are from actual local runs.
> 
> Regards,
> zmuxuny
> 

The fix looks good to me.

Per PG News on May 27 2018 [1], not sure how many folks still use this tool:
```
- Preserve information on use of git-external-diff. Now that the Working with
git wiki page no longer suggests producing context diffs, we should preserve
the information on how to use git-external-diff for those people who want to
view context format diffs. The most obvious place is in the script itself, so
that's what's done here.
https://git.postgresql.org/pg/commitdiff/4431c94c3606ab54594b15ad89c7e71e46b4fb6a
```

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






Re: [PATCH] Keep git-external-diff usage text from executing

От:
Chao Li <li.evan.chao@gmail.com>
Дата:


> On Oct 22, 2026, at 14:53, Chao Li  wrote:
> 
> 
> 
>> On Oct 21, 2026, at 12:16, 夏侯莯昍  wrote:
>> 
>> Hi,
>> 
>> src/tools/git-external-diff is a Bash script, but its usage text is enclosed
>> in the Perl POD markers =comment and =cut. Bash therefore tries to execute
>> the prose and the embedded git config/git diff examples on each invocation.
>> 
>> The attached patch changes only those two delimiters to a quoted no-op
>> here-document. This preserves the text literally, without executing it or
>> performing shell expansions, and leaves the actual diff code unchanged.
>> 
>> The patch was prepared against master at
>> 3cde90ecc5f85e7c6cb9fba29d473b2f6dd40ee1.
>> 
>> Validation:
>> - bash -n and git diff --check pass.
>> - The attached standalone test passes all three cases with the patch;
>> all three fail against the unmodified master file. It records Git calls
>> rather than allowing the documentation examples to change configuration
>> or invoke another diff. It covers unchanged content, context diffs with
>> spaced paths, and custom DIFF_OPTS=-u.
>> - A separate integration check using real Git in an isolated temporary
>> repository produces the expected context diff and leaves configuration
>> unchanged.
>> 
>> Run the standalone test with an explicit path to the file under test:
>> python3 test_git_external_diff.py /path/to/postgres/src/tools/git-external-diff
>> 
>> This was originally proposed to IvorySQL; its maintainers asked that this
>> inherited tool change be sent upstream first:
>> https://github.com/IvorySQL/IvorySQL/pull/2510
>> 
>> AI assistance was used to prepare the patch, tests, and this message.
>> The reported validation results are from actual local runs.
>> 
>> Regards,
>> zmuxuny
>> 
> 
> The fix looks good to me.
> 
> Per PG News on May 27 2018 [1], not sure how many folks still use this tool:
> ```
> - Preserve information on use of git-external-diff. Now that the Working with
> git wiki page no longer suggests producing context diffs, we should preserve
> the information on how to use git-external-diff for those people who want to
> view context format diffs. The most obvious place is in the script itself, so
> that's what's done here.
> https://git.postgresql.org/pg/commitdiff/4431c94c3606ab54594b15ad89c7e71e46b4fb6a
> ```

Oops, missed the reference [1].

[1] https://www.postgresql.org/message-id/20180527190517.GA29473%40fetter.org

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






Re: [PATCH] Keep git-external-diff usage text from executing

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Chao Li  writes:
> On Oct 21, 2026, at 12:16, 夏侯莯昍  wrote:
>> src/tools/git-external-diff is a Bash script, but its usage text is enclosed
>> in the Perl POD markers =comment and =cut. Bash therefore tries to execute
>> the prose and the embedded git config/git diff examples on each invocation.

> Per PG News on May 27 2018 [1], not sure how many folks still use this tool:

Surely, the number of people who use it is exactly zero --- else we'd
have heard complaints before now.  So I'm rather inclined to just
delete it instead of expending effort on fixing it.

			regards, tom lane


Re: [PATCH] Keep git-external-diff usage text from executing

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 22 Oct 2026, at 22:33, Tom Lane  wrote:

> So I'm rather inclined to just delete it instead of expending effort on fixing
> it.


+1

--
Daniel Gustafsson



Re: [PATCH] Keep git-external-diff usage text from executing

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
Вложения:
> On 23 Oct 2026, at 05:27, Daniel Gustafsson  wrote:
> 
>> On 22 Oct 2026, at 22:33, Tom Lane  wrote:
> 
>> So I'm rather inclined to just delete it instead of expending effort on fixing
>> it.
> 
> +1

PFA patch removing it.

--
Daniel Gustafsson

Re: [PATCH] Keep git-external-diff usage text from executing

От:
Chao Li <li.evan.chao@gmail.com>
Дата:


> On Oct 25, 2026, at 04:52, Daniel Gustafsson  wrote:
> 
>> On 23 Oct 2026, at 05:27, Daniel Gustafsson  wrote:
>> 
>>> On 22 Oct 2026, at 22:33, Tom Lane  wrote:
>> 
>>> So I'm rather inclined to just delete it instead of expending effort on fixing
>>> it.
>> 
>> +1
> 
> PFA patch removing it.
> 
> --
> Daniel Gustafsson
> 
> <0001-Remove-git-external-diff-from-tools-directory.patch>

LGTM. I also checked if there is any doc needs to be updated for the removal, and didn’t find any.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






Re: [PATCH] Keep git-external-diff usage text from executing

От:
xiahoumuxuan@gmail.com
Дата:
Hi Daniel,

I agree with Tom's reasoning. If this has gone unnoticed for so long,
removing the script makes more sense than fixing it. I'm happy with
removal instead of my original fix. Thanks for preparing the patch.

Regards,
zmuxuny


On Sat, 24 Oct 2026 22:52:57 +0200, Daniel Gustafsson  wrote:
> > On 23 Oct 2026, at 05:27, Daniel Gustafsson  wrote:
> >
> >> On 22 Oct 2026, at 22:33, Tom Lane  wrote:
> >
> >> So I'm rather inclined to just delete it instead of expending effort on fixing
> >> it.
> >
> > +1
>
> PFA patch removing it.
>
> --
> Daniel Gustafsson


Re: [PATCH] Keep git-external-diff usage text from executing

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 25 Oct 2026, at 06:31, xiahoumuxuan@gmail.com wrote:

> I'm happy with removal instead of my original fix.

Hearing no objections, done that way.

--
Daniel Gustafsson



FAQ