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

Re: [PATCH v2 14/22] i18n: rebase-interactive: mark strings for translation

From
Junio C Hamano <gitster@pobox.com>
Date
May 27, 2016, 16:58 UTC
Message-ID
<xmqqk2ifsajn.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<57481CA0.5080801@sapo.pt>
Vasco Almeida <vascomalmeida@sapo.pt> writes:
Show 21 quoted lines
>>>  is_empty_commit() {
>>> -	tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null ||
>>> -		die "$1: not a commit that can be picked")
>>> -	ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null ||
>>> +	sha1=$1
>>> +	tree=$(git rev-parse -q --verify "$sha1"^{tree} 2>/dev/null ||
>>> +		die "$(eval_gettext "\$sha1: not a commit that can be picked")")
>>> +	ptree=$(git rev-parse -q --verify "$sha1"^^{tree} 2>/dev/null ||
>>>  		ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904)
>>>  	test "$tree" = "$ptree"
>>>  }
>> 
>> Both of the two callsites of this function use the variable $sha1,
>> and at least one of them uses that variable after this function
>> returns, but they pass it as the first parameter to this function,
>> so the assignment added by this patch does not break them, which is
>> good.
>> 
> I didn't know that. I can change sha1=$1 to local_sha1=$1 or _sha1=$1 (I
> don't know what is the convention here) if that is safer, avoiding using
> the bash-ism "local" keyword, and preventing future distractions.

I do not think it is necessary to do any of the changes for this one, which is only used locally in this file. They just need to be careful when they add or modify the callers.

Even if it is renamed $local_sha1, they will still need to be careful anyway, because the only way they _can_ break or be broken by your patch is when they somehow decide to pass something that is not called $sha1 to this function, i.e. they would be changing the callsite---which they must be doing for a reason and would also involve change to the code what happens after this function returns. If they start using $local_sha1 there, they would be broken if you renamed it today, and if they use $sha1 there, they would be broken if you didn't---so they have to be careful and check what this one clobbers _anyway_.

IOW, a solution that clobbers _some_ variable cannot be made safer by renaming. The callers always have to be careful not to be affected.

You could do something like this, though. I _think_ the original that calls "die" inside $() is broken anyway, so it probably is a good change regardless.

 git-rebase--interactive.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 9d2bfb7..b5113d6 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -222,8 +222,10 @@ has_action () {
 }
 
 is_empty_commit() {
-	tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null ||
-		die "$1: not a commit that can be picked")
+	tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null) || {
+		sha1=$1
+		die "$(eval_gettext "\$sha1: not a commit that can be picked")"
+	}
 	ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null ||
 		ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904)
 	test "$tree" = "$ptree"
Previous: Vasco AlmeidaNext: Vasco Almeida
Message 21 of 38 in “i18n and test updates”
  1. 00/22 i18n and test updatesVasco Almeida, May 23, 2016
  2. 01/22 i18n: builtin/remote.c: fix mark for translationVasco Almeida, May 23, 2016
  3. 02/22 i18n: advice: mark string about detached head for translationVasco Almeida, May 23, 2016
  4. Vasco AlmeidaMay 30, 2016
  5. 03/22 i18n: advice: internationalize message for conflictsVasco Almeida, May 23, 2016
  6. 04/22 i18n: transport: mark strings for translationVasco Almeida, May 23, 2016
  7. 05/22 i18n: sequencer: mark entire sentences for translationVasco Almeida, May 23, 2016
  8. 06/22 i18n: sequencer: mark string for translationVasco Almeida, May 23, 2016
  9. 07/22 i18n: merge-octopus: mark messages for translationVasco Almeida, May 23, 2016
  10. 08/22 merge-octupus: use die shell function from git-sh-setup.shVasco Almeida, May 23, 2016
  11. 09/22 i18n: rebase: fix marked string to use eval_gettext variantVasco Almeida, May 23, 2016
  12. 10/22 i18n: rebase: mark placeholder for translationVasco Almeida, May 23, 2016
  13. 11/22 i18n: bisect: simplify error message for i18nVasco Almeida, May 23, 2016
  14. 12/22 t6030: update to use test_i18ncmpVasco Almeida, May 23, 2016
  15. 13/22 i18n: git-sh-setup.sh: mark strings for translationVasco Almeida, May 23, 2016
  16. Junio C HamanoMay 26, 2016
  17. Vasco AlmeidaMay 27, 2016
  18. 14/22 i18n: rebase-interactive: mark strings for translationVasco Almeida, May 23, 2016
  19. Junio C HamanoMay 26, 2016
  20. Vasco AlmeidaMay 27, 2016
  21. Junio C HamanoMay 27, 2016
  22. 15/22 i18n: rebase-interactive: mark here-doc strings for translationVasco Almeida, May 23, 2016
  23. Vasco AlmeidaMay 25, 2016
  24. 16/22 i18n: rebase-interactive: mark comments of squash for translationVasco Almeida, May 23, 2016
  25. Junio C HamanoMay 26, 2016
  26. Vasco AlmeidaMay 27, 2016
  27. 17/22 i18n: setup: mark strings for translationVasco Almeida, May 23, 2016
  28. 18/22 tests: use test_i18n* functions to suppress false positivesVasco Almeida, May 23, 2016
  29. Junio C HamanoMay 27, 2016
  30. Vasco AlmeidaMay 27, 2016
  31. Junio C HamanoMay 27, 2016
  32. 19/22 tests: unpack-trees: update to use test_i18n* functionsVasco Almeida, May 23, 2016
  33. 20/22 t9003: become resilient to GETTEXT_POISONVasco Almeida, May 23, 2016
  34. 21/22 t4153: fix negated test_i18ngrep callVasco Almeida, May 23, 2016
  35. 22/22 t5523: use test_i18ngrep for negationVasco Almeida, May 23, 2016
  36. Junio C HamanoMay 27, 2016
  37. Vasco AlmeidaMay 28, 2016
  38. Junio C HamanoMay 30, 2016

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.