git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v4 0/4] End-of-line normalization, getting close?
@ 2010-05-13 21:44 Eyvind Bernhardsen
  2010-05-13 21:44 ` [PATCH v4 1/4] autocrlf: Make it work also for un-normalized repositories Eyvind Bernhardsen
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eyvind Bernhardsen @ 2010-05-13 21:44 UTC (permalink / raw
  To: git; +Cc: msysGit, Linus Torvalds, Junio C Hamano, Finn Arne Gangstad

Here's the latest series.  Linus's suggested attribute names were a
lot saner than mine, so I've now split the "crlf" attribute into
"crlf" and "eol", and the "crlf" attribute gets renamed to "text" in
the final commit.  I dropped the patch that renamed autocrlf.

git-cvsserver gets a bit more love in this round (particularly the
documentation), so I think it should work as well as it did before.
Not too happy with the logic duplication, though.

Patch 1/4 is still "safe autocrlf" from Finn Arne, just for
convenience.

All in all, I think this looks pretty good now.
-- 
Eyvind


Eyvind Bernhardsen (3):
  Add tests for per-repository eol normalization
  Add per-repository eol normalization
  Rename the "crlf" attribute "text"

Finn Arne Gangstad (1):
  autocrlf: Make it work also for un-normalized repositories

 Documentation/config.txt        |   20 +++--
 Documentation/git-cvsserver.txt |   13 +--
 Documentation/gitattributes.txt |  164 +++++++++++++++++++++++++++++++--------
 attr.c                          |    2 +-
 cache.h                         |    9 ++-
 config.c                        |    2 +-
 convert.c                       |  155 +++++++++++++++++++++++++++++++------
 environment.c                   |    2 +-
 git-cvsserver.perl              |   13 ++-
 t/t0020-crlf.sh                 |   52 ++++++++++++
 t/t0025-crlf-auto.sh            |  156 +++++++++++++++++++++++++++++++++++++
 11 files changed, 507 insertions(+), 81 deletions(-)
 create mode 100755 t/t0025-crlf-auto.sh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 1/4] autocrlf: Make it work also for un-normalized repositories
  2010-05-13 21:44 [PATCH v4 0/4] End-of-line normalization, getting close? Eyvind Bernhardsen
@ 2010-05-13 21:44 ` Eyvind Bernhardsen
  2010-05-13 21:44 ` [PATCH v4 2/4] Add tests for per-repository eol normalization Eyvind Bernhardsen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eyvind Bernhardsen @ 2010-05-13 21:44 UTC (permalink / raw
  To: git; +Cc: msysGit, Linus Torvalds, Junio C Hamano, Finn Arne Gangstad

From: Finn Arne Gangstad <finnag@pvv.org>

Previously, autocrlf would only work well for normalized
repositories. Any text files that contained CRLF in the repository
would cause problems, and would be modified when handled with
core.autocrlf set.

Change autocrlf to not do any conversions to files that in the
repository already contain a CR. git with autocrlf set will never
create such a file, or change a LF only file to contain CRs, so the
(new) assumption is that if a file contains a CR, it is intentional,
and autocrlf should not change that.

The following sequence should now always be a NOP even with autocrlf
set (assuming a clean working directory):

git checkout <something>
touch *
git add -A .    (will add nothing)
git commit      (nothing to commit)

Previously this would break for any text file containing a CR.

Some of you may have been folowing Eyvind's excellent thread about
trying to make end-of-line translation in git a bit smoother.

I decided to attack the problem from a different angle: Is it possible
to make autocrlf behave non-destructively for all the previous problem cases?

Stealing the problem from Eyvind's initial mail (paraphrased and
summarized a bit):

1. Setting autocrlf globally is a pain since autocrlf does not work well
   with CRLF in the repo
2. Setting it in individual repos is hard since you do it "too late"
   (the clone will get it wrong)
3. If someone checks in a file with CRLF later, you get into problems again
4. If a repository once has contained CRLF, you can't tell autocrlf
   at which commit everything is sane again
5. autocrlf does needless work if you know that all your users want
   the same EOL style.

I belive that this patch makes autocrlf a safe (and good) default
setting for Windows, and this solves problems 1-4 (it solves 2 by being
set by default, which is early enough for clone).

I implemented it by looking for CR charactes in the index, and
aborting any conversion attempt if this is found.

Signed-off-by: Finn Arne Gangstad <finag@pvv.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>
---
 convert.c       |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 t/t0020-crlf.sh |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/convert.c b/convert.c
index 4f8fcb7..46622b0 100644
--- a/convert.c
+++ b/convert.c
@@ -120,6 +120,43 @@ static void check_safe_crlf(const char *path, int action,
 	}
 }
 
+static int has_cr_in_index(const char *path)
+{
+	int pos, len;
+	unsigned long sz;
+	enum object_type type;
+	void *data;
+	int has_cr;
+	struct index_state *istate = &the_index;
+
+	len = strlen(path);
+	pos = index_name_pos(istate, path, len);
+	if (pos < 0) {
+		/*
+		 * We might be in the middle of a merge, in which
+		 * case we would read stage #2 (ours).
+		 */
+		int i;
+		for (i = -pos - 1;
+		     (pos < 0 && i < istate->cache_nr &&
+		      !strcmp(istate->cache[i]->name, path));
+		     i++)
+			if (ce_stage(istate->cache[i]) == 2)
+				pos = i;
+	}
+	if (pos < 0)
+		return 0;
+	data = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);
+	if (!data || type != OBJ_BLOB) {
+		free(data);
+		return 0;
+	}
+
+	has_cr = memchr(data, '\r', sz) != NULL;
+	free(data);
+	return has_cr;
+}
+
 static int crlf_to_git(const char *path, const char *src, size_t len,
                        struct strbuf *buf, int action, enum safe_crlf checksafe)
 {
@@ -145,6 +182,13 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
 		 */
 		if (is_binary(len, &stats))
 			return 0;
+
+		/*
+		 * If the file in the index has any CR in it, do not convert.
+		 * This is the new safer autocrlf handling.
+		 */
+		if (has_cr_in_index(path))
+			return 0;
 	}
 
 	check_safe_crlf(path, action, &stats, checksafe);
@@ -203,6 +247,11 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,
 		return 0;
 
 	if (action == CRLF_GUESS) {
+		/* If we have any CR or CRLF line endings, we do not touch it */
+		/* This is the new safer autocrlf-handling */
+		if (stats.cr > 0 || stats.crlf > 0)
+			return 0;
+
 		/* If we have any bare CR characters, we're not going to touch it */
 		if (stats.cr != stats.crlf)
 			return 0;
diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh
index c3e7e32..234a94f 100755
--- a/t/t0020-crlf.sh
+++ b/t/t0020-crlf.sh
@@ -453,5 +453,57 @@ test_expect_success 'invalid .gitattributes (must not crash)' '
 	git diff
 
 '
+# Some more tests here to add new autocrlf functionality.
+# We want to have a known state here, so start a bit from scratch
+
+test_expect_success 'setting up for new autocrlf tests' '
+	git config core.autocrlf false &&
+	git config core.safecrlf false &&
+	rm -rf .????* * &&
+	for w in I am all LF; do echo $w; done >alllf &&
+	for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
+	for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
+	git add -A . &&
+	git commit -m "alllf, allcrlf and mixed only" &&
+	git tag -a -m "message" autocrlf-checkpoint
+'
+
+test_expect_success 'report no change after setting autocrlf' '
+	git config core.autocrlf true &&
+	touch * &&
+	git diff --exit-code
+'
+
+test_expect_success 'files are clean after checkout' '
+	rm * &&
+	git checkout -f &&
+	git diff --exit-code
+'
+
+cr_to_Q_no_NL () {
+    tr '\015' Q | tr -d '\012'
+}
+
+test_expect_success 'LF only file gets CRLF with autocrlf' '
+	test "$(cr_to_Q_no_NL < alllf)" = "IQamQallQLFQ"
+'
+
+test_expect_success 'Mixed file is still mixed with autocrlf' '
+	test "$(cr_to_Q_no_NL < mixed)" = "OhhereisCRLFQintext"
+'
+
+test_expect_success 'CRLF only file has CRLF with autocrlf' '
+	test "$(cr_to_Q_no_NL < allcrlf)" = "IQamQallQCRLFQ"
+'
+
+test_expect_success 'New CRLF file gets LF in repo' '
+	tr -d "\015" < alllf | append_cr > alllf2 &&
+	git add alllf2 &&
+	git commit -m "alllf2 added" &&
+	git config core.autocrlf false &&
+	rm * &&
+	git checkout -f &&
+	test_cmp alllf alllf2
+'
 
 test_done
-- 
1.7.1.5.gd739a

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/4] Add tests for per-repository eol normalization
  2010-05-13 21:44 [PATCH v4 0/4] End-of-line normalization, getting close? Eyvind Bernhardsen
  2010-05-13 21:44 ` [PATCH v4 1/4] autocrlf: Make it work also for un-normalized repositories Eyvind Bernhardsen
@ 2010-05-13 21:44 ` Eyvind Bernhardsen
  2010-05-13 21:44 ` [PATCH v4 3/4] Add " Eyvind Bernhardsen
  2010-05-13 21:44 ` [PATCH v4 4/4] Rename the "crlf" attribute "text" Eyvind Bernhardsen
  3 siblings, 0 replies; 5+ messages in thread
From: Eyvind Bernhardsen @ 2010-05-13 21:44 UTC (permalink / raw
  To: git; +Cc: msysGit, Linus Torvalds, Junio C Hamano, Finn Arne Gangstad

Signed-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>
---
 t/t0025-crlf-auto.sh |  143 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 143 insertions(+), 0 deletions(-)
 create mode 100755 t/t0025-crlf-auto.sh

diff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh
new file mode 100755
index 0000000..360117c
--- /dev/null
+++ b/t/t0025-crlf-auto.sh
@@ -0,0 +1,143 @@
+#!/bin/sh
+
+test_description='CRLF conversion'
+
+. ./test-lib.sh
+
+has_cr() {
+	tr '\015' Q <"$1" | grep Q >/dev/null
+}
+
+test_expect_success setup '
+
+	git config core.autocrlf false &&
+
+	for w in Hello world how are you; do echo $w; done >one &&
+	for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >two &&
+	for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >three &&
+	git add . &&
+
+	git commit -m initial &&
+
+	one=`git rev-parse HEAD:one` &&
+	two=`git rev-parse HEAD:two` &&
+
+	for w in Some extra lines here; do echo $w; done >>one &&
+	git diff >patch.file &&
+	patched=`git hash-object --stdin <one` &&
+	git read-tree --reset -u HEAD &&
+
+	echo happy.
+'
+
+test_expect_success 'default settings cause no changes' '
+
+	rm -f .gitattributes tmp one two &&
+	git read-tree --reset -u HEAD &&
+
+	! has_cr one &&
+	has_cr two &&
+	onediff=`git diff one` &&
+	twodiff=`git diff two` &&
+	test -z "$onediff" -a -z "$twodiff"
+'
+
+test_expect_failure 'crlf=true causes a CRLF file to be normalized' '
+
+	rm -f .gitattributes tmp one two &&
+	echo "two crlf" > .gitattributes &&
+	git read-tree --reset -u HEAD &&
+
+	# Note, "normalized" means that git will normalize it if added
+	has_cr two &&
+	twodiff=`git diff two` &&
+	test -n "$twodiff"
+'
+
+test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
+
+	rm -f .gitattributes tmp one two &&
+	git config core.autocrlf false &&
+	echo "one eol=crlf" > .gitattributes &&
+	git read-tree --reset -u HEAD &&
+
+	has_cr one &&
+	onediff=`git diff one` &&
+	test -z "$onediff"
+'
+
+test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
+
+	rm -f .gitattributes tmp one two &&
+	git config core.autocrlf input &&
+	echo "one eol=crlf" > .gitattributes &&
+	git read-tree --reset -u HEAD &&
+
+	has_cr one &&
+	onediff=`git diff one` &&
+	test -z "$onediff"
+'
+
+test_expect_failure 'eol=lf gives a normalized file LFs with autocrlf=true' '
+
+	rm -f .gitattributes tmp one two &&
+	git config core.autocrlf true &&
+	echo "one eol=lf" > .gitattributes &&
+	git read-tree --reset -u HEAD &&
+
+	! has_cr one &&
+	onediff=`git diff one` &&
+	test -z "$onediff"
+'
+
+test_expect_success 'autocrlf=true does not normalize CRLF files' '
+
+	rm -f .gitattributes tmp one two &&
+	git config core.autocrlf true &&
+	git read-tree --reset -u HEAD &&
+
+	has_cr one &&
+	has_cr two &&
+	onediff=`git diff one` &&
+	twodiff=`git diff two` &&
+	test -z "$onediff" -a -z "$twodiff"
+'
+
+test_expect_failure 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '
+
+	rm -f .gitattributes tmp one two &&
+	git config core.autocrlf true &&
+	echo "* crlf=auto" > .gitattributes &&
+	git read-tree --reset -u HEAD &&
+
+	has_cr one &&
+	has_cr two &&
+	onediff=`git diff one` &&
+	twodiff=`git diff two` &&
+	test -z "$onediff" -a -n "$twodiff"
+'
+
+test_expect_success 'crlf=auto, autocrlf=true does not normalize binary files' '
+
+	rm -f .gitattributes tmp one two three &&
+	git config core.autocrlf true &&
+	echo "* crlf=auto" > .gitattributes &&
+	git read-tree --reset -u HEAD &&
+
+	! has_cr three &&
+	threediff=`git diff three` &&
+	test -z "$threediff"
+'
+
+test_expect_failure 'eol=crlf _does_ normalize binary files' '
+
+	rm -f .gitattributes tmp one two three &&
+	echo "three eol=crlf" > .gitattributes &&
+	git read-tree --reset -u HEAD &&
+
+	has_cr three &&
+	threediff=`git diff three` &&
+	test -z "$threediff"
+'
+
+test_done
-- 
1.7.1.5.gd739a

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 3/4] Add per-repository eol normalization
  2010-05-13 21:44 [PATCH v4 0/4] End-of-line normalization, getting close? Eyvind Bernhardsen
  2010-05-13 21:44 ` [PATCH v4 1/4] autocrlf: Make it work also for un-normalized repositories Eyvind Bernhardsen
  2010-05-13 21:44 ` [PATCH v4 2/4] Add tests for per-repository eol normalization Eyvind Bernhardsen
@ 2010-05-13 21:44 ` Eyvind Bernhardsen
  2010-05-13 21:44 ` [PATCH v4 4/4] Rename the "crlf" attribute "text" Eyvind Bernhardsen
  3 siblings, 0 replies; 5+ messages in thread
From: Eyvind Bernhardsen @ 2010-05-13 21:44 UTC (permalink / raw
  To: git; +Cc: msysGit, Linus Torvalds, Junio C Hamano, Finn Arne Gangstad

Change the semantics of the "crlf" attribute so that it enables
end-of-line normalization when it is set, regardless of "core.autocrlf".

Add a new setting for "crlf": "auto", which enables end-of-line
conversion but does not override the automatic text file detection.

Add a new attribute "eol" with possible values "crlf" and "lf".  When
set, this attribute enables normalization and forces git to use CRLF or
LF line endings in the working directory, respectively.

The line ending style to be used for normalized text files in the
working directory is set using "core.autocrlf".  When it is set to
"true", CRLFs are used in the working directory; when set to "input" or
"false", LFs are used.

Signed-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>
---
 Documentation/config.txt        |    4 +-
 Documentation/gitattributes.txt |  153 +++++++++++++++++++++++++++++++--------
 cache.h                         |    9 ++-
 config.c                        |    2 +-
 convert.c                       |  117 +++++++++++++++++++++---------
 environment.c                   |    2 +-
 t/t0025-crlf-auto.sh            |   12 ++--
 7 files changed, 223 insertions(+), 76 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 92f851e..4d3c472 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -208,8 +208,8 @@ core.autocrlf::
 	based on the file's contents.  See linkgit:gitattributes[5].
 
 core.safecrlf::
-	If true, makes git check if converting `CRLF` as controlled by
-	`core.autocrlf` is reversible.  Git will verify if a command
+	If true, makes git check if converting `CRLF` is reversible when
+	end-of-line conversion is active.  Git will verify if a command
 	modifies a file in the work tree either directly or indirectly.
 	For example, committing a file followed by checking out the
 	same file should yield the original file in the work tree.  If
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index d892e64..c71d883 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -95,50 +95,139 @@ repository upon 'git add' and 'git commit'.
 `crlf`
 ^^^^^^
 
-This attribute controls the line-ending convention.
+This attribute enables and controls end-of-line normalization.  When a
+text file is normalized, its line endings are converted to LF in the
+repository.  To control what line ending style is used in the working
+directory, use the `eol` attribute for a single file and the
+`core.autocrlf` configuration variable for all text files.
 
 Set::
 
-	Setting the `crlf` attribute on a path is meant to mark
-	the path as a "text" file.  'core.autocrlf' conversion
-	takes place without guessing the content type by
-	inspection.
+	Setting the `crlf` attribute on a path enables end-of-line
+	normalization and marks the path as a text file.  End-of-line
+	conversion takes place without guessing the content type.
 
 Unset::
 
 	Unsetting the `crlf` attribute on a path tells git not to
 	attempt any end-of-line conversion upon checkin or checkout.
 
+Set to string value "auto"::
+
+	When `crlf` is set to "auto", the path is marked for automatic
+	end-of-line normalization.  If git decides that the content is
+	text, its line endings are normalized to LF on checkin.
+
 Unspecified::
 
-	Unspecified `crlf` attribute tells git to apply the
-	`core.autocrlf` conversion when the file content looks
-	like text.
+	If the `crlf` attribute is unspecified, git uses the `eol`
+	attribute and the `core.autocrlf` configuration variable to
+	determine if the file should be converted.
 
-Set to string value "input"::
+Any other value causes git to act as if `crlf` has been left
+unspecified.
 
-	This is similar to setting the attribute to `true`, but
-	also forces git to act as if `core.autocrlf` is set to
-	`input` for the path.
+`eol`
+^^^^^
 
-Any other value set to `crlf` attribute is ignored and git acts
-as if the attribute is left unspecified.
+This attribute sets a specific line-ending style to be used in the
+working directory.  It enables end-of-line normalization without any
+content checks, similar to setting the `crlf` attribute.
 
+Set to string value "crlf"::
 
-The `core.autocrlf` conversion
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+	This setting forces git to normalize line endings on checkin
+	and convert them to CRLF when the file is checked out,
+	regardless of `crlf` and `core.autocrlf`.
+
+Set to string value "lf"::
+
+	This setting forces git to normalize line endings to LF on
+	checkin and prevents conversion to CRLF when the file is
+	checked out, regardless of `crlf` and `core.autocrlf`.
+	`crlf=input` is a backwards compatibility alias for `eol=lf`.
+
+End-of-line conversion
+^^^^^^^^^^^^^^^^^^^^^^
 
-If the configuration variable `core.autocrlf` is false, no
-conversion is done.
+While git normally leaves file contents alone, it can be configured to
+normalize line endings to LF in the repository and, optionally, to
+convert them to CRLF when files are checked out.
 
-When `core.autocrlf` is true, it means that the platform wants
-CRLF line endings for files in the working tree, and you want to
-convert them back to the normal LF line endings when checking
-in to the repository.
+Here is an example that will make git normalize .txt, .vcproj and .sh
+files, ensure that .vcproj files have CRLF and .sh files have LF in
+the working directory, and prevent .jpg files from being normalized
+regardless of their content.
 
-When `core.autocrlf` is set to "input", line endings are
-converted to LF upon checkin, but there is no conversion done
-upon checkout.
+------------------------
+*.txt		crlf
+*.vcproj	eol=crlf
+*.sh		eol=lf
+*.jpg		-crlf
+------------------------
+
+Other source code management systems normalize all text files in their
+repositories, and there are two ways to enable similar automatic
+normalization in git.
+
+If you simply want to have CRLF line endings in your working directory
+regardless of the repository you are working with, you can set the
+config variable "core.autocrlf" without changing any attributes.
+
+------------------------
+[core]
+	autocrlf = true
+------------------------
+
+This does not force normalization of all text files, but does ensure
+that text files that you introduce to the repository have their line
+endings normalized to LF when they are added, and that files that are
+already normalized in the repository stay normalized.  You can also
+set `autocrlf` to "input" to have automatic normalization of new text
+files without conversion to CRLF in the working directory.
+
+If you want to interoperate with a source code management system that
+enforces end-of-line normalization, or you simply want all text files
+in your repository to be normalized, you should instead set the `crlf`
+attribute to "auto" for _all_ files.
+
+------------------------
+*	crlf=auto
+------------------------
+
+This ensures that all files that git considers to be text will have
+normalized (LF) line endings in the repository.
+
+NOTE: When `crlf=auto` normalization is enabled in an existing
+repository, any text files containing CRLFs should be normalized.  If
+they are not they will be normalized the next time someone tries to
+change them, causing unfortunate misattribution.  From a clean working
+directory:
+
+-------------------------------------------------
+$ echo "* crlf=auto" >>.gitattributes
+                    # ...this should be the first line in .gitattributes
+$ rm .git/index     # Remove the index to force git to
+$ git reset         # re-scan the working directory
+$ git status        # Show files that will be normalized
+$ git add -u
+$ git add .gitattributes
+$ git commit -m "Introduce end-of-line normalization"
+-------------------------------------------------
+
+If any files that should not be normalized show up in 'git status',
+unset their `crlf` attribute before running 'git add -u'.
+
+------------------------
+manual.pdf	-crlf
+------------------------
+
+Conversely, text files that git does not detect can have normalization
+enabled manually.
+
+------------------------
+weirdchars.txt	crlf
+------------------------
 
 If `core.safecrlf` is set to "true" or "warn", git verifies if
 the conversion is reversible for the current setting of
diff --git a/cache.h b/cache.h
index 5eb0573..d1f669e 100644
--- a/cache.h
+++ b/cache.h
@@ -547,7 +547,6 @@ extern int core_compression_seen;
 extern size_t packed_git_window_size;
 extern size_t packed_git_limit;
 extern size_t delta_base_cache_limit;
-extern int auto_crlf;
 extern int read_replace_refs;
 extern int fsync_object_files;
 extern int core_preload_index;
@@ -561,6 +560,14 @@ enum safe_crlf {
 
 extern enum safe_crlf safe_crlf;
 
+enum auto_crlf {
+	AUTO_CRLF_FALSE = 0,
+	AUTO_CRLF_TRUE = 1,
+	AUTO_CRLF_INPUT = -1,
+};
+
+extern enum auto_crlf auto_crlf;
+
 enum branch_track {
 	BRANCH_TRACK_UNSPECIFIED = -1,
 	BRANCH_TRACK_NEVER = 0,
diff --git a/config.c b/config.c
index 6963fbe..b60a1ff 100644
--- a/config.c
+++ b/config.c
@@ -461,7 +461,7 @@ static int git_default_core_config(const char *var, const char *value)
 
 	if (!strcmp(var, "core.autocrlf")) {
 		if (value && !strcasecmp(value, "input")) {
-			auto_crlf = -1;
+			auto_crlf = AUTO_CRLF_INPUT;
 			return 0;
 		}
 		auto_crlf = git_config_bool(var, value);
diff --git a/convert.c b/convert.c
index 46622b0..98bc029 100644
--- a/convert.c
+++ b/convert.c
@@ -8,13 +8,23 @@
  * This should use the pathname to decide on whether it wants to do some
  * more interesting conversions (automatic gzip/unzip, general format
  * conversions etc etc), but by default it just does automatic CRLF<->LF
- * translation when the "auto_crlf" option is set.
+ * translation when the "crlf" attribute or "auto_crlf" option is set.
  */
 
-#define CRLF_GUESS	(-1)
-#define CRLF_BINARY	0
-#define CRLF_TEXT	1
-#define CRLF_INPUT	2
+enum action {
+	CRLF_GUESS = -1,
+	CRLF_BINARY = 0,
+	CRLF_TEXT,
+	CRLF_INPUT,
+	CRLF_CRLF,
+	CRLF_AUTO,
+};
+
+enum eol {
+	EOL_UNSET,
+	EOL_LF,
+	EOL_CRLF,
+};
 
 struct text_stat {
 	/* NUL, CR, LF and CRLF counts */
@@ -89,13 +99,14 @@ static int is_binary(unsigned long size, struct text_stat *stats)
 	return 0;
 }
 
-static void check_safe_crlf(const char *path, int action,
+static void check_safe_crlf(const char *path, enum action action,
                             struct text_stat *stats, enum safe_crlf checksafe)
 {
 	if (!checksafe)
 		return;
 
-	if (action == CRLF_INPUT || auto_crlf <= 0) {
+	if (action == CRLF_INPUT ||
+	    (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_INPUT)) {
 		/*
 		 * CRLFs would not be restored by checkout:
 		 * check if we'd remove CRLFs
@@ -106,7 +117,8 @@ static void check_safe_crlf(const char *path, int action,
 			else /* i.e. SAFE_CRLF_FAIL */
 				die("CRLF would be replaced by LF in %s.", path);
 		}
-	} else if (auto_crlf > 0) {
+	} else if (action == CRLF_CRLF ||
+		   (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_TRUE)) {
 		/*
 		 * CRLFs would be added by checkout:
 		 * check if we have "naked" LFs
@@ -158,17 +170,18 @@ static int has_cr_in_index(const char *path)
 }
 
 static int crlf_to_git(const char *path, const char *src, size_t len,
-                       struct strbuf *buf, int action, enum safe_crlf checksafe)
+		       struct strbuf *buf, enum action action, enum safe_crlf checksafe)
 {
 	struct text_stat stats;
 	char *dst;
 
-	if ((action == CRLF_BINARY) || !auto_crlf || !len)
+	if (action == CRLF_BINARY ||
+	    (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE) || !len)
 		return 0;
 
 	gather_stats(src, len, &stats);
 
-	if (action == CRLF_GUESS) {
+	if (action == CRLF_AUTO || action == CRLF_GUESS) {
 		/*
 		 * We're currently not going to even try to convert stuff
 		 * that has bare CR characters. Does anybody do that crazy
@@ -183,12 +196,14 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
 		if (is_binary(len, &stats))
 			return 0;
 
-		/*
-		 * If the file in the index has any CR in it, do not convert.
-		 * This is the new safer autocrlf handling.
-		 */
-		if (has_cr_in_index(path))
-			return 0;
+		if (action == CRLF_GUESS) {
+			/*
+			 * If the file in the index has any CR in it, do not convert.
+			 * This is the new safer autocrlf handling.
+			 */
+			if (has_cr_in_index(path))
+				return 0;
+		}
 	}
 
 	check_safe_crlf(path, action, &stats, checksafe);
@@ -201,7 +216,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
 	if (strbuf_avail(buf) + buf->len < len)
 		strbuf_grow(buf, len - buf->len);
 	dst = buf->buf;
-	if (action == CRLF_GUESS) {
+	if (action == CRLF_AUTO || action == CRLF_GUESS) {
 		/*
 		 * If we guessed, we already know we rejected a file with
 		 * lone CR, and we can strip a CR without looking at what
@@ -224,13 +239,13 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
 }
 
 static int crlf_to_worktree(const char *path, const char *src, size_t len,
-                            struct strbuf *buf, int action)
+			    struct strbuf *buf, enum action action)
 {
 	char *to_free = NULL;
 	struct text_stat stats;
 
 	if ((action == CRLF_BINARY) || (action == CRLF_INPUT) ||
-	    auto_crlf <= 0)
+	    (action != CRLF_CRLF && auto_crlf != AUTO_CRLF_TRUE))
 		return 0;
 
 	if (!len)
@@ -246,11 +261,13 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,
 	if (stats.lf == stats.crlf)
 		return 0;
 
-	if (action == CRLF_GUESS) {
-		/* If we have any CR or CRLF line endings, we do not touch it */
-		/* This is the new safer autocrlf-handling */
-		if (stats.cr > 0 || stats.crlf > 0)
-			return 0;
+	if (action == CRLF_AUTO || action == CRLF_GUESS) {
+		if (action == CRLF_GUESS) {
+			/* If we have any CR or CRLF line endings, we do not touch it */
+			/* This is the new safer autocrlf-handling */
+			if (stats.cr > 0 || stats.crlf > 0)
+				return 0;
+		}
 
 		/* If we have any bare CR characters, we're not going to touch it */
 		if (stats.cr != stats.crlf)
@@ -424,11 +441,13 @@ static int read_convert_config(const char *var, const char *value, void *cb)
 static void setup_convert_check(struct git_attr_check *check)
 {
 	static struct git_attr *attr_crlf;
+	static struct git_attr *attr_eol;
 	static struct git_attr *attr_ident;
 	static struct git_attr *attr_filter;
 
 	if (!attr_crlf) {
 		attr_crlf = git_attr("crlf");
+		attr_eol = git_attr("eol");
 		attr_ident = git_attr("ident");
 		attr_filter = git_attr("filter");
 		user_convert_tail = &user_convert;
@@ -437,6 +456,7 @@ static void setup_convert_check(struct git_attr_check *check)
 	check[0].attr = attr_crlf;
 	check[1].attr = attr_ident;
 	check[2].attr = attr_filter;
+	check[3].attr = attr_eol;
 }
 
 static int count_ident(const char *cp, unsigned long size)
@@ -593,9 +613,24 @@ static int git_path_check_crlf(const char *path, struct git_attr_check *check)
 		;
 	else if (!strcmp(value, "input"))
 		return CRLF_INPUT;
+	else if (!strcmp(value, "auto"))
+		return CRLF_AUTO;
 	return CRLF_GUESS;
 }
 
+static int git_path_check_eol(const char *path, struct git_attr_check *check)
+{
+	const char *value = check->value;
+
+	if (ATTR_UNSET(value))
+		;
+	else if (!strcmp(value, "lf"))
+		return EOL_LF;
+	else if (!strcmp(value, "crlf"))
+		return EOL_CRLF;
+	return EOL_UNSET;
+}
+
 static struct convert_driver *git_path_check_convert(const char *path,
 					     struct git_attr_check *check)
 {
@@ -617,20 +652,32 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check)
 	return !!ATTR_TRUE(value);
 }
 
+enum action determine_action(enum action crlf_attr, enum eol eol_attr) {
+	if (crlf_attr == CRLF_BINARY)
+		return CRLF_BINARY;
+	if (eol_attr == EOL_LF)
+		return CRLF_INPUT;
+	if (eol_attr == EOL_CRLF)
+		return CRLF_CRLF;
+	return crlf_attr;
+}
+
 int convert_to_git(const char *path, const char *src, size_t len,
                    struct strbuf *dst, enum safe_crlf checksafe)
 {
-	struct git_attr_check check[3];
-	int crlf = CRLF_GUESS;
+	struct git_attr_check check[4];
+	enum action action = CRLF_GUESS;
+	enum eol eol = EOL_UNSET;
 	int ident = 0, ret = 0;
 	const char *filter = NULL;
 
 	setup_convert_check(check);
 	if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
 		struct convert_driver *drv;
-		crlf = git_path_check_crlf(path, check + 0);
+		action = git_path_check_crlf(path, check + 0);
 		ident = git_path_check_ident(path, check + 1);
 		drv = git_path_check_convert(path, check + 2);
+		eol = git_path_check_eol(path, check + 3);
 		if (drv && drv->clean)
 			filter = drv->clean;
 	}
@@ -640,7 +687,8 @@ int convert_to_git(const char *path, const char *src, size_t len,
 		src = dst->buf;
 		len = dst->len;
 	}
-	ret |= crlf_to_git(path, src, len, dst, crlf, checksafe);
+	action = determine_action(action, eol);
+	ret |= crlf_to_git(path, src, len, dst, action, checksafe);
 	if (ret) {
 		src = dst->buf;
 		len = dst->len;
@@ -650,17 +698,19 @@ int convert_to_git(const char *path, const char *src, size_t len,
 
 int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
 {
-	struct git_attr_check check[3];
-	int crlf = CRLF_GUESS;
+	struct git_attr_check check[4];
+	enum action action = CRLF_GUESS;
+	enum eol eol = EOL_UNSET;
 	int ident = 0, ret = 0;
 	const char *filter = NULL;
 
 	setup_convert_check(check);
 	if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
 		struct convert_driver *drv;
-		crlf = git_path_check_crlf(path, check + 0);
+		action = git_path_check_crlf(path, check + 0);
 		ident = git_path_check_ident(path, check + 1);
 		drv = git_path_check_convert(path, check + 2);
+		eol = git_path_check_eol(path, check + 3);
 		if (drv && drv->smudge)
 			filter = drv->smudge;
 	}
@@ -670,7 +720,8 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
 		src = dst->buf;
 		len = dst->len;
 	}
-	ret |= crlf_to_worktree(path, src, len, dst, crlf);
+	action = determine_action(action, eol);
+	ret |= crlf_to_worktree(path, src, len, dst, action);
 	if (ret) {
 		src = dst->buf;
 		len = dst->len;
diff --git a/environment.c b/environment.c
index 876c5e5..db4a5e9 100644
--- a/environment.c
+++ b/environment.c
@@ -38,7 +38,7 @@ const char *pager_program;
 int pager_use_color = 1;
 const char *editor_program;
 const char *excludes_file;
-int auto_crlf = 0;	/* 1: both ways, -1: only when adding git objects */
+enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
 int read_replace_refs = 1;
 enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
 unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
diff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh
index 360117c..44cb593 100755
--- a/t/t0025-crlf-auto.sh
+++ b/t/t0025-crlf-auto.sh
@@ -42,7 +42,7 @@ test_expect_success 'default settings cause no changes' '
 	test -z "$onediff" -a -z "$twodiff"
 '
 
-test_expect_failure 'crlf=true causes a CRLF file to be normalized' '
+test_expect_success 'crlf=true causes a CRLF file to be normalized' '
 
 	rm -f .gitattributes tmp one two &&
 	echo "two crlf" > .gitattributes &&
@@ -54,7 +54,7 @@ test_expect_failure 'crlf=true causes a CRLF file to be normalized' '
 	test -n "$twodiff"
 '
 
-test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
+test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
 
 	rm -f .gitattributes tmp one two &&
 	git config core.autocrlf false &&
@@ -66,7 +66,7 @@ test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=false'
 	test -z "$onediff"
 '
 
-test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
+test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
 
 	rm -f .gitattributes tmp one two &&
 	git config core.autocrlf input &&
@@ -78,7 +78,7 @@ test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=input'
 	test -z "$onediff"
 '
 
-test_expect_failure 'eol=lf gives a normalized file LFs with autocrlf=true' '
+test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' '
 
 	rm -f .gitattributes tmp one two &&
 	git config core.autocrlf true &&
@@ -103,7 +103,7 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' '
 	test -z "$onediff" -a -z "$twodiff"
 '
 
-test_expect_failure 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '
+test_expect_success 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '
 
 	rm -f .gitattributes tmp one two &&
 	git config core.autocrlf true &&
@@ -129,7 +129,7 @@ test_expect_success 'crlf=auto, autocrlf=true does not normalize binary files' '
 	test -z "$threediff"
 '
 
-test_expect_failure 'eol=crlf _does_ normalize binary files' '
+test_expect_success 'eol=crlf _does_ normalize binary files' '
 
 	rm -f .gitattributes tmp one two three &&
 	echo "three eol=crlf" > .gitattributes &&
-- 
1.7.1.5.gd739a

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 4/4] Rename the "crlf" attribute "text"
  2010-05-13 21:44 [PATCH v4 0/4] End-of-line normalization, getting close? Eyvind Bernhardsen
                   ` (2 preceding siblings ...)
  2010-05-13 21:44 ` [PATCH v4 3/4] Add " Eyvind Bernhardsen
@ 2010-05-13 21:44 ` Eyvind Bernhardsen
  3 siblings, 0 replies; 5+ messages in thread
From: Eyvind Bernhardsen @ 2010-05-13 21:44 UTC (permalink / raw
  To: git; +Cc: msysGit, Linus Torvalds, Junio C Hamano, Finn Arne Gangstad

As discussed on the list, "crlf" is not an optimal name.  Linus
suggested "text", which is much better.

Signed-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>
---
 Documentation/config.txt        |   16 ++++++----
 Documentation/git-cvsserver.txt |   13 +++-----
 Documentation/gitattributes.txt |   59 +++++++++++++++++++++++----------------
 attr.c                          |    2 +-
 convert.c                       |   23 ++++++++++-----
 git-cvsserver.perl              |   13 ++++++--
 t/t0025-crlf-auto.sh            |   21 +++++++++++--
 7 files changed, 91 insertions(+), 56 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4d3c472..207351b 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -204,7 +204,7 @@ core.autocrlf::
 	reading from the work tree but files are written out to the work
 	tree with `LF` at the end of lines.  A file is considered
 	"text" (i.e. be subjected to the autocrlf mechanism) based on
-	the file's `crlf` attribute, or if `crlf` is unspecified,
+	the file's `text` attribute, or if `text` is unspecified,
 	based on the file's contents.  See linkgit:gitattributes[5].
 
 core.safecrlf::
@@ -975,13 +975,15 @@ gitcvs.logfile::
 	various stuff. See linkgit:git-cvsserver[1].
 
 gitcvs.usecrlfattr::
-	If true, the server will look up the `crlf` attribute for
-	files to determine the '-k' modes to use. If `crlf` is set,
-	the '-k' mode will be left blank, so cvs clients will
-	treat it as text. If `crlf` is explicitly unset, the file
+	If true, the server will look up the end-of-line conversion
+	attributes for files to determine the '-k' modes to use. If
+	the attributes force git to treat a file as text,
+	the '-k' mode will be left blank so cvs clients will
+	treat it as text. If they suppress text conversion, the file
 	will be set with '-kb' mode, which suppresses any newline munging
-	the client might otherwise do. If `crlf` is not specified,
-	then 'gitcvs.allbinary' is used. See linkgit:gitattributes[5].
+	the client might otherwise do. If the attributes do not allow
+	the file type to be determined, then 'gitcvs.allbinary' is
+	used. See linkgit:gitattributes[5].
 
 gitcvs.allbinary::
 	This is used if 'gitcvs.usecrlfattr' does not resolve
diff --git a/Documentation/git-cvsserver.txt b/Documentation/git-cvsserver.txt
index dbb053e..0864857 100644
--- a/Documentation/git-cvsserver.txt
+++ b/Documentation/git-cvsserver.txt
@@ -340,16 +340,13 @@ By default the server leaves the '-k' mode blank for all files,
 which causes the cvs client to treat them as a text files, subject
 to crlf conversion on some platforms.
 
-You can make the server use `crlf` attributes to set the '-k' modes
-for files by setting the `gitcvs.usecrlfattr` config variable.
-In this case, if `crlf` is explicitly unset ('-crlf'), then the
-server will set '-kb' mode for binary files. If `crlf` is set,
-then the '-k' mode will explicitly be left blank.  See
-also linkgit:gitattributes[5] for more information about the `crlf`
-attribute.
+You can make the server use the end-of-line conversion attributes to
+set the '-k' modes for files by setting the `gitcvs.usecrlfattr`
+config variable.  See linkgit:gitattributes[5] for more information
+about end-of-line conversion.
 
 Alternatively, if `gitcvs.usecrlfattr` config is not enabled
-or if the `crlf` attribute is unspecified for a filename, then
+or the attributes do not allow automatic detection for a filename, then
 the server uses the `gitcvs.allbinary` config for the default setting.
 If `gitcvs.allbinary` is set, then file not otherwise
 specified will default to '-kb' mode. Otherwise the '-k' mode
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index c71d883..25753b7 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -92,7 +92,7 @@ such as 'git checkout' and 'git merge' run.  They also affect how
 git stores the contents you prepare in the working tree in the
 repository upon 'git add' and 'git commit'.
 
-`crlf`
+`text`
 ^^^^^^
 
 This attribute enables and controls end-of-line normalization.  When a
@@ -103,28 +103,28 @@ directory, use the `eol` attribute for a single file and the
 
 Set::
 
-	Setting the `crlf` attribute on a path enables end-of-line
+	Setting the `text` attribute on a path enables end-of-line
 	normalization and marks the path as a text file.  End-of-line
 	conversion takes place without guessing the content type.
 
 Unset::
 
-	Unsetting the `crlf` attribute on a path tells git not to
+	Unsetting the `text` attribute on a path tells git not to
 	attempt any end-of-line conversion upon checkin or checkout.
 
 Set to string value "auto"::
 
-	When `crlf` is set to "auto", the path is marked for automatic
+	When `text` is set to "auto", the path is marked for automatic
 	end-of-line normalization.  If git decides that the content is
 	text, its line endings are normalized to LF on checkin.
 
 Unspecified::
 
-	If the `crlf` attribute is unspecified, git uses the `eol`
+	If the `text` attribute is unspecified, git uses the `eol`
 	attribute and the `core.autocrlf` configuration variable to
 	determine if the file should be converted.
 
-Any other value causes git to act as if `crlf` has been left
+Any other value causes git to act as if `text` has been left
 unspecified.
 
 `eol`
@@ -132,20 +132,31 @@ unspecified.
 
 This attribute sets a specific line-ending style to be used in the
 working directory.  It enables end-of-line normalization without any
-content checks, similar to setting the `crlf` attribute.
+content checks, similar to setting the `text` attribute.
 
 Set to string value "crlf"::
 
 	This setting forces git to normalize line endings on checkin
 	and convert them to CRLF when the file is checked out,
-	regardless of `crlf` and `core.autocrlf`.
+	regardless of `text` and `core.autocrlf`.
 
 Set to string value "lf"::
 
 	This setting forces git to normalize line endings to LF on
 	checkin and prevents conversion to CRLF when the file is
-	checked out, regardless of `crlf` and `core.autocrlf`.
-	`crlf=input` is a backwards compatibility alias for `eol=lf`.
+	checked out, regardless of `text` and `core.autocrlf`.
+
+Backwards compatibility with `crlf` attribute
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+For backwards compatibility, the `crlf` attribute is interpreted as
+follows:
+
+------------------------
+crlf		text
+-crlf		-text
+crlf=input	eol=lf
+------------------------
 
 End-of-line conversion
 ^^^^^^^^^^^^^^^^^^^^^^
@@ -160,10 +171,10 @@ the working directory, and prevent .jpg files from being normalized
 regardless of their content.
 
 ------------------------
-*.txt		crlf
+*.txt		text
 *.vcproj	eol=crlf
 *.sh		eol=lf
-*.jpg		-crlf
+*.jpg		-text
 ------------------------
 
 Other source code management systems normalize all text files in their
@@ -188,24 +199,24 @@ files without conversion to CRLF in the working directory.
 
 If you want to interoperate with a source code management system that
 enforces end-of-line normalization, or you simply want all text files
-in your repository to be normalized, you should instead set the `crlf`
+in your repository to be normalized, you should instead set the `text`
 attribute to "auto" for _all_ files.
 
 ------------------------
-*	crlf=auto
+*	text=auto
 ------------------------
 
 This ensures that all files that git considers to be text will have
 normalized (LF) line endings in the repository.
 
-NOTE: When `crlf=auto` normalization is enabled in an existing
+NOTE: When `text=auto` normalization is enabled in an existing
 repository, any text files containing CRLFs should be normalized.  If
 they are not they will be normalized the next time someone tries to
 change them, causing unfortunate misattribution.  From a clean working
 directory:
 
 -------------------------------------------------
-$ echo "* crlf=auto" >>.gitattributes
+$ echo "* text=auto" >>.gitattributes
                     # ...this should be the first line in .gitattributes
 $ rm .git/index     # Remove the index to force git to
 $ git reset         # re-scan the working directory
@@ -216,17 +227,17 @@ $ git commit -m "Introduce end-of-line normalization"
 -------------------------------------------------
 
 If any files that should not be normalized show up in 'git status',
-unset their `crlf` attribute before running 'git add -u'.
+unset their `text` attribute before running 'git add -u'.
 
 ------------------------
-manual.pdf	-crlf
+manual.pdf	-text
 ------------------------
 
 Conversely, text files that git does not detect can have normalization
 enabled manually.
 
 ------------------------
-weirdchars.txt	crlf
+weirdchars.txt	text
 ------------------------
 
 If `core.safecrlf` is set to "true" or "warn", git verifies if
@@ -312,11 +323,11 @@ Interaction between checkin/checkout attributes
 In the check-in codepath, the worktree file is first converted
 with `filter` driver (if specified and corresponding driver
 defined), then the result is processed with `ident` (if
-specified), and then finally with `crlf` (again, if specified
+specified), and then finally with `text` (again, if specified
 and applicable).
 
 In the check-out codepath, the blob content is first converted
-with `crlf`, and then `ident` and fed to `filter`.
+with `text`, and then `ident` and fed to `filter`.
 
 
 Generating diff text
@@ -720,7 +731,7 @@ You do not want any end-of-line conversions applied to, nor textual diffs
 produced for, any binary file you track.  You would need to specify e.g.
 
 ------------
-*.jpg -crlf -diff
+*.jpg -text -diff
 ------------
 
 but that may become cumbersome, when you have many attributes.  Using
@@ -733,7 +744,7 @@ the same time.  The system knows a built-in attribute macro, `binary`:
 
 which is equivalent to the above.  Note that the attribute macros can only
 be "Set" (see the above example that sets "binary" macro as if it were an
-ordinary attribute --- setting it in turn unsets "crlf" and "diff").
+ordinary attribute --- setting it in turn unsets "text" and "diff").
 
 
 DEFINING ATTRIBUTE MACROS
@@ -744,7 +755,7 @@ at the toplevel (i.e. not in any subdirectory).  The built-in attribute
 macro "binary" is equivalent to:
 
 ------------
-[attr]binary -diff -crlf
+[attr]binary -diff -text
 ------------
 
 
diff --git a/attr.c b/attr.c
index f5346ed..bf00469 100644
--- a/attr.c
+++ b/attr.c
@@ -287,7 +287,7 @@ static void free_attr_elem(struct attr_stack *e)
 }
 
 static const char *builtin_attr[] = {
-	"[attr]binary -diff -crlf",
+	"[attr]binary -diff -text",
 	NULL,
 };
 
diff --git a/convert.c b/convert.c
index 98bc029..a309e07 100644
--- a/convert.c
+++ b/convert.c
@@ -440,12 +440,14 @@ static int read_convert_config(const char *var, const char *value, void *cb)
 
 static void setup_convert_check(struct git_attr_check *check)
 {
+	static struct git_attr *attr_text;
 	static struct git_attr *attr_crlf;
 	static struct git_attr *attr_eol;
 	static struct git_attr *attr_ident;
 	static struct git_attr *attr_filter;
 
-	if (!attr_crlf) {
+	if (!attr_text) {
+		attr_text = git_attr("text");
 		attr_crlf = git_attr("crlf");
 		attr_eol = git_attr("eol");
 		attr_ident = git_attr("ident");
@@ -457,6 +459,7 @@ static void setup_convert_check(struct git_attr_check *check)
 	check[1].attr = attr_ident;
 	check[2].attr = attr_filter;
 	check[3].attr = attr_eol;
+	check[4].attr = attr_text;
 }
 
 static int count_ident(const char *cp, unsigned long size)
@@ -652,20 +655,20 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check)
 	return !!ATTR_TRUE(value);
 }
 
-enum action determine_action(enum action crlf_attr, enum eol eol_attr) {
-	if (crlf_attr == CRLF_BINARY)
+enum action determine_action(enum action text_attr, enum eol eol_attr) {
+	if (text_attr == CRLF_BINARY)
 		return CRLF_BINARY;
 	if (eol_attr == EOL_LF)
 		return CRLF_INPUT;
 	if (eol_attr == EOL_CRLF)
 		return CRLF_CRLF;
-	return crlf_attr;
+	return text_attr;
 }
 
 int convert_to_git(const char *path, const char *src, size_t len,
                    struct strbuf *dst, enum safe_crlf checksafe)
 {
-	struct git_attr_check check[4];
+	struct git_attr_check check[5];
 	enum action action = CRLF_GUESS;
 	enum eol eol = EOL_UNSET;
 	int ident = 0, ret = 0;
@@ -674,7 +677,9 @@ int convert_to_git(const char *path, const char *src, size_t len,
 	setup_convert_check(check);
 	if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
 		struct convert_driver *drv;
-		action = git_path_check_crlf(path, check + 0);
+		action = git_path_check_crlf(path, check + 4);
+		if (action == CRLF_GUESS)
+			action = git_path_check_crlf(path, check + 0);
 		ident = git_path_check_ident(path, check + 1);
 		drv = git_path_check_convert(path, check + 2);
 		eol = git_path_check_eol(path, check + 3);
@@ -698,7 +703,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
 
 int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
 {
-	struct git_attr_check check[4];
+	struct git_attr_check check[5];
 	enum action action = CRLF_GUESS;
 	enum eol eol = EOL_UNSET;
 	int ident = 0, ret = 0;
@@ -707,7 +712,9 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
 	setup_convert_check(check);
 	if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
 		struct convert_driver *drv;
-		action = git_path_check_crlf(path, check + 0);
+		action = git_path_check_crlf(path, check + 4);
+		if (action == CRLF_GUESS)
+			action = git_path_check_crlf(path, check + 0);
 		ident = git_path_check_ident(path, check + 1);
 		drv = git_path_check_convert(path, check + 2);
 		eol = git_path_check_eol(path, check + 3);
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 13751db..4e55041 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -2369,15 +2369,20 @@ sub kopts_from_path
     if ( defined ( $cfg->{gitcvs}{usecrlfattr} ) and
          $cfg->{gitcvs}{usecrlfattr} =~ /\s*(1|true|yes)\s*$/i )
     {
-        my ($val) = check_attr( "crlf", $path );
-        if ( $val eq "set" )
+        my ($val) = check_attr( "text", $path );
+        if ( $val eq "unspecified" )
         {
-            return "";
+            $val = check_attr( "crlf", $path );
         }
-        elsif ( $val eq "unset" )
+        if ( $val eq "unset" )
         {
             return "-kb"
         }
+        elsif ( check_attr( "eol", $path ) ne "unspecified" ||
+                $val eq "set" || $val eq "input" )
+        {
+            return "";
+        }
         else
         {
             $log->info("Unrecognized check_attr crlf $path : $val");
diff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh
index 44cb593..8b1a128 100755
--- a/t/t0025-crlf-auto.sh
+++ b/t/t0025-crlf-auto.sh
@@ -44,6 +44,7 @@ test_expect_success 'default settings cause no changes' '
 
 test_expect_success 'crlf=true causes a CRLF file to be normalized' '
 
+	# Backwards compatibility check
 	rm -f .gitattributes tmp one two &&
 	echo "two crlf" > .gitattributes &&
 	git read-tree --reset -u HEAD &&
@@ -54,6 +55,18 @@ test_expect_success 'crlf=true causes a CRLF file to be normalized' '
 	test -n "$twodiff"
 '
 
+test_expect_success 'text=true causes a CRLF file to be normalized' '
+
+	rm -f .gitattributes tmp one two &&
+	echo "two text" > .gitattributes &&
+	git read-tree --reset -u HEAD &&
+
+	# Note, "normalized" means that git will normalize it if added
+	has_cr two &&
+	twodiff=`git diff two` &&
+	test -n "$twodiff"
+'
+
 test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
 
 	rm -f .gitattributes tmp one two &&
@@ -103,11 +116,11 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' '
 	test -z "$onediff" -a -z "$twodiff"
 '
 
-test_expect_success 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '
+test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
 
 	rm -f .gitattributes tmp one two &&
 	git config core.autocrlf true &&
-	echo "* crlf=auto" > .gitattributes &&
+	echo "* text=auto" > .gitattributes &&
 	git read-tree --reset -u HEAD &&
 
 	has_cr one &&
@@ -117,11 +130,11 @@ test_expect_success 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '
 	test -z "$onediff" -a -n "$twodiff"
 '
 
-test_expect_success 'crlf=auto, autocrlf=true does not normalize binary files' '
+test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
 
 	rm -f .gitattributes tmp one two three &&
 	git config core.autocrlf true &&
-	echo "* crlf=auto" > .gitattributes &&
+	echo "* text=auto" > .gitattributes &&
 	git read-tree --reset -u HEAD &&
 
 	! has_cr three &&
-- 
1.7.1.5.gd739a

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-05-13 21:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-13 21:44 [PATCH v4 0/4] End-of-line normalization, getting close? Eyvind Bernhardsen
2010-05-13 21:44 ` [PATCH v4 1/4] autocrlf: Make it work also for un-normalized repositories Eyvind Bernhardsen
2010-05-13 21:44 ` [PATCH v4 2/4] Add tests for per-repository eol normalization Eyvind Bernhardsen
2010-05-13 21:44 ` [PATCH v4 3/4] Add " Eyvind Bernhardsen
2010-05-13 21:44 ` [PATCH v4 4/4] Rename the "crlf" attribute "text" Eyvind Bernhardsen

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).