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

[PATCH 2/6] xdiff: factor out is_func_rec()

From
René Scharfe <l.s.r@web.de>
Date
Nov 18, 2017, 18:04 UTC
Message-ID
<4efcd033-ab8d-7b0c-0c2f-8e5b5cdd5e0c@web.de>
In-Reply-To
<790c2344-a71e-7089-9000-f9b37a4a5cd9@web.de>

Add a helper for checking if a given record is a function line. It frees callers from having to deal with the buffer arguments of match_func_rec().

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 xdiff/xemit.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index 6881445e4a..c2d5bd004c 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -121,6 +121,12 @@ static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri,
 	return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv);
 }
 
+static int is_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri)
+{
+	char dummy[1];
+	return match_func_rec(xdf, xecfg, ri, dummy, sizeof(dummy)) >= 0;
+}
+
 struct func_line {
 	long len;
 	char buf[80];
@@ -178,7 +184,6 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
 
 			/* Appended chunk? */
 			if (i1 >= xe->xdf1.nrec) {
-				char dummy[1];
 				long i2 = xch->i2;
 
 				/*
@@ -186,8 +191,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
 				 * a whole function was added.
 				 */
 				while (i2 < xe->xdf2.nrec) {
-					if (match_func_rec(&xe->xdf2, xecfg, i2,
-						dummy, sizeof(dummy)) >= 0)
+					if (is_func_rec(&xe->xdf2, xecfg, i2))
 						goto post_context_calculation;
 					i2++;
 				}
-- 
2.15.0
Previous: René ScharfeNext: René Scharfe
Message 11 of 15 in “show non-empty lines before functions with diff/grep -W”
  1. 0/6 show non-empty lines before functions with diff/grep -WRené Scharfe, Nov 18, 2017
  2. 1/6 t4051: add test for comments preceding function linesRené Scharfe, Nov 18, 2017
  3. Eric SunshineNov 19, 2017
  4. René ScharfeNov 19, 2017
  5. Junio C HamanoNov 20, 2017
  6. René ScharfeNov 20, 2017
  7. Junio C HamanoNov 21, 2017
  8. 3/6 xdiff: show non-empty lines before functions with -WRené Scharfe, Nov 18, 2017
  9. 5/6 grep: update boundary variable for pre-contextRené Scharfe, Nov 18, 2017
  10. 4/6 t7810: improve check of -W with user-defined function linesRené Scharfe, Nov 18, 2017
  11. 2/6 xdiff: factor out is_func_rec()René Scharfe, Nov 18, 2017
  12. 6/6 grep: show non-empty lines before functions with -WRené Scharfe, Nov 18, 2017
  13. Stefan BellerNov 20, 2017
  14. René ScharfeNov 20, 2017
  15. Stefan BellerNov 21, 2017

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.