Skip to contentSkip to conversation

Define 'crlf' attribute.

PATCH In review Junio C Hamano 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 Define 'crlf' attribute.

This defines the semantics of 'crlf' attribute as an example. When a path has this attribute unset (i.e. '!crlf'), autocrlf line-end conversion is not applied.

Eventually we would want to let users to build a pipeline of processing to munge blob data to filesystem format (and in the other direction) based on combination of attributes, and at that point the mechanism in convert_to_{git,working_tree}() that looks at 'crlf' attribute needs to be enhanced. Perhaps the existing 'crlf' would become the first step in the input chain, and the last step in the output chain.

---
 attr.c          |   18 ++++++++++++++++++
 convert.c       |   49 ++++++++++++++++++++++++++++++++++++++++++-------
 t/t0020-crlf.sh |   24 ++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 7 deletions(-)
attr.c +18 -0
index bdbc4a3..d35ae9e 100644
@@ -299,3 +299,21 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check)
 		rem = fill(path, pathlen, stk, check, num, rem);
 	return 0;
 }
+
+static void setup_binary_check(struct git_attr_check *check)
+{
+	static struct git_attr *attr_binary;
+
+	if (!attr_binary)
+		attr_binary = git_attr("binary", 6);
+	check->attr = attr_binary;
+}
+
+int git_path_is_binary(const char *path)
+{
+	struct git_attr_check attr_binary_check;
+
+	setup_binary_check(&attr_binary_check);
+	return (!git_checkattr(path, 1, &attr_binary_check) &&
+		(0 < attr_binary_check.isset));
+}
convert.c +42 -7

73 lines not on this page · raw message

t/t0020-crlf.sh +24 -0
index 723b29a..600dcd3 100755
@@ -214,4 +214,28 @@ test_expect_success 'apply patch --index (autocrlf=true)' '
 	}
 '
 
+test_expect_success '.gitattributes says two is binary' '
+
+	echo "two !crlf" >.gitattributes &&
+	rm -f tmp one dir/two &&
+	git repo-config core.autocrlf true &&
+	git read-tree --reset -u HEAD &&
+
+	if remove_cr dir/two >/dev/null
+	then
+		echo "Huh?"
+		false
+	else
+		: happy
+	fi &&
+
+	if remove_cr one >/dev/null
+	then
+		: happy
+	else
+		echo "Huh?"
+		false
+	fi
+'
+
 test_done
Signature · 1 line
1.5.1.1.784.g95e2
#1 lore raw

Hi,

Quoted 4 lines · Junio C Hamano
attr.c +0 -0
index bdbc4a3..d35ae9e 100644

attr.c int git_checkattr(const char *path, int num, struct git_attr_check *check) · line 319

Quoted 10 lines
attr.c +9 -0
[...]
+
+int git_path_is_binary(const char *path)
+{
+	struct git_attr_check attr_binary_check;
+
+	setup_binary_check(&attr_binary_check);
+	return (!git_checkattr(path, 1, &attr_binary_check) &&
+		(0 < attr_binary_check.isset));
+}

This function is not declared in a header file, and ...

Quoted 10 lines
convert.c +5 -0
index 898bfe3..20c744a 100644
[...]
+
+static int git_path_is_binary(const char *path)
+{
+	struct git_attr_check attr_crlf_check;
+

convert.c int convert_to_working_tree(const char *path, char **bufp, unsigned long *sizep) · line 207

Quoted 10 lines
convert.c +10 -0
+	setup_crlf_check(&attr_crlf_check);
+
+	/*
+	 * If crlf is not mentioned, default to autocrlf;
+	 * disable autocrlf only when crlf attribute is explicitly
+	 * unset.
+	 */
+	return (!git_checkattr(path, 1, &attr_crlf_check) &&
+		(0 == attr_crlf_check.isset));
+}

... here you have a function of the _same_ name, which does something subtly different: it checks for "crlf" instead of "binary".

Perhaps you wanted the change to attr.c at a later stage, and the function in convert.c should be renamed to "path_wants_crlf()"?

[Reading 3/3 revealed that indeed, the 18 lines in attr.c were unwanted.]

Ciao,
Dscho