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

Re: [PATCH v2 2/3] diffcore-pickaxe: remove fill_one()

From
Jeff King <peff@peff.net>
Date
Apr 5, 2013, 00:08 UTC
Message-ID
<20130405000847.GB27775@sigill.intra.peff.net>
In-Reply-To
<004969e2ef9bb8017ce66e36b60a447ab35068d0.1365105971.git.simon@ruderich.org>
On Thu, Apr 04, 2013 at 10:21:08PM +0200, Simon Ruderich wrote:
Show 18 quoted lines
> From: Jeff King <peff@peff.net>
> 
> fill_one is _almost_ identical to just calling fill_textconv; the
> exception is that for the !DIFF_FILE_VALID case, fill_textconv gives us
> an empty buffer rather than a NULL one.
> 
> Signed-off-by: Simon Ruderich <simon@ruderich.org>
> ---
> On Thu, Apr 04, 2013 at 01:49:42PM -0400, Jeff King wrote:
> > [snip]
> >
> > What do you think of something like this on top (this is on top of your
> > patches, but again, I would suggest re-ordering your two, so it would
> > come as patch 2/3):
> 
> Hello Jeff,
> 
> That's a good idea. I've added your patch, thanks. Signed-off?

Thanks. The whole series looks good to me. I think Junio's proposed cleanup is a good direction, too, but I don't mind if that comes on top.

Here's an updated version of the patch with my signoff; I also expanded on the commit message a little bit. The patch text is the same (I'm just including the whole patch for Junio's convenience in applying).

-Peff
-- >8 --
Subject: [PATCH] diffcore-pickaxe: remove fill_one()

fill_one is _almost_ identical to just calling fill_textconv; the exception is that for the !DIFF_FILE_VALID case, fill_textconv gives us an empty buffer rather than a NULL one. Since we currently use the NULL pointer as a signal that the file is not present on one side of the diff, we must now switch to using DIFF_FILE_VALID to make the same check.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Simon Ruderich <simon@ruderich.org>
---
 diffcore-pickaxe.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 8f955f8..3124f49 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -74,16 +74,6 @@ static void diffgrep_consume(void *priv, char *line, unsigned long len)
 	line[len] = hold;
 }
 
-static void fill_one(struct diff_filespec *one,
-		     mmfile_t *mf, struct userdiff_driver *textconv)
-{
-	if (DIFF_FILE_VALID(one)) {
-		mf->size = fill_textconv(textconv, one, &mf->ptr);
-	} else {
-		memset(mf, 0, sizeof(*mf));
-	}
-}
-
 static int diff_grep(struct diff_filepair *p, struct diff_options *o,
 		     regex_t *regexp, kwset_t kws)
 {
@@ -99,15 +89,15 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
 	textconv_one = get_textconv(p->one);
 	textconv_two = get_textconv(p->two);
 
-	fill_one(p->one, &mf1, textconv_one);
-	fill_one(p->two, &mf2, textconv_two);
+	mf1.size = fill_textconv(textconv_one, p->one, &mf1.ptr);
+	mf2.size = fill_textconv(textconv_two, p->two, &mf2.ptr);
 
-	if (!mf1.ptr) {
-		if (!mf2.ptr)
+	if (!DIFF_FILE_VALID(p->one)) {
+		if (!DIFF_FILE_VALID(p->two))
 			return 0; /* ignore unmerged */
 		/* created "two" -- does it have what we are looking for? */
 		hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
-	} else if (!mf2.ptr) {
+	} else if (!DIFF_FILE_VALID(p->two)) {
 		/* removed "one" -- did it have what we are looking for? */
 		hit = !regexec(regexp, mf1.ptr, 1, &regmatch, 0);
 	} else {
@@ -224,16 +214,16 @@ static int has_changes(struct diff_filepair *p, struct diff_options *o,
 	if (textconv_one == textconv_two && diff_unmodified_pair(p))
 		return 0;
 
-	fill_one(p->one, &mf1, textconv_one);
-	fill_one(p->two, &mf2, textconv_two);
+	mf1.size = fill_textconv(textconv_one, p->one, &mf1.ptr);
+	mf2.size = fill_textconv(textconv_two, p->two, &mf2.ptr);
 
-	if (!mf1.ptr) {
-		if (!mf2.ptr)
+	if (!DIFF_FILE_VALID(p->one)) {
+		if (!DIFF_FILE_VALID(p->two))
 			ret = 0; /* ignore unmerged */
 		/* created */
 		ret = contains(&mf2, o, regexp, kws) != 0;
 	}
-	else if (!mf2.ptr) /* removed */
+	else if (!DIFF_FILE_VALID(p->two)) /* removed */
 		ret = contains(&mf1, o, regexp, kws) != 0;
 	else
 		ret = contains(&mf1, o, regexp, kws) !=
-- 
1.8.2.rc0.33.gd915649
Previous: Simon RuderichNext: Junio C Hamano
Message 15 of 27 in “[BUG] git log -S not respecting --no-textconv”
  1. Matthieu MoyApr 4, 2013
  2. 1/2 diffcore-pickaxe: respect --no-textconvSimon Ruderich, Apr 4, 2013
  3. Matthieu MoyApr 4, 2013
  4. Jeff KingApr 4, 2013
  5. Junio C HamanoApr 4, 2013
  6. Jeff KingApr 4, 2013
  7. Junio C HamanoApr 4, 2013
  8. 1/3 diffcore-pickaxe: remove unnecessary call to get_textconv()Simon Ruderich, Apr 4, 2013
  9. Junio C HamanoApr 4, 2013
  10. Junio C HamanoApr 4, 2013
  11. Jeff KingApr 4, 2013
  12. Junio C HamanoApr 4, 2013
  13. Simon RuderichApr 5, 2013
  14. 2/3 diffcore-pickaxe: remove fill_one()Simon Ruderich, Apr 4, 2013
  15. Jeff KingApr 5, 2013
  16. Junio C HamanoApr 5, 2013
  17. 1/3 diffcore-pickaxe: port optimization from has_changes() to diff_grep()Junio C Hamano, Apr 5, 2013
  18. 2/3 diffcore-pickaxe: fix leaks in "log -S<block>" and "log -G<pattern>"Junio C Hamano, Apr 5, 2013
  19. 3/3 diffcore-pickaxe: unify setup and teardown code between log -S/-GJunio C Hamano, Apr 5, 2013
  20. Jeff KingApr 5, 2013
  21. Junio C HamanoApr 5, 2013
  22. Jeff KingApr 5, 2013
  23. Junio C HamanoApr 5, 2013
  24. 3/3 diffcore-pickaxe: respect --no-textconvSimon Ruderich, Apr 4, 2013
  25. Matthieu MoyApr 5, 2013
  26. 3/3 diffcore-pickaxe: respect --no-textconvSimon Ruderich, Apr 5, 2013
  27. Junio C HamanoApr 5, 2013

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.