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

[PATCH 1/2] diffcore-pickaxe: refactor !one or !two case in diff_grep

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 24, 2019, 15:22 UTC
Message-ID
<20190424152215.16251-2-avarab@gmail.com>
In-Reply-To
<20190424102609.GA19697@vmlxhi-102.adit-jv.com>

Refactor the code around processing an added (!one) or deleted (!two) file in diff_grep, which is used by the -G option.

This makes a subsequent change where we'd like to munge the "one" or "two" "ptr" smaller. While we're at it let's add an assert that "one" and "two" can't both be false at the same time, which is always the case.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 diffcore-pickaxe.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index a9c6d60df2..3c6416bfe2 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -45,12 +45,16 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
 	xpparam_t xpp;
 	xdemitconf_t xecfg;
 
-	if (!one)
-		return !regexec_buf(regexp, two->ptr, two->size,
-				    1, &regmatch, 0);
-	if (!two)
-		return !regexec_buf(regexp, one->ptr, one->size,
-				    1, &regmatch, 0);
+	if (!one || !two) {
+		mmfile_t *which = one ? one : two;
+		int ret;
+		char *string = which->ptr;
+		size_t size = which->size;
+		assert(!(!one && !two));
+		ret = !regexec_buf(regexp, string, size,
+				   1, &regmatch, 0);
+		return ret;
+	}
 
 	/*
 	 * We have both sides; need to run textual diff and see if
-- 
2.21.0.593.g511ec345e18
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 3 of 14 in “Multi-line 'git log -G<regex>'?”
  1. Eugeniu RoscaApr 24, 2019
  2. 0/2 diffcore-pickaxe: implement --pickaxe-raw-diffÆvar Arnfjörð Bjarmason, Apr 24, 2019
  3. 1/2 diffcore-pickaxe: refactor !one or !two case in diff_grepÆvar Arnfjörð Bjarmason, Apr 24, 2019
  4. 2/2 diffcore-pickaxe: add --pickaxe-raw-diff for use with -GÆvar Arnfjörð Bjarmason, Apr 24, 2019
  5. Ævar Arnfjörð BjarmasonApr 24, 2019
  6. Eugeniu RoscaApr 24, 2019
  7. Ævar Arnfjörð BjarmasonApr 24, 2019
  8. Junio C HamanoApr 25, 2019
  9. Ævar Arnfjörð BjarmasonApr 25, 2019
  10. Eugeniu RoscaMay 3, 2019
  11. Eugeniu RoscaMay 3, 2019
  12. Eugeniu RoscaApr 25, 2019
  13. Ævar Arnfjörð BjarmasonApr 25, 2019
  14. Jeff KingMay 3, 2019

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.