git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH V2] config: add --expiry-date
       [not found] <f9d6d1cfcad17c93a0131cf69c3d7705@unimetic.com>
@ 2017-11-13 17:53 ` hsed
  0 siblings, 0 replies; 6+ messages in thread
From: hsed @ 2017-11-13 17:53 UTC (permalink / raw)
  To: Git; +Cc: Jeff King, Kevin Daudt

Description:
This patch adds a new option to the config command.

Enables flag --expiry-date as a data-type to covert date-strings to
timestamps when reading from config files (GET).
This flag is ignored on write (SET) because the date-string is stored in
config without performing any normalization.

A few test cases are also created since this is a new feature.

Motivation:
A parse_expiry_date() function already existed for api calls,
this patch simply allows the function to be used from the command line.

Update:
Added suggestions, documentation, relative time test case and test
helper function to print out timestamps for comparison. Updated reflog.c
to avoid function duplication.

Signed-off-by: Haaris <hsed@unimetic.com>
---
  Documentation/git-config.txt |  5 +++++
  builtin/config.c             | 10 +++++++++-
  builtin/reflog.c             | 14 ++------------
  config.c                     |  9 +++++++++
  config.h                     |  1 +
  t/helper/test-date.c         | 12 ++++++++++++
  t/t1300-repo-config.sh       | 30 ++++++++++++++++++++++++++++++
  7 files changed, 68 insertions(+), 13 deletions(-)

diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 4edd09fc6..14da5fc15 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -180,6 +180,11 @@ See also <<FILES>>.
  	value (but you can use `git config section.variable ~/`
  	from the command line to let your shell do the expansion).

+--expiry-date::
+	`git config` will ensure that the output is converted from
+	a fixed or relative date-string to a timestamp. This option
+	has no effect when setting the value.
+
  -z::
  --null::
  	For all options that output values and/or keys, always
diff --git a/builtin/config.c b/builtin/config.c
index d13daeeb5..afdb02191 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -52,6 +52,7 @@ static int show_origin;
  #define TYPE_INT (1<<1)
  #define TYPE_BOOL_OR_INT (1<<2)
  #define TYPE_PATH (1<<3)
+#define TYPE_EXPIRY_DATE (1<<4)

  static struct option builtin_config_options[] = {
  	OPT_GROUP(N_("Config file location")),
@@ -80,6 +81,7 @@ static struct option builtin_config_options[] = {
  	OPT_BIT(0, "int", &types, N_("value is decimal number"), TYPE_INT),
  	OPT_BIT(0, "bool-or-int", &types, N_("value is --bool or --int"), 
TYPE_BOOL_OR_INT),
  	OPT_BIT(0, "path", &types, N_("value is a path (file or directory 
name)"), TYPE_PATH),
+	OPT_BIT(0, "expiry-date", &types, N_("value is an expiry date"), 
TYPE_EXPIRY_DATE),
  	OPT_GROUP(N_("Other")),
  	OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL 
byte")),
  	OPT_BOOL(0, "name-only", &omit_values, N_("show variable names 
only")),
@@ -159,6 +161,11 @@ static int format_config(struct strbuf *buf, const 
char *key_, const char *value
  				return -1;
  			strbuf_addstr(buf, v);
  			free((char *)v);
+		} else if (types == TYPE_EXPIRY_DATE) {
+			timestamp_t t;
+			if(git_config_expiry_date(&t, key_, value_) < 0)
+				return -1;
+			strbuf_addf(buf, "%"PRItime, t);
  		} else if (value_) {
  			strbuf_addstr(buf, value_);
  		} else {
@@ -273,12 +280,13 @@ static char *normalize_value(const char *key, 
const char *value)
  	if (!value)
  		return NULL;

-	if (types == 0 || types == TYPE_PATH)
+	if (types == 0 || types == TYPE_PATH || types == TYPE_EXPIRY_DATE)
  		/*
  		 * We don't do normalization for TYPE_PATH here: If
  		 * the path is like ~/foobar/, we prefer to store
  		 * "~/foobar/" in the config file, and to expand the ~
  		 * when retrieving the value.
+		 * Also don't do normalization for expiry dates.
  		 */
  		return xstrdup(value);
  	if (types == TYPE_INT)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index ab31a3b6a..223372531 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -416,16 +416,6 @@ static struct reflog_expire_cfg *find_cfg_ent(const 
char *pattern, size_t len)
  	return ent;
  }

-static int parse_expire_cfg_value(const char *var, const char *value, 
timestamp_t *expire)
-{
-	if (!value)
-		return config_error_nonbool(var);
-	if (parse_expiry_date(value, expire))
-		return error(_("'%s' for '%s' is not a valid timestamp"),
-			     value, var);
-	return 0;
-}
-
  /* expiry timer slot */
  #define EXPIRE_TOTAL   01
  #define EXPIRE_UNREACH 02
@@ -443,11 +433,11 @@ static int reflog_expire_config(const char *var, 
const char *value, void *cb)

  	if (!strcmp(key, "reflogexpire")) {
  		slot = EXPIRE_TOTAL;
-		if (parse_expire_cfg_value(var, value, &expire))
+		if (git_config_expiry_date(&expire, var, value))
  			return -1;
  	} else if (!strcmp(key, "reflogexpireunreachable")) {
  		slot = EXPIRE_UNREACH;
-		if (parse_expire_cfg_value(var, value, &expire))
+		if (git_config_expiry_date(&expire, var, value))
  			return -1;
  	} else
  		return git_default_config(var, value, cb);
diff --git a/config.c b/config.c
index 903abf953..6ded9ce98 100644
--- a/config.c
+++ b/config.c
@@ -990,6 +990,15 @@ int git_config_pathname(const char **dest, const 
char *var, const char *value)
  	return 0;
  }

+int git_config_expiry_date(timestamp_t *timestamp, const char *var, 
const char *value)
+{
+	if (!value)
+		return config_error_nonbool(var);
+	if (parse_expiry_date(value, timestamp))
+		die(_("failed to parse date_string in: '%s'"), value);
+	return 0;
+}
+
  static int git_default_core_config(const char *var, const char *value)
  {
  	/* This needs a better name */
diff --git a/config.h b/config.h
index a49d26441..fc66c5933 100644
--- a/config.h
+++ b/config.h
@@ -58,6 +58,7 @@ extern int git_config_bool_or_int(const char *, const 
char *, int *);
  extern int git_config_bool(const char *, const char *);
  extern int git_config_string(const char **, const char *, const char 
*);
  extern int git_config_pathname(const char **, const char *, const char 
*);
+extern int git_config_expiry_date(timestamp_t *, const char *, const 
char *);
  extern int git_config_set_in_file_gently(const char *, const char *, 
const char *);
  extern void git_config_set_in_file(const char *, const char *, const 
char *);
  extern int git_config_set_gently(const char *, const char *);
diff --git a/t/helper/test-date.c b/t/helper/test-date.c
index f414a3ac6..ac8368797 100644
--- a/t/helper/test-date.c
+++ b/t/helper/test-date.c
@@ -5,6 +5,7 @@ static const char *usage_msg = "\n"
  "  test-date show:<format> [time_t]...\n"
  "  test-date parse [date]...\n"
  "  test-date approxidate [date]...\n"
+"  test-date timestamp [date]...\n"
  "  test-date is64bit\n"
  "  test-date time_t-is64bit\n";

@@ -71,6 +72,15 @@ static void parse_approxidate(const char **argv, 
struct timeval *now)
  	}
  }

+static void parse_approx_timestamp(const char **argv, struct timeval 
*now)
+{
+	for (; *argv; argv++) {
+		timestamp_t t;
+		t = approxidate_relative(*argv, now);
+		printf("%s -> %"PRItime"\n", *argv, t);
+	}
+}
+
  int cmd_main(int argc, const char **argv)
  {
  	struct timeval now;
@@ -95,6 +105,8 @@ int cmd_main(int argc, const char **argv)
  		parse_dates(argv+1, &now);
  	else if (!strcmp(*argv, "approxidate"))
  		parse_approxidate(argv+1, &now);
+	else if (!strcmp(*argv, "timestamp"))
+		parse_approx_timestamp(argv+1, &now);
  	else if (!strcmp(*argv, "is64bit"))
  		return sizeof(timestamp_t) == 8 ? 0 : 1;
  	else if (!strcmp(*argv, "time_t-is64bit"))
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 364a53700..cbeb9bebe 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -901,6 +901,36 @@ test_expect_success 'get --path barfs on boolean 
variable' '
  	test_must_fail git config --get --path path.bool
  '

+test_expect_success 'get --expiry-date' '
+	rel="3.weeks.5.days.00:00" &&
+	rel_out="$rel ->" &&
+	cat >.git/config <<-\EOF &&
+	[date]
+	valid1 = "3.weeks.5.days 00:00"
+	valid2 = "Fri Jun 4 15:46:55 2010"
+	valid3 = "2017/11/11 11:11:11PM"
+	valid4 = "2017/11/10 09:08:07 PM"
+	valid5 = "never"
+	invalid1 = "abc"
+	EOF
+	cat >expect <<-EOF &&
+	$(test-date timestamp $rel)
+	1275666415
+	1510441871
+	1510348087
+	0
+	EOF
+	{
+		echo "$rel_out $(git config --expiry-date date.valid1)"
+		git config --expiry-date date.valid2 &&
+		git config --expiry-date date.valid3 &&
+		git config --expiry-date date.valid4 &&
+		git config --expiry-date date.valid5
+	} >actual &&
+	test_cmp expect actual &&
+	test_must_fail git config --expiry-date date.invalid1
+'
+
  cat > expect << EOF
  [quote]
  	leading = " test"

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

* Re: [PATCH V2] config: add --expiry-date
  2017-11-14  6:38   ` Junio C Hamano
@ 2017-11-15 22:10     ` hsed
  0 siblings, 0 replies; 6+ messages in thread
From: hsed @ 2017-11-15 22:10 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git

On 2017-11-14 06:38, Junio C Hamano wrote:
> hsed@unimetic.com writes:
> 
>> From: Haaris <hsed@unimetic.com>
>> 
>> Description:
>> This patch adds a new option to the config command.
>> 
>> ...
>> 
>> Motivation:
>> A parse_expiry_date() function already existed for api calls,
>> this patch simply allows the function to be used from the command 
>> line.
>> 
>> Signed-off-by: Haaris <hsed@unimetic.com>
>> ---
> 
> Please drop all these section headers; they are irritating.  Learn
> from "git log --no-merges" how the log messages in this project is
> written and imitate them.  Documentation/SubmittingPatches would be
> helpful.
> 
> 	Add --expiry-date as a new type 'git config --get' takes,
> 	similar to existing --int, --bool, etc. types, so that
> 	scripts can learn values of configuration variables like
> 	gc.reflogexpire (e.g. "2.weeks") in a more useful way
> 	(e.g. the timesamp as of two weeks ago, expressed in number
> 	of seconds since epoch).
> 
> 	As a helper function necessary to do this already exists in
> 	the implementation of builtin/reflog.c, the implementation
> 	is just the matter of moving it to config.c and using it
> 	from bultin/config.c, but shuffle the order of the parameter
> 	so that the pointer to the output variable comes first.
> 	This is to match the convention used by git_config_pathname()
> 	and other helper functions.
> 
> or something like that?

Hi,
I am sorry for not following the format properly. I will change this for
next patch update.

> 
>> +		} else if (types == TYPE_EXPIRY_DATE) {
>> +			timestamp_t t;
>> +			if(git_config_expiry_date(&t, key_, value_) < 0)
> 
> Style.

Sure.

> 
> 	if (git_config_expiry_date(&t, key_, value_) < 0)
> 
>> +				return -1;
>> +			strbuf_addf(buf, "%"PRItime, t);
>> ...
> 
> Thanks.


Kind Regards,
Haaris

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

* Re: [PATCH V2] config: add --expiry-date
  2017-11-14  6:21   ` Christian Couder
@ 2017-11-14 16:03     ` Marc Branchaud
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Branchaud @ 2017-11-14 16:03 UTC (permalink / raw)
  To: Christian Couder, hsed; +Cc: Jeff King, git

On 2017-11-14 01:21 AM, Christian Couder wrote:
> On Tue, Nov 14, 2017 at 3:04 AM,  <hsed@unimetic.com> wrote:
>> From: Haaris <hsed@unimetic.com>
>>
>> Description:
>> This patch adds a new option to the config command.
>>
>> Uses flag --expiry-date as a data-type to covert date-strings to
>> timestamps when reading from config files (GET).
>> This flag is ignored on write (SET) because the date-string is stored in
>> config without performing any normalization.
>>
>> Creates a few test cases and documentation since its a new feature.
>>
>> Motivation:
>> A parse_expiry_date() function already existed for api calls,
>> this patch simply allows the function to be used from the command line.
>>
>> Signed-off-by: Haaris <hsed@unimetic.com>
> 
> Documentation/SubmittingPatches contains the following:
> 
> "Also notice that a real name is used in the Signed-off-by: line. Please
> don't hide your real name."
> 
> And there is the following example before that:
> 
>          Signed-off-by: Random J Developer <random@developer.example.org>
> 
> So it looks like "a real name" actually means "a real firstname and a
> real surname".
> 
> It would be nice if your "Signed-off-by:" could match this format.

It might already match that format if Haaris lives in a society that 
only uses single names.

Still, such names are unusual enough that it's good to check that new 
contributors are following the guidelines properly.

		M.


> Also if you have a "From:" line at the beginning of the patch, please
> make sure that the name there is tha same as on the "Signed-off-by:".
> 
> Thanks for working on this,
> Christian.
> 

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

* Re: [PATCH V2] config: add --expiry-date
  2017-11-14  2:04 ` [PATCH V2] config: add --expiry-date hsed
  2017-11-14  6:21   ` Christian Couder
@ 2017-11-14  6:38   ` Junio C Hamano
  2017-11-15 22:10     ` hsed
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2017-11-14  6:38 UTC (permalink / raw)
  To: hsed; +Cc: peff, git

hsed@unimetic.com writes:

> From: Haaris <hsed@unimetic.com>
>
> Description:
> This patch adds a new option to the config command.
>
> Uses flag --expiry-date as a data-type to covert date-strings to
> timestamps when reading from config files (GET).
> This flag is ignored on write (SET) because the date-string is stored in
> config without performing any normalization.
>
> Creates a few test cases and documentation since its a new feature.
>
> Motivation:
> A parse_expiry_date() function already existed for api calls,
> this patch simply allows the function to be used from the command line.
>
> Signed-off-by: Haaris <hsed@unimetic.com>
> ---

Please drop all these section headers; they are irritating.  Learn
from "git log --no-merges" how the log messages in this project is
written and imitate them.  Documentation/SubmittingPatches would be
helpful.

	Add --expiry-date as a new type 'git config --get' takes,
	similar to existing --int, --bool, etc. types, so that
	scripts can learn values of configuration variables like
	gc.reflogexpire (e.g. "2.weeks") in a more useful way
	(e.g. the timesamp as of two weeks ago, expressed in number
	of seconds since epoch).

	As a helper function necessary to do this already exists in
	the implementation of builtin/reflog.c, the implementation
	is just the matter of moving it to config.c and using it
	from bultin/config.c, but shuffle the order of the parameter
	so that the pointer to the output variable comes first.
	This is to match the convention used by git_config_pathname()
	and other helper functions.

or something like that?

> +		} else if (types == TYPE_EXPIRY_DATE) {
> +			timestamp_t t;
> +			if(git_config_expiry_date(&t, key_, value_) < 0)

Style.

	if (git_config_expiry_date(&t, key_, value_) < 0)

> +				return -1;
> +			strbuf_addf(buf, "%"PRItime, t);
> ...

Thanks.

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

* Re: [PATCH V2] config: add --expiry-date
  2017-11-14  2:04 ` [PATCH V2] config: add --expiry-date hsed
@ 2017-11-14  6:21   ` Christian Couder
  2017-11-14 16:03     ` Marc Branchaud
  2017-11-14  6:38   ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: Christian Couder @ 2017-11-14  6:21 UTC (permalink / raw)
  To: hsed; +Cc: Jeff King, git

On Tue, Nov 14, 2017 at 3:04 AM,  <hsed@unimetic.com> wrote:
> From: Haaris <hsed@unimetic.com>
>
> Description:
> This patch adds a new option to the config command.
>
> Uses flag --expiry-date as a data-type to covert date-strings to
> timestamps when reading from config files (GET).
> This flag is ignored on write (SET) because the date-string is stored in
> config without performing any normalization.
>
> Creates a few test cases and documentation since its a new feature.
>
> Motivation:
> A parse_expiry_date() function already existed for api calls,
> this patch simply allows the function to be used from the command line.
>
> Signed-off-by: Haaris <hsed@unimetic.com>

Documentation/SubmittingPatches contains the following:

"Also notice that a real name is used in the Signed-off-by: line. Please
don't hide your real name."

And there is the following example before that:

        Signed-off-by: Random J Developer <random@developer.example.org>

So it looks like "a real name" actually means "a real firstname and a
real surname".

It would be nice if your "Signed-off-by:" could match this format.

Also if you have a "From:" line at the beginning of the patch, please
make sure that the name there is tha same as on the "Signed-off-by:".

Thanks for working on this,
Christian.

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

* [PATCH V2] config: add --expiry-date
  2017-11-12 14:55 [PATCH] config: added --expiry-date type support Jeff King
@ 2017-11-14  2:04 ` hsed
  2017-11-14  6:21   ` Christian Couder
  2017-11-14  6:38   ` Junio C Hamano
  0 siblings, 2 replies; 6+ messages in thread
From: hsed @ 2017-11-14  2:04 UTC (permalink / raw)
  To: peff; +Cc: git, hsed

From: Haaris <hsed@unimetic.com>

Description:
This patch adds a new option to the config command.

Uses flag --expiry-date as a data-type to covert date-strings to
timestamps when reading from config files (GET).
This flag is ignored on write (SET) because the date-string is stored in
config without performing any normalization.

Creates a few test cases and documentation since its a new feature.

Motivation:
A parse_expiry_date() function already existed for api calls,
this patch simply allows the function to be used from the command line.

Signed-off-by: Haaris <hsed@unimetic.com>
---
 Documentation/git-config.txt |  5 +++++
 builtin/config.c             | 10 +++++++++-
 builtin/reflog.c             | 14 ++------------
 config.c                     |  9 +++++++++
 config.h                     |  1 +
 t/helper/test-date.c         | 12 ++++++++++++
 t/t1300-repo-config.sh       | 30 ++++++++++++++++++++++++++++++
 7 files changed, 68 insertions(+), 13 deletions(-)

Update:
Added suggestions, documentation, relative time test case and test
helper function to print out timestamps for comparison. Updated reflog.c
to avoid function duplication.

Sorry for duplicate messages, the other one didn't get threaded properly.

diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 4edd09f..14da5fc 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -180,6 +180,11 @@ See also <<FILES>>.
 	value (but you can use `git config section.variable ~/`
 	from the command line to let your shell do the expansion).
 
+--expiry-date::
+	`git config` will ensure that the output is converted from
+	a fixed or relative date-string to a timestamp. This option
+	has no effect when setting the value.
+
 -z::
 --null::
 	For all options that output values and/or keys, always
diff --git a/builtin/config.c b/builtin/config.c
index d13daee..afdb021 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -52,6 +52,7 @@ static int show_origin;
 #define TYPE_INT (1<<1)
 #define TYPE_BOOL_OR_INT (1<<2)
 #define TYPE_PATH (1<<3)
+#define TYPE_EXPIRY_DATE (1<<4)
 
 static struct option builtin_config_options[] = {
 	OPT_GROUP(N_("Config file location")),
@@ -80,6 +81,7 @@ static struct option builtin_config_options[] = {
 	OPT_BIT(0, "int", &types, N_("value is decimal number"), TYPE_INT),
 	OPT_BIT(0, "bool-or-int", &types, N_("value is --bool or --int"), TYPE_BOOL_OR_INT),
 	OPT_BIT(0, "path", &types, N_("value is a path (file or directory name)"), TYPE_PATH),
+	OPT_BIT(0, "expiry-date", &types, N_("value is an expiry date"), TYPE_EXPIRY_DATE),
 	OPT_GROUP(N_("Other")),
 	OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")),
 	OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")),
@@ -159,6 +161,11 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
 				return -1;
 			strbuf_addstr(buf, v);
 			free((char *)v);
+		} else if (types == TYPE_EXPIRY_DATE) {
+			timestamp_t t;
+			if(git_config_expiry_date(&t, key_, value_) < 0)
+				return -1;
+			strbuf_addf(buf, "%"PRItime, t);
 		} else if (value_) {
 			strbuf_addstr(buf, value_);
 		} else {
@@ -273,12 +280,13 @@ static char *normalize_value(const char *key, const char *value)
 	if (!value)
 		return NULL;
 
-	if (types == 0 || types == TYPE_PATH)
+	if (types == 0 || types == TYPE_PATH || types == TYPE_EXPIRY_DATE)
 		/*
 		 * We don't do normalization for TYPE_PATH here: If
 		 * the path is like ~/foobar/, we prefer to store
 		 * "~/foobar/" in the config file, and to expand the ~
 		 * when retrieving the value.
+		 * Also don't do normalization for expiry dates.
 		 */
 		return xstrdup(value);
 	if (types == TYPE_INT)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index ab31a3b..2233725 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -416,16 +416,6 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
 	return ent;
 }
 
-static int parse_expire_cfg_value(const char *var, const char *value, timestamp_t *expire)
-{
-	if (!value)
-		return config_error_nonbool(var);
-	if (parse_expiry_date(value, expire))
-		return error(_("'%s' for '%s' is not a valid timestamp"),
-			     value, var);
-	return 0;
-}
-
 /* expiry timer slot */
 #define EXPIRE_TOTAL   01
 #define EXPIRE_UNREACH 02
@@ -443,11 +433,11 @@ static int reflog_expire_config(const char *var, const char *value, void *cb)
 
 	if (!strcmp(key, "reflogexpire")) {
 		slot = EXPIRE_TOTAL;
-		if (parse_expire_cfg_value(var, value, &expire))
+		if (git_config_expiry_date(&expire, var, value))
 			return -1;
 	} else if (!strcmp(key, "reflogexpireunreachable")) {
 		slot = EXPIRE_UNREACH;
-		if (parse_expire_cfg_value(var, value, &expire))
+		if (git_config_expiry_date(&expire, var, value))
 			return -1;
 	} else
 		return git_default_config(var, value, cb);
diff --git a/config.c b/config.c
index 903abf9..6ded9ce 100644
--- a/config.c
+++ b/config.c
@@ -990,6 +990,15 @@ int git_config_pathname(const char **dest, const char *var, const char *value)
 	return 0;
 }
 
+int git_config_expiry_date(timestamp_t *timestamp, const char *var, const char *value)
+{
+	if (!value)
+		return config_error_nonbool(var);
+	if (parse_expiry_date(value, timestamp))
+		die(_("failed to parse date_string in: '%s'"), value);
+	return 0;
+}
+
 static int git_default_core_config(const char *var, const char *value)
 {
 	/* This needs a better name */
diff --git a/config.h b/config.h
index a49d264..fc66c59 100644
--- a/config.h
+++ b/config.h
@@ -58,6 +58,7 @@ extern int git_config_bool_or_int(const char *, const char *, int *);
 extern int git_config_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
+extern int git_config_expiry_date(timestamp_t *, const char *, const char *);
 extern int git_config_set_in_file_gently(const char *, const char *, const char *);
 extern void git_config_set_in_file(const char *, const char *, const char *);
 extern int git_config_set_gently(const char *, const char *);
diff --git a/t/helper/test-date.c b/t/helper/test-date.c
index f414a3a..ac83687 100644
--- a/t/helper/test-date.c
+++ b/t/helper/test-date.c
@@ -5,6 +5,7 @@ static const char *usage_msg = "\n"
 "  test-date show:<format> [time_t]...\n"
 "  test-date parse [date]...\n"
 "  test-date approxidate [date]...\n"
+"  test-date timestamp [date]...\n"
 "  test-date is64bit\n"
 "  test-date time_t-is64bit\n";
 
@@ -71,6 +72,15 @@ static void parse_approxidate(const char **argv, struct timeval *now)
 	}
 }
 
+static void parse_approx_timestamp(const char **argv, struct timeval *now)
+{
+	for (; *argv; argv++) {
+		timestamp_t t;
+		t = approxidate_relative(*argv, now);
+		printf("%s -> %"PRItime"\n", *argv, t);
+	}
+}
+
 int cmd_main(int argc, const char **argv)
 {
 	struct timeval now;
@@ -95,6 +105,8 @@ int cmd_main(int argc, const char **argv)
 		parse_dates(argv+1, &now);
 	else if (!strcmp(*argv, "approxidate"))
 		parse_approxidate(argv+1, &now);
+	else if (!strcmp(*argv, "timestamp"))
+		parse_approx_timestamp(argv+1, &now);
 	else if (!strcmp(*argv, "is64bit"))
 		return sizeof(timestamp_t) == 8 ? 0 : 1;
 	else if (!strcmp(*argv, "time_t-is64bit"))
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 364a537..cbeb9be 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -901,6 +901,36 @@ test_expect_success 'get --path barfs on boolean variable' '
 	test_must_fail git config --get --path path.bool
 '
 
+test_expect_success 'get --expiry-date' '
+	rel="3.weeks.5.days.00:00" &&
+	rel_out="$rel ->" &&
+	cat >.git/config <<-\EOF &&
+	[date]
+	valid1 = "3.weeks.5.days 00:00"
+	valid2 = "Fri Jun 4 15:46:55 2010"
+	valid3 = "2017/11/11 11:11:11PM"
+	valid4 = "2017/11/10 09:08:07 PM"
+	valid5 = "never"
+	invalid1 = "abc"
+	EOF
+	cat >expect <<-EOF &&
+	$(test-date timestamp $rel)
+	1275666415
+	1510441871
+	1510348087
+	0
+	EOF
+	{
+		echo "$rel_out $(git config --expiry-date date.valid1)"
+		git config --expiry-date date.valid2 &&
+		git config --expiry-date date.valid3 &&
+		git config --expiry-date date.valid4 &&
+		git config --expiry-date date.valid5
+	} >actual &&
+	test_cmp expect actual &&
+	test_must_fail git config --expiry-date date.invalid1
+'
+
 cat > expect << EOF
 [quote]
 	leading = " test"
-- 
2.7.4


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

end of thread, other threads:[~2017-11-15 22:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <f9d6d1cfcad17c93a0131cf69c3d7705@unimetic.com>
2017-11-13 17:53 ` [PATCH V2] config: add --expiry-date hsed
2017-11-12 14:55 [PATCH] config: added --expiry-date type support Jeff King
2017-11-14  2:04 ` [PATCH V2] config: add --expiry-date hsed
2017-11-14  6:21   ` Christian Couder
2017-11-14 16:03     ` Marc Branchaud
2017-11-14  6:38   ` Junio C Hamano
2017-11-15 22:10     ` hsed

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git