Skip to contentSkip to conversation

approxidate woes

DISCUSSION Andreas Krey 2 participants 3 messages Nov 15, 2018

lore
Share & tools
lore
#0 lore raw

Hi everybody,

I've now located why our backup repo shrinks every month:

  git gc --prune=2d

doesn't do what I expected, and differs a lot from --prune=48h.

The latter actually means 'older than two days', while the former is 'since the second day of this month, same time as now'.

Even '2d ago' does not help - '2 days ago' does.

Mildly irritating, and worse, hard to find in the documentation. I failed at the latter and fell back to the sources, finding './bin-wrappers/test-date approxidate' for trying.

Where would I look?

- Andreas

Signature · 3 lines
"Totally trivial. Famous last words."
From: Linus Torvalds <torvalds@*.org>
Date: Fri, 22 Jan 2010 07:29:21 -0800
#1 lore raw
Quoted 5 lines · Andreas Krey

I've now located why our backup repo shrinks every month:

  git gc --prune=2d

doesn't do what I expected, and differs a lot from --prune=48h.

Yeah, it understands "2 days", but not "d" as a unit.

I don't think "48h" does what you expect either:

  $ t/helper/test-date approxidate now
  now -> 2018-11-15 14:43:32 +0000
  $ t/helper/test-date approxidate 48h
  48h -> 2018-11-15 14:43:34 +0000
  $ t/helper/test-date approxidate 48.hours
  48.hours -> 2018-11-13 14:43:38 +0000

It might be reasonable to teach approxidate these obvious shorthands (one tricky one is "m"; normally I'd say "minute", but in Git timescales "month" is more likely).

Quoted 5 lines

Mildly irritating, and worse, hard to find in the documentation. I failed at the latter and fell back to the sources, finding './bin-wrappers/test-date approxidate' for trying.

Where would I look?

I don't think approxidate is really documented at all. It started as Linus's idea of "handle what people would probably say", and the fixes over the years have mostly been "eh, that's crazy, let's do better with this input".

You'd have to reverse engineer it a bit from the source, unfortunately.

-Peff

#2 lore raw
Quoted 10 lines · Jeff King

I don't think "48h" does what you expect either:

  $ t/helper/test-date approxidate now
  now -> 2018-11-15 14:43:32 +0000
  $ t/helper/test-date approxidate 48h
  48h -> 2018-11-15 14:43:34 +0000
  $ t/helper/test-date approxidate 48.hours
  48.hours -> 2018-11-13 14:43:38 +0000

Whoops, those should all be:

t/helper/test-tool date approxidate ...

in recent versions of Git (I was bisecting something earlier, and has a crufty test-date left over from an old version!).

Adding new unit aliases would be something like:

date.c +1 -0
index 9bc15df6f9..eb477d1601 100644
@@ -1016,6 +1016,7 @@ static const struct typelen {
 	{ "minutes", 60 },
 	{ "hours", 60*60 },
 	{ "days", 24*60*60 },
+	{ "d", 24*60*60 },
 	{ "weeks", 7*24*60*60 },
 	{ NULL }
 };

but I suspect we need to tighten up the string matching a bit. I think that would allow "2 dogs" to be parsed as "days".

-Peff