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

[PATCH 3/5] xdiff: introduce XDF_INEXACT_MATCH

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 20, 2012, 02:16 UTC
Message-ID
<1329704188-9955-4-git-send-email-gitster@pobox.com>
In-Reply-To
<1329704188-9955-1-git-send-email-gitster@pobox.com>

The XDF_WHITESPACE_FLAGS mask is used to decide if a simple memcmp() is sufficient to tell if two lines are the same for the purpose of producing diff. In the current code, only options in the ignore-whitespace family happen to call for a matching logic that is more complex than memcmp(), but when we add new options, e.g. ignore-case, it will become apparent that the mask is misnamed.

Introduce XDF_INEXACT_MATCH mask to express its true meaning: when any of these bits are set, we may need to inspect the contents of the two lines that are not exactly the same, as we may still consider them "matching".

The XDF_WHITESPACE_FLAGS will become useful again in a later patch in the series and its definition is kept.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c         |    2 +-
 xdiff/xdiff.h  |    6 +++++-
 xdiff/xutils.c |    4 ++--
 3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/diff.c b/diff.c
index 52cda7a..87b2ec1 100644
--- a/diff.c
+++ b/diff.c
@@ -2142,7 +2142,7 @@ static void builtin_diff(const char *name_a,
 		struct emit_callback ecbdata;
 		const struct userdiff_funcname *pe;
 
-		if (!DIFF_XDL_TST(o, WHITESPACE_FLAGS) || must_show_header) {
+		if (!DIFF_XDL_TST(o, INEXACT_MATCH) || must_show_header) {
 			fprintf(o->file, "%s", header.buf);
 			strbuf_reset(&header);
 		}
diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
index 09215af..48793f9 100644
--- a/xdiff/xdiff.h
+++ b/xdiff/xdiff.h
@@ -32,7 +32,11 @@ extern "C" {
 #define XDF_IGNORE_WHITESPACE (1 << 2)
 #define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3)
 #define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4)
-#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)
+#define XDF_WHITESPACE_FLAGS \
+	(XDF_IGNORE_WHITESPACE | \
+	 XDF_IGNORE_WHITESPACE_CHANGE | \
+	 XDF_IGNORE_WHITESPACE_AT_EOL)
+#define XDF_INEXACT_MATCH XDF_WHITESPACE_FLAGS
 
 #define XDF_PATIENCE_DIFF (1 << 5)
 #define XDF_HISTOGRAM_DIFF (1 << 6)
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 0de084e..aa6de74 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -176,7 +176,7 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
 
 	if (s1 == s2 && !memcmp(l1, l2, s1))
 		return 1;
-	if (!(flags & XDF_WHITESPACE_FLAGS))
+	if (!(flags & XDF_INEXACT_MATCH))
 		return 0;
 
 	i1 = 0;
@@ -281,7 +281,7 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
 	unsigned long ha = 5381;
 	char const *ptr = *data;
 
-	if (flags & XDF_WHITESPACE_FLAGS)
+	if (flags & XDF_INEXACT_MATCH)
 		return xdl_hash_record_with_whitespace(data, top, flags);
 
 	for (; ptr < top && *ptr != '\n'; ptr++) {
-- 
1.7.9.1.265.g25f75
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 14 in “diff --ignore-case”
  1. 0/5 diff --ignore-caseJunio C Hamano, Feb 20, 2012
  2. 1/5 xdiff: remove XDL_PATCH_* macrosJunio C Hamano, Feb 20, 2012
  3. 2/5 xdiff: PATIENCE/HISTOGRAM are not independent option bitsJunio C Hamano, Feb 20, 2012
  4. 3/5 xdiff: introduce XDF_INEXACT_MATCHJunio C Hamano, Feb 20, 2012
  5. 4/5 xdiff: introduce XDF_IGNORE_CASEJunio C Hamano, Feb 20, 2012
  6. Jakub NarebskiFeb 22, 2012
  7. 5/5 diff: --ignore-caseJunio C Hamano, Feb 20, 2012
  8. 6/5 diff -iJunio C Hamano, Feb 20, 2012
  9. Johannes SixtFeb 20, 2012
  10. Junio C HamanoFeb 20, 2012
  11. Thomas RastFeb 20, 2012
  12. Junio C HamanoFeb 20, 2012
  13. Chris LeongFeb 20, 2012
  14. Re* [PATCH 0/5] diff --ignore-caseJunio C Hamano, Feb 21, 2012

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.