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

[PATCH v2 11/13] for_each_reflog(): don't abort for bad references

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jun 3, 2016, 12:33 UTC
Message-ID
<2ef290baec6d7114e230ca09a3c59d09e6ade9aa.1464957077.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1464957077.git.mhagger@alum.mit.edu>

If there is a file under "$GIT_DIR/logs" with no corresponding reference, the old code was emitting an error message, aborting the reflog iteration, and returning -1. But

* None of the callers was checking the exit value
* The callers all want to find all legitimate reflogs (sometimes for the
  purpose of determining object reachability!) and wouldn't benefit from
  a truncated iteration anyway.

So instead, emit an error message and skip the "broken" reflog, but continue with the iteration.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs/files-backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index cd8c7ee..e8dd9d1 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3324,7 +3324,7 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data
 				struct object_id oid;
 
 				if (read_ref_full(name->buf, 0, oid.hash, NULL))
-					retval = error("bad ref for %s", name->buf);
+					error("bad ref for %s", name->buf);
 				else
 					retval = fn(name->buf, &oid, 0, cb_data);
 			}
-- 
2.8.1
Previous: Michael HaggertyNext: Michael Haggerty
Message 12 of 23 in “Reference iterators”
  1. 00/13 Reference iteratorsMichael Haggerty, Jun 3, 2016
  2. 01/13 refs: remove unnecessary "extern" keywordsMichael Haggerty, Jun 3, 2016
  3. 02/13 do_for_each_ref(): move docstring to the header fileMichael Haggerty, Jun 3, 2016
  4. 03/13 refs: use name "prefix" consistentlyMichael Haggerty, Jun 3, 2016
  5. 04/13 delete_refs(): add a flags argumentMichael Haggerty, Jun 3, 2016
  6. 05/13 remote rm: handle symbolic refs correctlyMichael Haggerty, Jun 3, 2016
  7. 06/13 get_ref_cache(): only create an instance if there is a submoduleMichael Haggerty, Jun 3, 2016
  8. 07/13 entry_resolves_to_object(): rename function from ref_resolves_to_object()Michael Haggerty, Jun 3, 2016
  9. 08/13 ref_resolves_to_object(): new functionMichael Haggerty, Jun 3, 2016
  10. 09/13 refs: introduce an iterator interfaceMichael Haggerty, Jun 3, 2016
  11. 10/13 do_for_each_ref(): reimplement using reference iterationMichael Haggerty, Jun 3, 2016
  12. 11/13 for_each_reflog(): don't abort for bad referencesMichael Haggerty, Jun 3, 2016
  13. 12/13 dir_iterator: new API for iterating over a directory treeMichael Haggerty, Jun 3, 2016
  14. Eric SunshineJun 7, 2016
  15. Michael HaggertyJun 9, 2016
  16. Michael HaggertyJun 9, 2016
  17. Junio C HamanoJun 9, 2016
  18. 13/13 for_each_reflog(): reimplement using iteratorsMichael Haggerty, Jun 3, 2016
  19. David TurnerJun 3, 2016
  20. Junio C HamanoJun 3, 2016
  21. Michael HaggertyJun 3, 2016
  22. Junio C HamanoJun 3, 2016
  23. Michael HaggertyJun 7, 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.