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

[PATCH 2/4] convert.c: restructure the attribute checking part.

From
Junio C Hamano <junkio@cox.net>
Date
Apr 21, 2007, 10:40 UTC
Message-ID
<1177152059853-git-send-email-junkio@cox.net>
In-Reply-To
<11771520591529-git-send-email-junkio@cox.net>

This separates the checkattr() call and interpretation of the returned value specific to the 'crlf' attribute into separate routines, so that we can run a single call to checkattr() to check for more than one attributes, and then interprete what the returned settings mean separately.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 convert.c |   48 ++++++++++++++++++++++++++++--------------------
 1 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/convert.c b/convert.c
index 742b895..37239ac 100644
--- a/convert.c
+++ b/convert.c
@@ -200,7 +200,7 @@ static char *crlf_to_worktree(const char *path, const char *src, unsigned long *
 	return buffer;
 }
 
-static void setup_crlf_check(struct git_attr_check *check)
+static void setup_convert_check(struct git_attr_check *check)
 {
 	static struct git_attr *attr_crlf;
 
@@ -209,33 +209,41 @@ static void setup_crlf_check(struct git_attr_check *check)
 	check->attr = attr_crlf;
 }
 
-static int git_path_check_crlf(const char *path)
+static int git_path_check_crlf(const char *path, struct git_attr_check *check)
 {
-	struct git_attr_check attr_crlf_check;
-
-	setup_crlf_check(&attr_crlf_check);
-
-	if (!git_checkattr(path, 1, &attr_crlf_check)) {
-		const char *value = attr_crlf_check.value;
-		if (ATTR_TRUE(value))
-			return CRLF_TEXT;
-		else if (ATTR_FALSE(value))
-			return CRLF_BINARY;
-		else if (ATTR_UNSET(value))
-			;
-		else if (!strcmp(value, "input"))
-			return CRLF_INPUT;
-		/* fallthru */
-	}
+	const char *value = check->value;
+
+	if (ATTR_TRUE(value))
+		return CRLF_TEXT;
+	else if (ATTR_FALSE(value))
+		return CRLF_BINARY;
+	else if (ATTR_UNSET(value))
+		;
+	else if (!strcmp(value, "input"))
+		return CRLF_INPUT;
 	return CRLF_GUESS;
 }
 
 char *convert_to_git(const char *path, const char *src, unsigned long *sizep)
 {
-	return crlf_to_git(path, src, sizep, git_path_check_crlf(path));
+	struct git_attr_check check[1];
+	int crlf = CRLF_GUESS;
+
+	setup_convert_check(check);
+	if (!git_checkattr(path, 1, check)) {
+		crlf = git_path_check_crlf(path, check);
+	}
+	return crlf_to_git(path, src, sizep, crlf);
 }
 
 char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep)
 {
-	return crlf_to_worktree(path, src, sizep, git_path_check_crlf(path));
+	struct git_attr_check check[1];
+	int crlf = CRLF_GUESS;
+
+	setup_convert_check(check);
+	if (!git_checkattr(path, 1, check)) {
+		crlf = git_path_check_crlf(path, check);
+	}
+	return crlf_to_worktree(path, src, sizep, crlf);
 }
-- 
1.5.1.1.948.g9f6f
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 22 in “External 'filter' attributes and drivers”
  1. 0/4 External 'filter' attributes and driversJunio C Hamano, Apr 21, 2007
  2. 1/4 Simplify calling of CR/LF conversion routinesJunio C Hamano, Apr 21, 2007
  3. 2/4 convert.c: restructure the attribute checking part.Junio C Hamano, Apr 21, 2007
  4. 3/4 lockfile: record the primary process.Junio C Hamano, Apr 21, 2007
  5. 4/4 Add 'filter' attribute and external filter driver definition.Junio C Hamano, Apr 21, 2007
  6. Shawn O. PearceApr 22, 2007
  7. Junio C HamanoApr 22, 2007
  8. Shawn O. PearceApr 22, 2007
  9. David LangApr 22, 2007
  10. Junio C HamanoApr 22, 2007
  11. David LangApr 22, 2007
  12. David LangApr 22, 2007
  13. Junio C HamanoApr 22, 2007
  14. David LangApr 22, 2007
  15. Nicolas PitreApr 22, 2007
  16. David LangApr 22, 2007
  17. Linus TorvaldsApr 22, 2007
  18. Junio C HamanoApr 22, 2007
  19. Alex RiesenApr 21, 2007
  20. David LangApr 22, 2007
  21. Shawn O. PearceApr 22, 2007
  22. David LangApr 22, 2007

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.