# [PATCH] Use "git_config_string" to simplify "builtin-gc.c" code where "prune_expire" is set

5 messages from 2008-09-30 to 2008-09-30. Participants: David Bryson, Shawn O. Pearce.
Thread: https://gitlist.dev/t/15730

## David Bryson, 2008-09-30 19:05

Subject: [PATCH] Use "git_config_string" to simplify "builtin-gc.c" code where "prune_expire" is set
Message-ID: <20080930190549.GA9869@eratosthenes.cryptobackpack.org>
URL: https://gitlist.dev/e/20080930190549.GA9869%40eratosthenes.cryptobackpack.org

```
Hi all,
This is a quick janitor patch and my first patch sent to the git mailing
list.  Please let me know if I have done any process of the patch
submission wrong, and if I got the Janitorial task done in the proper
fashion.

Signed-off-by: David Bryson <david@statichacks.org>
---
 builtin-gc.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/builtin-gc.c b/builtin-gc.c
index fac200e..6260652 100644
--- a/builtin-gc.c
+++ b/builtin-gc.c
@@ -57,15 +57,12 @@ static int gc_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 	if (!strcmp(var, "gc.pruneexpire")) {
-		if (!value)
-			return config_error_nonbool(var);
-		if (strcmp(value, "now")) {
+		if (value && strcmp(value, "now")) {
 			unsigned long now = approxidate("now");
 			if (approxidate(value) >= now)
 				return error("Invalid %s: '%s'", var, value);
 		}
-		prune_expire = xstrdup(value);
-		return 0;
+		return git_config_string(&prune_expire, var, value);
 	}
 	return git_default_config(var, value, cb);
 }
-- 
1.6.0.2

```

## Shawn O. Pearce, 2008-09-30 19:37

Subject: Re: [PATCH] Use "git_config_string" to simplify "builtin-gc.c" code where "prune_expire" is set
Message-ID: <20080930193725.GJ21310@spearce.org>
URL: https://gitlist.dev/e/20080930193725.GJ21310%40spearce.org
In-Reply-To: <20080930190549.GA9869@eratosthenes.cryptobackpack.org>

```
David Bryson <david@statichacks.org> wrote:
> Hi all,
> This is a quick janitor patch and my first patch sent to the git mailing
> list.  Please let me know if I have done any process of the patch
> submission wrong, and if I got the Janitorial task done in the proper
> fashion.

This part of the message probably should go after the "---" line.
Everything above "---" goes into the commit message, everything
after it is automatically cut by git-am.

This sort of "Hi, I'm new" isn't very useful in the long term in
the project logs, but its still useful to introduce yourself.  ;-)
 
> Signed-off-by: David Bryson <david@statichacks.org>
> ---
>  builtin-gc.c |    7 ++-----
>  1 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/builtin-gc.c b/builtin-gc.c
> index fac200e..6260652 100644
> --- a/builtin-gc.c
> +++ b/builtin-gc.c
> @@ -57,15 +57,12 @@ static int gc_config(const char *var, const char *value, void *cb)
>  		return 0;
>  	}
>  	if (!strcmp(var, "gc.pruneexpire")) {
> -		if (!value)
> -			return config_error_nonbool(var);
> -		if (strcmp(value, "now")) {
> +		if (value && strcmp(value, "now")) {
>  			unsigned long now = approxidate("now");
>  			if (approxidate(value) >= now)
>  				return error("Invalid %s: '%s'", var, value);
>  		}
> -		prune_expire = xstrdup(value);
> -		return 0;
> +		return git_config_string(&prune_expire, var, value);
>  	}
>  	return git_default_config(var, value, cb);
>  }

-- 
Shawn.

```

## David Bryson, 2008-09-30 19:53

Subject: [PATCH] Use "git_config_string" to simplify "builtin-gc.c" code where "prune_expire" is set
Message-ID: <20080930195355.GA14499@eratosthenes.cryptobackpack.org>
URL: https://gitlist.dev/e/20080930195355.GA14499%40eratosthenes.cryptobackpack.org
In-Reply-To: <20080930190549.GA9869@eratosthenes.cryptobackpack.org>

```

Signed-off-by: David Bryson <david@statichacks.org>
---
 builtin-gc.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/builtin-gc.c b/builtin-gc.c
index fac200e..6260652 100644
--- a/builtin-gc.c
+++ b/builtin-gc.c
@@ -57,15 +57,12 @@ static int gc_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 	if (!strcmp(var, "gc.pruneexpire")) {
-		if (!value)
-			return config_error_nonbool(var);
-		if (strcmp(value, "now")) {
+		if (value && strcmp(value, "now")) {
 			unsigned long now = approxidate("now");
 			if (approxidate(value) >= now)
 				return error("Invalid %s: '%s'", var, value);
 		}
-		prune_expire = xstrdup(value);
-		return 0;
+		return git_config_string(&prune_expire, var, value);
 	}
 	return git_default_config(var, value, cb);
 }
-- 
1.6.0.2

```

## Shawn O. Pearce, 2008-09-30 20:04

Subject: Re: [PATCH] Use "git_config_string" to simplify "builtin-gc.c" code where "prune_expire" is set
Message-ID: <20080930200423.GL21310@spearce.org>
URL: https://gitlist.dev/e/20080930200423.GL21310%40spearce.org
In-Reply-To: <20080930195355.GA14499@eratosthenes.cryptobackpack.org>

```
David Bryson <david@statichacks.org> wrote:
> diff --git a/builtin-gc.c b/builtin-gc.c
> index fac200e..6260652 100644
> --- a/builtin-gc.c
> +++ b/builtin-gc.c
> @@ -57,15 +57,12 @@ static int gc_config(const char *var, const char *value, void *cb)
>  		return 0;
>  	}
>  	if (!strcmp(var, "gc.pruneexpire")) {
> -		if (!value)
> -			return config_error_nonbool(var);
> -		if (strcmp(value, "now")) {
> +		if (value && strcmp(value, "now")) {
>  			unsigned long now = approxidate("now");
>  			if (approxidate(value) >= now)
>  				return error("Invalid %s: '%s'", var, value);
>  		}
> -		prune_expire = xstrdup(value);
> -		return 0;
> +		return git_config_string(&prune_expire, var, value);

The message formatting was a lot better.  But:

builtin-gc.c:65: warning: passing argument 1 of 'git_config_string' from incompatible pointer type

>From http://git.or.cz/gitwiki/Janitor:

  This is because the first argument to "git_config_string" should
  be a "const char **", not a "char **". There will be a compile
  time warning if a "char **" is passed instead of a "const char **"
  and the patch will be rejected. (And no, casting the "char **"
  into a "const char **" is not a good solution either.)"

-- 
Shawn.

```

## David Bryson, 2008-09-30 20:28

Subject: [PATCH] Use "git_config_string" to simplify "builtin-gc.c" code where "prune_expire" is set
Message-ID: <20080930202858.GA1953@eratosthenes.cryptobackpack.org>
URL: https://gitlist.dev/e/20080930202858.GA1953%40eratosthenes.cryptobackpack.org
In-Reply-To: <20080930190549.GA9869@eratosthenes.cryptobackpack.org>

```

Signed-off-by: David Bryson <david@statichacks.org>
---
Manage to fix the const char ** compile error, third time is a
harm(hopefully!)

 builtin-gc.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/builtin-gc.c b/builtin-gc.c
index fac200e..7af65bb 100644
--- a/builtin-gc.c
+++ b/builtin-gc.c
@@ -26,7 +26,7 @@ static int pack_refs = 1;
 static int aggressive_window = -1;
 static int gc_auto_threshold = 6700;
 static int gc_auto_pack_limit = 50;
-static char *prune_expire = "2.weeks.ago";
+static const char *prune_expire = "2.weeks.ago";
 
 #define MAX_ADD 10
 static const char *argv_pack_refs[] = {"pack-refs", "--all", "--prune", NULL};
@@ -57,15 +57,12 @@ static int gc_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 	if (!strcmp(var, "gc.pruneexpire")) {
-		if (!value)
-			return config_error_nonbool(var);
-		if (strcmp(value, "now")) {
+		if (value && strcmp(value, "now")) {
 			unsigned long now = approxidate("now");
 			if (approxidate(value) >= now)
 				return error("Invalid %s: '%s'", var, value);
 		}
-		prune_expire = xstrdup(value);
-		return 0;
+		return git_config_string(&prune_expire, var, value);
 	}
 	return git_default_config(var, value, cb);
 }
-- 
1.6.0.2

```
