Michael Haggerty <mhag...@alum.mit.edu> writes:

> would be that it expires *everything*.  But in fact it seems to only
> expire things that are at least one second old, which doesn't seem at
> all useful in the real world.  "--expire=all" is accepted without
> complaint but doesn't do what one would hope.

Perhaps that is worth fixing, independent of this topic.

Approxidate gives the current time for anything it does not
understand, and that is how --expire=all is interpreted as "anything
older than now".  For that matter, even a string "now" has long been
interpreted as the current time with the same "I do not understand
it, so I'll give you the current timestamp" logic, until we added an
official support for "now" at 93cfa7c7a85e (approxidate_careful()
reports errorneous date string, 2010-01-26) for entirely different
reasons.

A completely untested patch for your enjoyment...

 builtin/reflog.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index 72a0af7..9fa0e41 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -492,15 +492,28 @@ static struct reflog_expire_cfg *find_cfg_ent(const char 
*pattern, size_t len)
        return ent;
 }
 
+static void parse_expire_value(const char *value, unsigned long *expire)
+{
+       if (!strcmp(value, "never") || !strcmp(value, "false"))
+               *expire = 0;
+       else if (!strcmp(value, "all") || !strcmp(value, "now"))
+               /*
+                * We take over "now" here, which usually translates
+                * to the current timestamp, because the user really
+                * means everything she has done in the past, and by
+                * definition reflogs are the record of the past,
+                * there is nothing from the future to be kept.
+                */
+               *expire = ULONG_MAX;
+       else
+               *expire = approxidate(value);
+}
+
 static int parse_expire_cfg_value(const char *var, const char *value, unsigned 
long *expire)
 {
        if (!value)
                return config_error_nonbool(var);
-       if (!strcmp(value, "never") || !strcmp(value, "false")) {
-               *expire = 0;
-               return 0;
-       }
-       *expire = approxidate(value);
+       parse_expire_value(value, expire);
        return 0;
 }
 
@@ -614,11 +627,11 @@ static int cmd_reflog_expire(int argc, const char **argv, 
const char *prefix)
                if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
                        cb.dry_run = 1;
                else if (!prefixcmp(arg, "--expire=")) {
-                       cb.expire_total = approxidate(arg + 9);
+                       parse_expire_value(arg + 9, &cb.expire_total);
                        explicit_expiry |= EXPIRE_TOTAL;
                }
                else if (!prefixcmp(arg, "--expire-unreachable=")) {
-                       cb.expire_unreachable = approxidate(arg + 21);
+                       parse_expire_value(arg + 21, &cb.expire_unreachable);
                        explicit_expiry |= EXPIRE_UNREACH;
                }
                else if (!strcmp(arg, "--stale-fix"))



--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to