git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [QUESTION]: How to get uploading git objects via a git command in a pre-receive-hook
@ 2024-06-29 14:42 ZheNing Hu
  2024-06-29 16:29 ` Christian Couder
  0 siblings, 1 reply; 3+ messages in thread
From: ZheNing Hu @ 2024-06-29 14:42 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Taylor Blau

Hi,

I want to check the uploaded Git LFS objects in the pre-receive hook
of the Git server. Assuming that the Git repository during the upload
process is A.git, my current approach is to create an empty repository
B.git and then use
GIT_ALTERNATE_OBJECT_DIRECTORIES="A.git/objects/tmp_objdir-incoming-**"
followed by executing git -C B.git cat-file --batch-check
--batch-all-objects to obtain the objects being uploaded, then filter
out the LFS objects. This process is very time-consuming, taking
roughly more than 10 seconds. I wonder if there's a simpler method?


Thanks.
--
ZheNing Hu

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [QUESTION]: How to get uploading git objects via a git command in a pre-receive-hook
  2024-06-29 14:42 [QUESTION]: How to get uploading git objects via a git command in a pre-receive-hook ZheNing Hu
@ 2024-06-29 16:29 ` Christian Couder
  2024-07-01  3:40   ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Couder @ 2024-06-29 16:29 UTC (permalink / raw)
  To: ZheNing Hu; +Cc: Git List, Junio C Hamano, Taylor Blau

Hi ZheNing,

On Sat, Jun 29, 2024 at 4:42 PM ZheNing Hu <adlternative@gmail.com> wrote:
>
> Hi,
>
> I want to check the uploaded Git LFS objects in the pre-receive hook
> of the Git server. Assuming that the Git repository during the upload
> process is A.git, my current approach is to create an empty repository
> B.git and then use
> GIT_ALTERNATE_OBJECT_DIRECTORIES="A.git/objects/tmp_objdir-incoming-**"
> followed by executing git -C B.git cat-file --batch-check
> --batch-all-objects to obtain the objects being uploaded, then filter
> out the LFS objects. This process is very time-consuming, taking
> roughly more than 10 seconds. I wonder if there's a simpler method?

I wonder if it's possible to use `git verify-pack --verbose` on the
received packfile.

Best,
Christian.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [QUESTION]: How to get uploading git objects via a git command in a pre-receive-hook
  2024-06-29 16:29 ` Christian Couder
@ 2024-07-01  3:40   ` Jeff King
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff King @ 2024-07-01  3:40 UTC (permalink / raw)
  To: Christian Couder; +Cc: ZheNing Hu, Git List, Junio C Hamano, Taylor Blau

On Sat, Jun 29, 2024 at 06:29:41PM +0200, Christian Couder wrote:

> > I want to check the uploaded Git LFS objects in the pre-receive hook
> > of the Git server. Assuming that the Git repository during the upload
> > process is A.git, my current approach is to create an empty repository
> > B.git and then use
> > GIT_ALTERNATE_OBJECT_DIRECTORIES="A.git/objects/tmp_objdir-incoming-**"
> > followed by executing git -C B.git cat-file --batch-check
> > --batch-all-objects to obtain the objects being uploaded, then filter
> > out the LFS objects. This process is very time-consuming, taking
> > roughly more than 10 seconds. I wonder if there's a simpler method?
> 
> I wonder if it's possible to use `git verify-pack --verbose` on the
> received packfile.

By the time the pre-receive hook is running, we've indexed the pack. So
you can just find the pack in the tmpdir (via GIT_QUARANTINE_PATH) and
run "git show-index" against it, which is much faster. Keeping in mind
that the pack could also have been exploded to loose objects if it's
small, in which case you'd need to use "find" or similar to enumerate
the loose object files.

In theory you could use "cat-file --batch-all-objects", but I suspect
the reason it takes a long time is that it has access to all of the
original objects in the repo, too (and so is enumerating those). You
might be able to get away with unsetting various GIT_* variables to
avoid that, but I think the result would be kind of fragile.

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-01  3:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-29 14:42 [QUESTION]: How to get uploading git objects via a git command in a pre-receive-hook ZheNing Hu
2024-06-29 16:29 ` Christian Couder
2024-07-01  3:40   ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).