Skip to content

completion: various __gitdir()-related improvements

SZEDER Gábor git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest21 patches 1 replyIn review

Changes in v2 from the cover letter

- Use our real_path() instead of system realpath() to implement 'git rev-parse --absolute-git-dir'.
- Refactored a bit how __git_refs() determines where it should list refs from.
- Renamed a few refnames and remote in the tests (this accounts for the bulk of the interdiff).
- Misc small adjustments: a few more comments, removed unnecessary disambiguating '--', typofix and more consistent quoting.
- Improved commit messages.
- Rebased to current master.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/21completion: improve __git_refs()'s in-code documentationcontrib/completion/git-completion.bash+5 -30 replies
2/21completion tests: don't add test cruft to the test repositoryt/t9902-completion.sh+3 -30 replies
3/21completion tests: make the $cur variable local to the test helper functionst/t9902-completion.sh+2 -20 replies
4/21completion tests: consolidate getting path of current working directoryt/t9902-completion.sh+21 -230 replies
5/21completion tests: check __gitdir()'s output in the error casest/t9902-completion.sh+5 -30 replies
6/21completion tests: add tests for the __git_refs() helper functiont/t9902-completion.sh+264 -10 replies
7/21completion: ensure that the repository path given on the command line existscontrib/completion/git-completion.bash t/t9902-completion.sh+9 -00 replies
8/21completion: fix most spots not respecting 'git --git-dir=<path>'contrib/completion/git-completion.bash+7 -50 replies
9/21completion: respect 'git --git-dir=<path>' when listing remote refscontrib/completion/git-completion.bash t/t9902-completion.sh+19 -70 replies
10/21completion: list refs from remote when remote's name matches a directorycontrib/completion/git-completion.bash t/t9902-completion.sh+28 -30 replies
11/21completion: don't list 'HEAD' when trying refs completion outside of a repocontrib/completion/git-completion.bash t/t9902-completion.sh+7 -30 replies
12/21completion: list short refs from a remote given as a URLcontrib/completion/git-completion.bash t/t9902-completion.sh+19 -60 replies
13/21completion: don't offer commands when 'git --opt' needs an argumentcontrib/completion/git-completion.bash+11 -00 replies
14/21completion: fix completion after 'git -C <path>'contrib/completion/git-completion.bash t/t9902-completion.sh+10 -50 replies
15/21rev-parse: add '--absolute-git-dir' optionDocumentation/git-rev-parse.txt builtin/rev-parse.c t/t1500-rev-parse.sh+31 -160 replies
16/21completion: respect 'git -C <path>'contrib/completion/git-completion.bash t/t9902-completion.sh+101 -50 replies
17/21completion: don't use __gitdir() for git commandscontrib/completion/git-completion.bash+31 -295 replies
18/21completion: consolidate silencing errors from git commandscontrib/completion/git-completion.bash+12 -160 replies
19/21completion: don't guard git executions with __gitdir()contrib/completion/git-completion.bash+11 -210 replies
20/21completion: extract repository discovery from __gitdir()contrib/completion/git-completion.bash t/t9902-completion.sh+42 -220 replies
21/21completion: cache the path to the repositorycontrib/completion/git-completion.bash t/t9902-completion.sh+132 -750 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCHv2 00/21] completion: various __gitdir()-related improvements

This is a long overdue reroll of a bunch of bugfixes, cleanups and optimizations related to how the completion script finds the path to the repository and how it uses that path. Most importantly this series adds support for completion following 'git -C path', and it eliminates a few subshells and git processes, for the sake of fork()+exec() challenged OSes.

The first round is at [1]. It made its way to pu back then, but since the reroll didn't come it was eventually discarded.

What did NOT change since v1 is that the new option added to 'git rev-parse' is still called '--absolute-git-dir'. There was a suggestion [2] to turn it into an orthogonal '--absolute-dir' option that works with other path-querying options, too, but I really doubt it's worth it. In short, regular scripts don't care, because a relative path doesn't make any difference for them, and before we do this orthogonal thing we have to decide a bunch of questions first, see [3].

Changes since v1:

- Use our real_path() instead of system realpath() to implement 'git rev-parse --absolute-git-dir'.
- Refactored a bit how __git_refs() determines where it should list refs from.
- Renamed a few refnames and remote in the tests (this accounts for the bulk of the interdiff).
- Misc small adjustments: a few more comments, removed unnecessary disambiguating '--', typofix and more consistent quoting.
- Improved commit messages.
- Rebased to current master.

The interdiff below is compared to v1 rebased on top of current master.

This series is also available at

https://github.com/szeder/git completion-gitdir-improvements

[1] - http://public-inbox.org/git/[email protected]/T/

[2] - http://public-inbox.org/git/CANoM8SXO_Rz_CVOz9ptsaVCzcQ2D1FQrSuFFW4vZ4SdRYMzD=w@mail.gmail.com/

[3] - http://public-inbox.org/git/20160518185825.Horde.EPd2nJNvqEW_VX4b01yWdIr@webmail.informatik.kit.edu/

SZEDER Gábor (21):
completion: improve __git_refs()'s in-code documentation completion tests: don't add test cruft to the test repository completion tests: make the $cur variable local to the test helper
functions
completion tests: consolidate getting path of current working
directory
completion tests: check __gitdir()'s output in the error cases completion tests: add tests for the __git_refs() helper function
completion: ensure that the repository path given on the command line
exists
completion: fix most spots not respecting 'git --git-dir=<path>'
completion: respect 'git --git-dir=<path>' when listing remote refs
completion: list refs from remote when remote's name matches a
directory
completion: don't list 'HEAD' when trying refs completion outside of a
repo
completion: list short refs from a remote given as a URL
completion: don't offer commands when 'git --opt' needs an argument
completion: fix completion after 'git -C <path>'
rev-parse: add '--absolute-git-dir' option
completion: respect 'git -C <path>'
completion: don't use __gitdir() for git commands
completion: consolidate silencing errors from git commands
completion: don't guard git executions with __gitdir()
completion: extract repository discovery from __gitdir()
completion: cache the path to the repository

 Documentation/git-rev-parse.txt        |   4 +
 builtin/rev-parse.c                    |  26 +-
 contrib/completion/git-completion.bash | 250 ++++++++++-----
 t/t1500-rev-parse.sh                   |  17 +-
 t/t9902-completion.sh                  | 561 +++++++++++++++++++++++++++++----
 5 files changed, 690 insertions(+), 168 deletions(-)
Signature · 1 line
2.11.0.555.g967c1bcb3
builtin/rev-parse.c +1 -4
index 4040b3c86..1967bafba 100644
@@ -820,10 +820,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 					if (!gitdir && !prefix)
 						gitdir = ".git";
 					if (gitdir) {
-						char absolute_path[PATH_MAX];
-						if (!realpath(gitdir, absolute_path))
-							die_errno(_("unable to get absolute path"));
-						puts(absolute_path);
+						puts(real_path(gitdir));
 						continue;
 					}
 				}
contrib/completion/git-completion.bash +22 -22

97 lines not on this page · raw message

t/t9902-completion.sh +92 -77

312 lines not on this page · raw message