All of lore.kernel.org
 help / color / mirror / Atom feed
* How to determine age of HEAD commit
@ 2019-12-08 12:09 Philip Oakley
  2019-12-08 14:07 ` Roger Gammans
  0 siblings, 1 reply; 3+ messages in thread
From: Philip Oakley @ 2019-12-08 12:09 UTC (permalink / raw)
  To: Git List

The Visual Studio git solution uses the vcpkg manager for dependencies, 
via a cloned git repo.

To avoid repeated probing for updates when compiling, I considered 
holding of on 'git pull' for the repo for say 24 hours (daily update). 
However I'm not aware of a git command that returns the numeric value of 
the agedness of a given local commit (typically HEAD).

Is there a command that does return the numeric agedness of a commit 
(e.g. now - commit_date, in seconds)?
-- 
Philip


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

* Re: How to determine age of HEAD commit
  2019-12-08 12:09 How to determine age of HEAD commit Philip Oakley
@ 2019-12-08 14:07 ` Roger Gammans
  2019-12-08 15:05   ` Philip Oakley
  0 siblings, 1 reply; 3+ messages in thread
From: Roger Gammans @ 2019-12-08 14:07 UTC (permalink / raw)
  To: Philip Oakley, Git List

On Sun, 2019-12-08 at 12:09 +0000, Philip Oakley wrote:
> Is there a command that does return the numeric agedness of a commit 
> (e.g. now - commit_date, in seconds)?

Hi

I don't know a specific command for the age. But `git cat-file commit
HEAD`, will give you the commit's timestamps in seconds from the the
epoch. (Plus some timezone info).

I can construct a bash script, shown below (warning: only had the most 
rudimentary testing), which turns that into an age. For your use case
you might be better getting yesterdays unix-timestamp from date, if GNU
date is available, and directly comparing it to the commit timestamp.

------
#!/bin/bash

now=$(date +"%s")
commit=$(git cat-file commit HEAD | grep committer)
commit=${commit##*>}
commit=${commit%%+*}
echo $(( $now-$commit ))
#--------------

-- 
Roger Gammans <rgammans@gammascience.co.uk>


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

* Re: How to determine age of HEAD commit
  2019-12-08 14:07 ` Roger Gammans
@ 2019-12-08 15:05   ` Philip Oakley
  0 siblings, 0 replies; 3+ messages in thread
From: Philip Oakley @ 2019-12-08 15:05 UTC (permalink / raw)
  To: Roger Gammans, Git List

Hi Roger,

On 08/12/2019 14:07, Roger Gammans wrote:
> On Sun, 2019-12-08 at 12:09 +0000, Philip Oakley wrote:
>> Is there a command that does return the numeric agedness of a commit
>> (e.g. now - commit_date, in seconds)?
> Hi
>
> I don't know a specific command for the age. But `git cat-file commit
> HEAD`, will give you the commit's timestamps in seconds from the the
> epoch. (Plus some timezone info).
>
> I can construct a bash script, shown below (warning: only had the most
> rudimentary testing), which turns that into an age. For your use case
> you might be better getting yesterdays unix-timestamp from date, if GNU
> date is available, and directly comparing it to the commit timestamp.
>
> ------
> #!/bin/bash
>
> now=$(date +"%s")
> commit=$(git cat-file commit HEAD | grep committer)
> commit=${commit##*>}
> commit=${commit%%+*}
> echo $(( $now-$commit ))
> #--------------
>
Thanks,
That has spurred me into looking at a few other ideas.
Unfortunately the script needs to run inside a DOS batch file as part of 
a Visual Studio pre-build step, hence the desire for a direct command.

That said I have now found, with a bit of rooting around, that

    `git log -1 --format=format:"%ct" HEAD`

does appear to give the right form of answer. Just need to see if I can 
fit it into the DOS pre-build script now ;-)
There may be extra tweaks needed.. (a merged pull has the pull date, but 
a fast forward pull has the original date)

Philip

Philip

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

end of thread, other threads:[~2019-12-08 15:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-08 12:09 How to determine age of HEAD commit Philip Oakley
2019-12-08 14:07 ` Roger Gammans
2019-12-08 15:05   ` Philip Oakley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.