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

Re: [PATCH 4/6] receive-pack: quarantine objects until pre-receive accepts

From
Jeff King <peff@peff.net>
Date
Apr 10, 2017, 21:14 UTC
Message-ID
<20170410211424.226psdn7ra3sb3mv@sigill.intra.peff.net>
In-Reply-To
<CACBZZX7Rt4zLGk=iy_Z9+8M-xUexwYA060R-v0nvseY7g+zA0w@mail.gmail.com>
On Sat, Apr 08, 2017 at 04:53:38PM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 11 quoted lines
> Very late reply, but I have a question about this. Is there anything
> you can do on the plumbing level to figure out which area an object is
> in (of course that's not mutually exclusive).
> 
> The use-case for that is e.g. having a hook that rejects large
> binaries, but has an exception for a binary that's been added in the
> past, before your change there's no optimal way to find that out,
> you'd need to go over the whole history and list all blobs that have
> ever been added, with your change it would be trivial if something
> could give me "this object is in the quarantine area", but AFAICT
> there's no API that'll show me that.

No, I don't think there's a way to ask that. The best API to add it to would probably be "cat-file --batch-check", which can tell you similar things about the on-disk storage, like "is it a delta? against what?" and the on-disk size.

_But_. Like those other things, it would have the big caveat that the object may appear multiple times. So if somebody sent you an object that was a duplicate of an existing one, you may or may not see it as being in the quarantine directory.

I think a better rule for hooks is to complain about history which introduces new references to problematic objects. IOW, instead of looking at the object database, actually see what the history introduces:

  while read old new refname; do
	echo "$new"
	if test "$old" != 0000000000000000000000000000000000000000; then
		echo "^$old"
	fi
  done |
  git rev-list --objects --stdin |
  while read sha1 fn; do
    # various object checks against $sha1
  done

However, if large binaries are your interest, I will suggest one other thing: it's much cheaper to find them during index-pack, rather than by traversing history. At GitHub we run with a patch to index-pack that dumps the sha1s of any large blobs into .large-objects in the quarantine directory. You can abort there, of course, but it's hard to produce a implement any other policy or produce a nice message. But if you just note them and leave it to the pre-receive hook, then that hook can do the traversal to find, e.g., which pathnames reference the large blobs. And it only has to run at all when we know there's at least one such blob (and it can quit immediately when it finds it).

I can share those patches, but they need some cleanup to be ready for inclusion.

> Also, I think this whole thing could really do with some documentation
> in githooks(5). E.g. what hooks does it apply for? The test is just
> for pre-receive but the patch changes run_update_hook(), does it also
> take effect for update? Ditto the caveat about update-ref.

My thinking was that the cases where the effects were user-visible were sufficiently insane that nobody would need to know or care when the feature was in use.

It isn't in use for the update hook. It can't be, because that is run per-ref. So the objects need to be pulled out of the quarantine before the first ref is updated (I think the call in run_update_hook is leftover cruft from before I realized that; it should be a noop because we'll always have migrated the objects by then, and tmp_objdir_env() will just return NULL).

-Peff
Previous: Ævar Arnfjörð BjarmasonNext: Jeff King
Message 17 of 32 in “receive-pack: quarantine pushed objects”
  1. 0/6 receive-pack: quarantine pushed objectsJeff King, Sep 30, 2016
  2. 1/6 check_connected: accept an env argumentJeff King, Sep 30, 2016
  3. 2/6 sha1_file: always allow relative paths to alternatesJeff King, Sep 30, 2016
  4. René ScharfeOct 2, 2016
  5. Jeff KingOct 2, 2016
  6. Jeff KingOct 2, 2016
  7. Jeff KingOct 2, 2016
  8. 3/6 tmp-objdir: introduce API for temporary object directoriesJeff King, Sep 30, 2016
  9. Junio C HamanoSep 30, 2016
  10. Jeff KingSep 30, 2016
  11. David TurnerSep 30, 2016
  12. Jeff KingSep 30, 2016
  13. David TurnerSep 30, 2016
  14. 4/6 receive-pack: quarantine objects until pre-receive acceptsJeff King, Sep 30, 2016
  15. Jeff KingOct 1, 2016
  16. Ævar Arnfjörð BjarmasonApr 8, 2017
  17. Jeff KingApr 10, 2017
  18. 5/6 tmp-objdir: put quarantine information in the environmentJeff King, Sep 30, 2016
  19. 6/6 tmp-objdir: do not migrate files starting with '.'Jeff King, Sep 30, 2016
  20. Christian CouderOct 2, 2016
  21. Jeff KingOct 2, 2016
  22. Christian CouderOct 3, 2016
  23. 0/5 receive-pack: quarantine pushed objectsJeff King, Oct 3, 2016
  24. 1/5 check_connected: accept an env argumentJeff King, Oct 3, 2016
  25. Jakub NarębskiOct 5, 2016
  26. Jeff KingOct 5, 2016
  27. 2/5 tmp-objdir: introduce API for temporary object directoriesJeff King, Oct 3, 2016
  28. 3/5 receive-pack: quarantine objects until pre-receive acceptsJeff King, Oct 3, 2016
  29. 5/5 tmp-objdir: do not migrate files starting with '.'Jeff King, Oct 3, 2016
  30. 4/5 tmp-objdir: put quarantine information in the environmentJeff King, Oct 3, 2016
  31. Junio C HamanoOct 3, 2016
  32. Jeff KingOct 3, 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.