From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Simpkins Subject: [PATCH 3/3] clean up parsing of expiration dates Date: Fri, 26 Feb 2010 19:50:04 -0800 Message-ID: <1267242604-5215-3-git-send-email-simpkins@facebook.com> References: <20100227012130.GA28452@facebook.com> <1267242604-5215-1-git-send-email-simpkins@facebook.com> <1267242604-5215-2-git-send-email-simpkins@facebook.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Adam Simpkins To: , X-From: git-owner@vger.kernel.org Sat Feb 27 04:52:20 2010 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NlDj1-0001L5-AC for gcvg-git-2@lo.gmane.org; Sat, 27 Feb 2010 04:52:19 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967766Ab0B0DwL (ORCPT ); Fri, 26 Feb 2010 22:52:11 -0500 Received: from mailout-snc1.facebook.com ([69.63.179.25]:50255 "EHLO mailout-snc1.facebook.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967761Ab0B0DwJ (ORCPT ); Fri, 26 Feb 2010 22:52:09 -0500 Received: from mail.thefacebook.com ([192.168.18.83]) by pp01.snc1.tfbnw.net (8.14.3/8.14.3) with ESMTP id o1R3paEL004077 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT); Fri, 26 Feb 2010 19:51:39 -0800 Received: from simpkins (192.168.18.252) by mail.TheFacebook.com (192.168.18.83) with Microsoft SMTP Server (TLS) id 8.2.213.0; Fri, 26 Feb 2010 19:50:39 -0800 Received: from simpkins by simpkins with local (Exim 4.69) (envelope-from ) id 1NlDhP-0001N1-OY; Fri, 26 Feb 2010 19:50:39 -0800 X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1267242604-5215-2-git-send-email-simpkins@facebook.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=1.12.8161:2.4.5,1.2.40,4.0.166 definitions=2010-02-27_02:2010-02-06,2010-02-27,2010-02-26 signatures=0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: The gc, prune, and reflog command all take arguments that control expiring of old objects/log entries. This cleans up the parsing of these arguments, and centralizes the logic so the commands behave consistently. Two new functions have been added for parsing expiration dates: parse_expire_date() is similar to approxidate_careful(), but also accepts the value "false" as a synonym for "never". git_config_expire_date() calls parse_expire_date(), and prints an error message if the value is invalid. A new OPT_EXPIRE_DATE option type has also been added to parse-options.h for parsing expiration date command line arguments. Signed-off-by: Adam Simpkins --- builtin-gc.c | 9 ++++----- builtin-prune.c | 4 ++-- builtin-reflog.c | 27 +++++++++++---------------- cache.h | 2 ++ config.c | 12 ++++++++++++ date.c | 10 ++++++++++ parse-options.c | 17 +++++++++++++++++ parse-options.h | 4 ++++ t/t1410-reflog.sh | 11 +++++++++++ t/t5304-prune.sh | 36 +++++++++++++++++++++++++++++++++++- 10 files changed, 108 insertions(+), 24 deletions(-) diff --git a/builtin-gc.c b/builtin-gc.c index c304638..3921e6e 100644 --- a/builtin-gc.c +++ b/builtin-gc.c @@ -57,11 +57,10 @@ static int gc_config(const char *var, const char *value, void *cb) return 0; } if (!strcmp(var, "gc.pruneexpire")) { - if (value && strcmp(value, "now")) { - unsigned long now = approxidate("now"); - if (approxidate(value) >= now) - return error("Invalid %s: '%s'", var, value); - } + /* Make sure the value is valid */ + unsigned long expire_date; + if (git_config_expire_date(&expire_date, var, value)) + return -1; return git_config_string(&prune_expire, var, value); } return git_default_config(var, value, cb); diff --git a/builtin-prune.c b/builtin-prune.c index f22bcf6..e8d25a6 100644 --- a/builtin-prune.c +++ b/builtin-prune.c @@ -129,8 +129,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix) "do not remove, show only"), OPT_BOOLEAN('v', NULL, &verbose, "report pruned objects"), - OPT_DATE(0, "expire", &expire, - "expire objects older than