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

Re: What's cooking in git.git (Jun 2012, #01; Sun, 3)

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 10, 2012, 07:26 UTC
Message-ID
<7vmx4baaqc.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAMP44s2VGLj8kRih-95A0VDq86WKWHF3EhLvz0etyHHtP27qLA@mail.gmail.com>
Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 5 quoted lines
>> I did not see anything like these.
>
> Nor is it needed *right now*. You could release v1.7.11 without any of
> these, and then v1.7.11.1 or even v1.7.12 with a solution; I bet
> __gitdir() would not have changed by that point.

And by that time on whom are you placing the burden of making sure they do not diverge? Don't you still realize that you are being irresponsible?

In any case, I am tired of your arguing without being constructive, so let's try again. This is the third option I suggested to you.

Notice in the post context lines that they are already subtly different; one pays attention to $GIT_DIR, and the other does not. Shouldn't they be not just kept in sync, but start out in sync in the first place?

Aren't there other functions or variables that need to be kept in sync between these, by the way?

-- >8 --
Subject: completion: warn people about duplicated function

The __gitdir function is duplicated between completion and prompt scripts, and these definitions should not diverge; otherwise one of them can be subtly broken depending on the order the user's shell dot-sources them.

Leave a note to people who may want to touch one copy to make sure they update the other one in sync. Hopefully this line would also appear in the context of the patch to allow reviewers to notice a patch that attempts to update only one of them.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 contrib/completion/git-completion.bash | 2 ++
 contrib/completion/git-prompt.sh       | 2 ++
 2 files changed, 4 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index abf8215..efcd875 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -33,12 +33,14 @@ case "$COMP_WORDBREAKS" in
 esac
 
 # __gitdir accepts 0 or 1 arguments (i.e., location)
 # returns location of .git repo
 __gitdir ()
 {
+	# Note: this function is duplicated in git-prompt.sh
+	# When updating it, make sure you update the other one to match.
 	if [ -z "${1-}" ]; then
 		if [ -n "${__git_dir-}" ]; then
 			echo "$__git_dir"
 		elif [ -d .git ]; then
 			echo .git
 		else
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 8e2e9f3..29b1ec9 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -50,12 +50,14 @@
 # setting the bash.showUpstream config variable.
 
 # __gitdir accepts 0 or 1 arguments (i.e., location)
 # returns location of .git repo
 __gitdir ()
 {
+	# Note: this function is duplicated in git-completion.bash
+	# When updating it, make sure you update the other one to match.
 	if [ -z "${1-}" ]; then
 		if [ -n "${__git_dir-}" ]; then
 			echo "$__git_dir"
 		elif [ -n "${GIT_DIR-}" ]; then
 			test -d "${GIT_DIR-}" || return 1
 			echo "$GIT_DIR"
Previous: Felipe ContrerasNext: Felipe Contreras
Message 5 of 12 in “What's cooking in git.git (Jun 2012, #01; Sun, 3)”
  1. Junio C HamanoJun 4, 2012
  2. Felipe ContrerasJun 6, 2012
  3. Junio C HamanoJun 6, 2012
  4. Felipe ContrerasJun 6, 2012
  5. Junio C HamanoJun 10, 2012
  6. Felipe ContrerasJun 10, 2012
  7. Junio C HamanoJun 11, 2012
  8. Felipe ContrerasJun 13, 2012
  9. Junio C HamanoJun 13, 2012
  10. Felipe ContrerasJun 13, 2012
  11. René ScharfeJun 10, 2012
  12. Felipe ContrerasJun 11, 2012

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.