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

Re: [PATCH 1/8] am: suppress error output from a conditional

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
May 11, 2013, 23:38 UTC
Message-ID
<CALkWK0mtJU_fWK7A2BXN3f5VRT4Qh69PE0nfQaTJ6GU1Z5=wig@mail.gmail.com>
In-Reply-To
<7vhaia51vh.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
> If you are introducing "dotest exists but next/last may not be
> present" as a valid new state, it probably should check the presence
> and/or absence of them explicitly,

Um, a test -f preceding the cat? Why, when cat implicitly checks existence anyway?

> but more importantly, it is a
> good idea to move "test $# != 0" higher.
This?
diff --git a/git-am.sh b/git-am.sh
index 47c1021..1e10e31 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -446,9 +446,9 @@ done
 # If the dotest directory exists, but we have finished applying all the
 # patches in them, clear it out.
 if test -d "$dotest" &&
+   test $# != 0 &&
    last=$(cat "$dotest/last" 2>/dev/null) &&
    next=$(cat "$dotest/next" 2>/dev/null) &&
-   test $# != 0 &&
    test "$next" -gt "$last"
 then
    rm -fr "$dotest"

> Earlier it did not matter
> because when $dotest existed, next/last were supposed to be there
> and absence of them was an error codepath. Now, missing these files
> is not an error but is a perfectly normal state,

It's not a "normal state" for the purposes of git-am.sh.  There is no
codepath in the program that depends only on $dotest, but not
next/last.  I would frame this as: "checking for $dotest is not a
sufficient prerequisite anymore; we have to additionally look for
next/last".  To git-am.sh, an empty $dotest or just a
$dotest/autostash is equivalent to no $dotest at all.

> so checking what
> can be checked more cheaply makes sense as a general code hygiene.

Yeah, I agree.  See "am: tighten a conditional that checks for
$dotest", where I get away with just checking $dotest/last (and assume
that $dotest/next is present by extension).  How do I apply your
suggestion to this particular patch?
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 18 in “rebase.autostash completed”
  1. 0/8 rebase.autostash completedRamkumar Ramachandra, May 10, 2013
  2. 1/8 am: suppress error output from a conditionalRamkumar Ramachandra, May 10, 2013
  3. Junio C HamanoMay 10, 2013
  4. Ramkumar RamachandraMay 11, 2013
  5. Junio C HamanoMay 12, 2013
  6. 2/8 rebase -i: don't error out if $state_dir already existsRamkumar Ramachandra, May 10, 2013
  7. 3/8 am: tighten a conditional that checks for $dotestRamkumar Ramachandra, May 10, 2013
  8. 4/8 rebase: prepare to do generic housekeepingRamkumar Ramachandra, May 10, 2013
  9. Eric SunshineMay 10, 2013
  10. Junio C HamanoMay 10, 2013
  11. Junio C HamanoMay 10, 2013
  12. Ramkumar RamachandraMay 10, 2013
  13. 5/8 am: return control to caller, for housekeepingRamkumar Ramachandra, May 10, 2013
  14. 6/8 rebase -i: return control to caller, for housekeepingRamkumar Ramachandra, May 10, 2013
  15. 7/8 rebase --merge: return control to caller, for housekeepingRamkumar Ramachandra, May 10, 2013
  16. 8/8 rebase: implement --[no-]autostash and rebase.autostashRamkumar Ramachandra, May 10, 2013
  17. Eric SunshineMay 10, 2013
  18. Junio C HamanoMay 10, 2013

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.