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

Add support for negative refs

From
Linus Torvalds <torvalds@osdl.org>
Date
Sep 12, 2006, 03:10 UTC
Message-ID
<Pine.LNX.4.64.0609112008500.27779@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0609111632050.27779@g5.osdl.org>

You can remove a ref that is packed two different ways: either simply repack all the refs without that one, or create a loose ref that has the magic all-zero SHA1.

This also adds back the test that a ref actually has the object it points to.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
This one is trivial, and obviously depends on the previous series.

I'm sending it just because I have a much bigger cleanup that I'd _really_ like to go in, and I did this trivial one before that much more interesting one.

diff --git a/refs.c b/refs.c
index 5f80a68..72e2283 100644
--- a/refs.c
+++ b/refs.c
@@ -280,6 +280,12 @@ static int do_for_each_ref(const char *b
 		}
 		if (strncmp(base, entry->name, trim))
 			continue;
+		if (is_null_sha1(entry->sha1))
+			continue;
+		if (!has_sha1_file(entry->sha1)) {
+			error("%s does not point to a valid object!", entry->name);
+			continue;
+		}
 		retval = fn(entry->name + trim, entry->sha1);
 		if (retval)
 			return retval;
Previous: Chris WedgwoodNext: Linus Torvalds
Message 7 of 21 in “Allow multiple "git_path()" uses”
  1. Linus TorvaldsSep 11, 2006
  2. Start handling references internally as a sorted in-memory listLinus Torvalds, Sep 11, 2006
  3. Linus TorvaldsSep 11, 2006
  4. Junio C HamanoSep 11, 2006
  5. Linus TorvaldsSep 12, 2006
  6. Chris WedgwoodSep 12, 2006
  7. Add support for negative refsLinus Torvalds, Sep 12, 2006
  8. Make ref resolution sanerLinus Torvalds, Sep 12, 2006
  9. Jeff KingSep 12, 2006
  10. Linus TorvaldsSep 12, 2006
  11. [RFC] git-pack-refs --pruneJunio C Hamano, Sep 18, 2006
  12. Linus TorvaldsSep 18, 2006
  13. Junio C HamanoSep 18, 2006
  14. Junio C HamanoSep 21, 2006
  15. 1/5 symbolit-ref: fix resolve_ref conversion.Junio C Hamano, Sep 21, 2006
  16. 2/5 Add callback data to for_each_ref() family.Junio C Hamano, Sep 21, 2006
  17. 3/5 Tell between packed, unpacked and symbolic refs.Junio C Hamano, Sep 21, 2006
  18. 4/5 pack-refs: do not pack symbolic refs.Junio C Hamano, Sep 21, 2006
  19. 5/5 git-pack-refs --pruneJunio C Hamano, Sep 21, 2006
  20. Linus TorvaldsSep 21, 2006
  21. Junio C HamanoSep 22, 2006

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.