git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] repo-config: support --get-regexp and fix crash

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 3, 2006, 12:41 UTC
Message-ID
<Pine.LNX.4.63.0605031438510.6340@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<7vlktjhhvc.fsf@assigned-by-dhcp.cox.net>
Hi,
thanks for your patch.
On Tue, 2 May 2006, Junio C Hamano wrote:
Show 28 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > @@ -26,16 +29,18 @@ static int show_config(const char* key_,
> >  	if (value_ == NULL)
> >  		value_ = "";
> >  
> > -	if (!strcmp(key_, key) &&
> > +	if ((use_key_regexp || !strcmp(key_, key)) &&
> > +			(!use_key_regexp ||
> > +			 !regexec(key_regexp, key_, 0, NULL, 0)) &&
> >  			(regexp == NULL ||
> >  			 (do_not_match ^
> >  			  !regexec(regexp, value_, 0, NULL, 0)))) {
> 
> That's a convoluted logic.
> 
>  (1) Either we are using key-regexp, or otherwise the key has to
>      exactly match; and
> 
>  (2) Either we are not using key-regexp, or key-regexp must
>      match; and
> 
>  (3) Either we are not using regexp, or value must match (or
>      unmatch) as we are told by do_no_match.
> 
> It all makes sense, but I wonder if this is the clearest way to
> convey what is happening to people.  Not that I have a cleaner
> alternative in mind...
How about this (on top of your patch):

--- snip --- [PATCH] repo-config: deconvolute logics

It was rightly noticed that the logic is quite convoluted. Fix that.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	The real change is very short, but a code block got reindented, 
	too.
 repo-config.c |   50 ++++++++++++++++++++++++++------------------------
 1 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/repo-config.c b/repo-config.c
index 7e06d1a..63eda1b 100644
--- a/repo-config.c
+++ b/repo-config.c
@@ -27,36 +27,38 @@ static int show_config(const char* key_,
 {
 	char value[256];
 	const char *vptr = value;
+	int dup_error = 0;
 
 	if (value_ == NULL)
 		value_ = "";
 
-	if ((use_key_regexp || !strcmp(key_, key)) &&
-			(!use_key_regexp ||
-			 !regexec(key_regexp, key_, 0, NULL, 0)) &&
-			(regexp == NULL ||
+	if (!use_key_regexp && strcmp(key_, key))
+		return 0;
+	if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0))
+		return 0;
+	if (regexp != NULL &&
 			 (do_not_match ^
-			  !regexec(regexp, value_, 0, NULL, 0)))) {
-		int dup_error = 0;
-		if (show_keys)
-			printf("%s ", key_);
-		if (seen && !do_all)
-			dup_error = 1;
-		if (type == T_INT)
-			sprintf(value, "%d", git_config_int(key_, value_));
-		else if (type == T_BOOL)
-			sprintf(value, "%s", git_config_bool(key_, value_)
-					     ? "true" : "false");
-		else
-			vptr = value_;
-		seen++;
-		if (dup_error) {
-			error("More than one value for the key %s: %s",
-			      key_, vptr);
-		}
-		else
-			printf("%s\n", vptr);
+			  regexec(regexp, value_, 0, NULL, 0)))
+		return 0;
+
+	if (show_keys)
+		printf("%s ", key_);
+	if (seen && !do_all)
+		dup_error = 1;
+	if (type == T_INT)
+		sprintf(value, "%d", git_config_int(key_, value_));
+	else if (type == T_BOOL)
+		vptr = git_config_bool(key_, value_) ? "true" : "false";
+	else
+		vptr = value_;
+	seen++;
+	if (dup_error) {
+		error("More than one value for the key %s: %s",
+				key_, vptr);
 	}
+	else
+		printf("%s\n", vptr);
+
 	return 0;
 }
 
Previous: Junio C Hamano
Message 5 of 5 in “repo-config: support --get-regexp and fix crash”
  1. repo-config: support --get-regexp and fix crashJohannes Schindelin, May 2, 2006
  2. Junio C HamanoMay 2, 2006
  3. Johannes SchindelinMay 3, 2006
  4. Junio C HamanoMay 3, 2006
  5. Johannes SchindelinMay 3, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.