git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* How can I tell if anything was fetched?
@ 2012-10-11 16:25 Phil Lawrence
  2012-10-11 16:45 ` Andreas Schwab
  2012-10-12  6:28 ` Johannes Sixt
  0 siblings, 2 replies; 5+ messages in thread
From: Phil Lawrence @ 2012-10-11 16:25 UTC (permalink / raw
  To: git

I have a cron job that regularly fetches into a bare repo.  Currently,
the job then pushes the repo to another remote, regardless of whether
or not anything was actually fetched.  That's a waste.

What is the best way to know whether or not anything was received
during the fetch?  I don't want to be stuck trying to parse the answer
out of STDOUT and STDERR...

One approach might be to first generate a state-of-the-repo SHA1:
    # http://stackoverflow.com/a/7350019/834039
    # http://git-scm.com/book/ch9-2.html
    {
        git rev-list --objects --all
        git rev-list --objects -g --no-walk --all
        git rev-list --objects --no-walk \
            $(git fsck --unreachable |
              grep '^unreachable commit' |
              cut -d' ' -f3)
    } | sort | uniq | git hash-object -w --stdin

I could then do the git fetch, generate another state-of-the-repo SHA1
and compare...

Thoughts?

--
Phil Lawrence

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

* Re: How can I tell if anything was fetched?
  2012-10-11 16:25 How can I tell if anything was fetched? Phil Lawrence
@ 2012-10-11 16:45 ` Andreas Schwab
  2012-10-11 18:29   ` Enrico Weigelt
  2012-10-12  7:47   ` Jeff King
  2012-10-12  6:28 ` Johannes Sixt
  1 sibling, 2 replies; 5+ messages in thread
From: Andreas Schwab @ 2012-10-11 16:45 UTC (permalink / raw
  To: Phil Lawrence; +Cc: git

Phil Lawrence <prlawrence@gmail.com> writes:

> One approach might be to first generate a state-of-the-repo SHA1:
>     # http://stackoverflow.com/a/7350019/834039
>     # http://git-scm.com/book/ch9-2.html
>     {
>         git rev-list --objects --all
>         git rev-list --objects -g --no-walk --all
>         git rev-list --objects --no-walk \
>             $(git fsck --unreachable |
>               grep '^unreachable commit' |
>               cut -d' ' -f3)
>     } | sort | uniq | git hash-object -w --stdin

I think you'd only need to record the state of all refs (eg. the output
of `git for-each-ref') to reliably detect any changes.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: How can I tell if anything was fetched?
  2012-10-11 16:45 ` Andreas Schwab
@ 2012-10-11 18:29   ` Enrico Weigelt
  2012-10-12  7:47   ` Jeff King
  1 sibling, 0 replies; 5+ messages in thread
From: Enrico Weigelt @ 2012-10-11 18:29 UTC (permalink / raw
  To: Andreas Schwab; +Cc: git, Phil Lawrence


> I think you'd only need to record the state of all refs (eg. the
> output
> of `git for-each-ref') to reliably detect any changes.

I would just record the output of `git ls-remote . | sort -u` somewhere
and compare it next time (maybe you even wanna grep for the desired
ref namespaces).


cu
-- 
Mit freundlichen Grüßen / Kind regards 

Enrico Weigelt 
VNC - Virtual Network Consult GmbH 
Head Of Development 

Pariser Platz 4a, D-10117 Berlin
Tel.: +49 (30) 3464615-20
Fax: +49 (30) 3464615-59

enrico.weigelt@vnc.biz; www.vnc.de 

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

* Re: How can I tell if anything was fetched?
  2012-10-11 16:25 How can I tell if anything was fetched? Phil Lawrence
  2012-10-11 16:45 ` Andreas Schwab
@ 2012-10-12  6:28 ` Johannes Sixt
  1 sibling, 0 replies; 5+ messages in thread
From: Johannes Sixt @ 2012-10-12  6:28 UTC (permalink / raw
  To: Phil Lawrence; +Cc: git

Am 10/11/2012 18:25, schrieb Phil Lawrence:
> What is the best way to know whether or not anything was received
> during the fetch?  I don't want to be stuck trying to parse the answer
> out of STDOUT and STDERR...

what="--all"	 # or "--remotes=the-remote"
presha1s=$(git rev-parse $what)
git fetch the-remote
if test -z "$(git rev-list -1 $what --not $presha1s)"
then
	echo nothing new
fi

Error checking is left as an exercise for the user ;)

-- Hannes

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

* Re: How can I tell if anything was fetched?
  2012-10-11 16:45 ` Andreas Schwab
  2012-10-11 18:29   ` Enrico Weigelt
@ 2012-10-12  7:47   ` Jeff King
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff King @ 2012-10-12  7:47 UTC (permalink / raw
  To: Andreas Schwab; +Cc: Phil Lawrence, git

On Thu, Oct 11, 2012 at 06:45:09PM +0200, Andreas Schwab wrote:

> Phil Lawrence <prlawrence@gmail.com> writes:
> 
> > One approach might be to first generate a state-of-the-repo SHA1:
> >     # http://stackoverflow.com/a/7350019/834039
> >     # http://git-scm.com/book/ch9-2.html
> >     {
> >         git rev-list --objects --all
> >         git rev-list --objects -g --no-walk --all
> >         git rev-list --objects --no-walk \
> >             $(git fsck --unreachable |
> >               grep '^unreachable commit' |
> >               cut -d' ' -f3)
> >     } | sort | uniq | git hash-object -w --stdin
> 
> I think you'd only need to record the state of all refs (eg. the output
> of `git for-each-ref') to reliably detect any changes.

To clarify on the "only" in your sentence: it is not just that recording
the ref changes is more efficient. But recording the object state is
actively wrong. You might have fetched ref changes that do not introduce
new objects (e.g., a rewind of history, or a branch deletion). The
before-and-after ref state is both sufficient and necessary.  I suspect
you already realized that, Andreas, but I wanted to make sure it was
clear to readers, including the OP.

Checking ref state does suffer from potential race conditions with any
other simultaneous updates.  I don't think there is any reason we
couldn't have "git fetch" produce a machine-readable output detailing
what happened. We already have the same for "git push". I think it is
simply the case that nobody has really wanted it so far.

-Peff

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

end of thread, other threads:[~2012-10-12  7:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-11 16:25 How can I tell if anything was fetched? Phil Lawrence
2012-10-11 16:45 ` Andreas Schwab
2012-10-11 18:29   ` Enrico Weigelt
2012-10-12  7:47   ` Jeff King
2012-10-12  6:28 ` Johannes Sixt

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).