Rename the "crlf" attribute "text"
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eyvind Bernhardsen committed
May 19, 2010 at 22:43 UTC
5ec3e67052289217c84e53d2cda90d939ac5725b
7 files changed
+91
-56
Documentation/config.txt
+9
-7
@@ -199,7 +199,7 @@ core.autocrlf::
199
reading from the filesystem but files are written out with
200
`LF` at the end of lines. A file is considered
201
"text" (i.e. be subjected to the autocrlf mechanism) based on
202
- the file's `crlf` attribute, or if `crlf` is unspecified,
202
+ the file's `text` attribute, or if `text` is unspecified,
203
based on the file's contents. See linkgit:gitattributes[5].
204
205
core.safecrlf::
@@ -943,13 +943,15 @@ gitcvs.logfile::
943
various stuff. See linkgit:git-cvsserver[1].
944
945
gitcvs.usecrlfattr::
946
- If true, the server will look up the `crlf` attribute for
947
- files to determine the '-k' modes to use. If `crlf` is set,
948
- the '-k' mode will be left blank, so cvs clients will
949
- treat it as text. If `crlf` is explicitly unset, the file
946
+ If true, the server will look up the end-of-line conversion
947
+ attributes for files to determine the '-k' modes to use. If
948
+ the attributes force git to treat a file as text,
949
+ the '-k' mode will be left blank so cvs clients will
950
+ treat it as text. If they suppress text conversion, the file
951
will be set with '-kb' mode, which suppresses any newline munging
951
- the client might otherwise do. If `crlf` is not specified,
952
- then 'gitcvs.allbinary' is used. See linkgit:gitattributes[5].
952
+ the client might otherwise do. If the attributes do not allow
953
+ the file type to be determined, then 'gitcvs.allbinary' is
954
+ used. See linkgit:gitattributes[5].
955
956
gitcvs.allbinary::
957
This is used if 'gitcvs.usecrlfattr' does not resolve
Documentation/git-cvsserver.txt
+5
-8
@@ -340,16 +340,13 @@ By default the server leaves the '-k' mode blank for all files,
340
which causes the cvs client to treat them as a text files, subject
341
to crlf conversion on some platforms.
342
343
-You can make the server use `crlf` attributes to set the '-k' modes
344
-for files by setting the `gitcvs.usecrlfattr` config variable.
345
-In this case, if `crlf` is explicitly unset ('-crlf'), then the
346
-server will set '-kb' mode for binary files. If `crlf` is set,
347
-then the '-k' mode will explicitly be left blank. See
348
-also linkgit:gitattributes[5] for more information about the `crlf`
349
-attribute.
343
+You can make the server use the end-of-line conversion attributes to
344
+set the '-k' modes for files by setting the `gitcvs.usecrlfattr`
345
+config variable. See linkgit:gitattributes[5] for more information
346
+about end-of-line conversion.
347
348
Alternatively, if `gitcvs.usecrlfattr` config is not enabled
352
-or if the `crlf` attribute is unspecified for a filename, then
349
+or the attributes do not allow automatic detection for a filename, then
350
the server uses the `gitcvs.allbinary` config for the default setting.
351
If `gitcvs.allbinary` is set, then file not otherwise
352
specified will default to '-kb' mode. Otherwise the '-k' mode
Documentation/gitattributes.txt
+35
-24
@@ -92,7 +92,7 @@ such as 'git checkout' and 'git merge' run. They also affect how
92
git stores the contents you prepare in the working tree in the
93
repository upon 'git add' and 'git commit'.
94
95
-`crlf`
95
+`text`
96
^^^^^^
97
98
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
103
104
Set::
105
106
- Setting the `crlf` attribute on a path enables end-of-line
106
+ Setting the `text` attribute on a path enables end-of-line
107
normalization and marks the path as a text file. End-of-line
108
conversion takes place without guessing the content type.
109
110
Unset::
111
112
- Unsetting the `crlf` attribute on a path tells git not to
112
+ Unsetting the `text` attribute on a path tells git not to
113
attempt any end-of-line conversion upon checkin or checkout.
114
115
Set to string value "auto"::
116
117
- When `crlf` is set to "auto", the path is marked for automatic
117
+ When `text` is set to "auto", the path is marked for automatic
118
end-of-line normalization. If git decides that the content is
119
text, its line endings are normalized to LF on checkin.
120
121
Unspecified::
122
123
- If the `crlf` attribute is unspecified, git uses the `eol`
123
+ If the `text` attribute is unspecified, git uses the `eol`
124
attribute and the `core.autocrlf` configuration variable to
125
determine if the file should be converted.
126
127
-Any other value causes git to act as if `crlf` has been left
127
+Any other value causes git to act as if `text` has been left
128
unspecified.
129
130
`eol`
@@ -132,20 +132,31 @@ unspecified.
132
133
This attribute sets a specific line-ending style to be used in the
134
working directory. It enables end-of-line normalization without any
135
-content checks, similar to setting the `crlf` attribute.
135
+content checks, similar to setting the `text` attribute.
136
137
Set to string value "crlf"::
138
139
This setting forces git to normalize line endings on checkin
140
and convert them to CRLF when the file is checked out,
141
- regardless of `crlf` and `core.autocrlf`.
141
+ regardless of `text` and `core.autocrlf`.
142
143
Set to string value "lf"::
144
145
This setting forces git to normalize line endings to LF on
146
checkin and prevents conversion to CRLF when the file is
147
- checked out, regardless of `crlf` and `core.autocrlf`.
148
- `crlf=input` is a backwards compatibility alias for `eol=lf`.
147
+ checked out, regardless of `text` and `core.autocrlf`.
148
+
149
+Backwards compatibility with `crlf` attribute
150
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151
+
152
+For backwards compatibility, the `crlf` attribute is interpreted as
153
+follows:
154
+
155
+------------------------
156
+crlf text
157
+-crlf -text
158
+crlf=input eol=lf
159
+------------------------
160
161
End-of-line conversion
162
^^^^^^^^^^^^^^^^^^^^^^
@@ -160,10 +171,10 @@ the working directory, and prevent .jpg files from being normalized
171
regardless of their content.
172
173
------------------------
163
-*.txt crlf
174
+*.txt text
175
*.vcproj eol=crlf
176
*.sh eol=lf
166
-*.jpg -crlf
177
+*.jpg -text
178
------------------------
179
180
Other source code management systems normalize all text files in their
@@ -188,24 +199,24 @@ files without conversion to CRLF in the working directory.
199
200
If you want to interoperate with a source code management system that
201
enforces end-of-line normalization, or you simply want all text files
191
-in your repository to be normalized, you should instead set the `crlf`
202
+in your repository to be normalized, you should instead set the `text`
203
attribute to "auto" for _all_ files.
204
205
------------------------
195
-* crlf=auto
206
+* text=auto
207
------------------------
208
209
This ensures that all files that git considers to be text will have
210
normalized (LF) line endings in the repository.
211
201
-NOTE: When `crlf=auto` normalization is enabled in an existing
212
+NOTE: When `text=auto` normalization is enabled in an existing
213
repository, any text files containing CRLFs should be normalized. If
214
they are not they will be normalized the next time someone tries to
215
change them, causing unfortunate misattribution. From a clean working
216
directory:
217
218
-------------------------------------------------
208
-$ echo "* crlf=auto" >>.gitattributes
219
+$ echo "* text=auto" >>.gitattributes
220
$ rm .git/index # Remove the index to force git to
221
$ git reset # re-scan the working directory
222
$ git status # Show files that will be normalized
@@ -215,17 +226,17 @@ $ git commit -m "Introduce end-of-line normalization"
226
-------------------------------------------------
227
228
If any files that should not be normalized show up in 'git status',
218
-unset their `crlf` attribute before running 'git add -u'.
229
+unset their `text` attribute before running 'git add -u'.
230
231
------------------------
221
-manual.pdf -crlf
232
+manual.pdf -text
233
------------------------
234
235
Conversely, text files that git does not detect can have normalization
236
enabled manually.
237
238
------------------------
228
-weirdchars.txt crlf
239
+weirdchars.txt text
240
------------------------
241
242
If `core.safecrlf` is set to "true" or "warn", git verifies if
@@ -311,11 +322,11 @@ Interaction between checkin/checkout attributes
322
In the check-in codepath, the worktree file is first converted
323
with `filter` driver (if specified and corresponding driver
324
defined), then the result is processed with `ident` (if
314
-specified), and then finally with `crlf` (again, if specified
325
+specified), and then finally with `text` (again, if specified
326
and applicable).
327
328
In the check-out codepath, the blob content is first converted
318
-with `crlf`, and then `ident` and fed to `filter`.
329
+with `text`, and then `ident` and fed to `filter`.
330
331
332
Generating diff text
@@ -718,7 +729,7 @@ You do not want any end-of-line conversions applied to, nor textual diffs
729
produced for, any binary file you track. You would need to specify e.g.
730
731
------------
721
-*.jpg -crlf -diff
732
+*.jpg -text -diff
733
------------
734
735
but that may become cumbersome, when you have many attributes. Using
@@ -731,7 +742,7 @@ the same time. The system knows a built-in attribute macro, `binary`:
742
743
which is equivalent to the above. Note that the attribute macros can only
744
be "Set" (see the above example that sets "binary" macro as if it were an
734
-ordinary attribute --- setting it in turn unsets "crlf" and "diff").
745
+ordinary attribute --- setting it in turn unsets "text" and "diff").
746
747
748
DEFINING ATTRIBUTE MACROS
@@ -742,7 +753,7 @@ at the toplevel (i.e. not in any subdirectory). The built-in attribute
753
macro "binary" is equivalent to:
754
755
------------
745
-[attr]binary -diff -crlf
756
+[attr]binary -diff -text
757
------------
758
759
attr.c
+1
-1
@@ -287,7 +287,7 @@ static void free_attr_elem(struct attr_stack *e)
287
}
288
289
static const char *builtin_attr[] = {
290
- "[attr]binary -diff -crlf",
290
+ "[attr]binary -diff -text",
291
NULL,
292
};
293
convert.c
+15
-8
@@ -439,12 +439,14 @@ static int read_convert_config(const char *var, const char *value, void *cb)
439
440
static void setup_convert_check(struct git_attr_check *check)
441
{
442
+ static struct git_attr *attr_text;
443
static struct git_attr *attr_crlf;
444
static struct git_attr *attr_eol;
445
static struct git_attr *attr_ident;
446
static struct git_attr *attr_filter;
447
447
- if (!attr_crlf) {
448
+ if (!attr_text) {
449
+ attr_text = git_attr("text");
450
attr_crlf = git_attr("crlf");
451
attr_eol = git_attr("eol");
452
attr_ident = git_attr("ident");
@@ -456,6 +458,7 @@ static void setup_convert_check(struct git_attr_check *check)
458
check[1].attr = attr_ident;
459
check[2].attr = attr_filter;
460
check[3].attr = attr_eol;
461
+ check[4].attr = attr_text;
462
}
463
464
static int count_ident(const char *cp, unsigned long size)
@@ -651,20 +654,20 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check)
654
return !!ATTR_TRUE(value);
655
}
656
654
-enum action determine_action(enum action crlf_attr, enum eol eol_attr) {
655
- if (crlf_attr == CRLF_BINARY)
657
+enum action determine_action(enum action text_attr, enum eol eol_attr) {
658
+ if (text_attr == CRLF_BINARY)
659
return CRLF_BINARY;
660
if (eol_attr == EOL_LF)
661
return CRLF_INPUT;
662
if (eol_attr == EOL_CRLF)
663
return CRLF_CRLF;
661
- return crlf_attr;
664
+ return text_attr;
665
}
666
667
int convert_to_git(const char *path, const char *src, size_t len,
668
struct strbuf *dst, enum safe_crlf checksafe)
669
{
667
- struct git_attr_check check[4];
670
+ struct git_attr_check check[5];
671
enum action action = CRLF_GUESS;
672
enum eol eol = EOL_UNSET;
673
int ident = 0, ret = 0;
@@ -673,7 +676,9 @@ int convert_to_git(const char *path, const char *src, size_t len,
676
setup_convert_check(check);
677
if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
678
struct convert_driver *drv;
676
- action = git_path_check_crlf(path, check + 0);
679
+ action = git_path_check_crlf(path, check + 4);
680
+ if (action == CRLF_GUESS)
681
+ action = git_path_check_crlf(path, check + 0);
682
ident = git_path_check_ident(path, check + 1);
683
drv = git_path_check_convert(path, check + 2);
684
eol = git_path_check_eol(path, check + 3);
@@ -697,7 +702,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
702
703
int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
704
{
700
- struct git_attr_check check[4];
705
+ struct git_attr_check check[5];
706
enum action action = CRLF_GUESS;
707
enum eol eol = EOL_UNSET;
708
int ident = 0, ret = 0;
@@ -706,7 +711,9 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
711
setup_convert_check(check);
712
if (!git_checkattr(path, ARRAY_SIZE(check), check)) {
713
struct convert_driver *drv;
709
- action = git_path_check_crlf(path, check + 0);
714
+ action = git_path_check_crlf(path, check + 4);
715
+ if (action == CRLF_GUESS)
716
+ action = git_path_check_crlf(path, check + 0);
717
ident = git_path_check_ident(path, check + 1);
718
drv = git_path_check_convert(path, check + 2);
719
eol = git_path_check_eol(path, check + 3);
git-cvsserver.perl
+9
-4
@@ -2369,15 +2369,20 @@ sub kopts_from_path
2369
if ( defined ( $cfg->{gitcvs}{usecrlfattr} ) and
2370
$cfg->{gitcvs}{usecrlfattr} =~ /\s*(1|true|yes)\s*$/i )
2371
{
2372
- my ($val) = check_attr( "crlf", $path );
2373
- if ( $val eq "set" )
2372
+ my ($val) = check_attr( "text", $path );
2373
+ if ( $val eq "unspecified" )
2374
{
2375
- return "";
2375
+ $val = check_attr( "crlf", $path );
2376
}
2377
- elsif ( $val eq "unset" )
2377
+ if ( $val eq "unset" )
2378
{
2379
return "-kb"
2380
}
2381
+ elsif ( check_attr( "eol", $path ) ne "unspecified" ||
2382
+ $val eq "set" || $val eq "input" )
2383
+ {
2384
+ return "";
2385
+ }
2386
else
2387
{
2388
$log->info("Unrecognized check_attr crlf $path : $val");
t/t0025-crlf-auto.sh
+17
-4
@@ -41,6 +41,7 @@ test_expect_success 'default settings cause no changes' '
41
42
test_expect_success 'crlf=true causes a CRLF file to be normalized' '
43
44
+ # Backwards compatibility check
45
rm -f .gitattributes tmp one two three &&
46
echo "two crlf" > .gitattributes &&
47
git read-tree --reset -u HEAD &&
@@ -51,6 +52,18 @@ test_expect_success 'crlf=true causes a CRLF file to be normalized' '
52
test -n "$twodiff"
53
'
54
55
+test_expect_success 'text=true causes a CRLF file to be normalized' '
56
+
57
+ rm -f .gitattributes tmp one two three &&
58
+ echo "two text" > .gitattributes &&
59
+ git read-tree --reset -u HEAD &&
60
+
61
+ # Note, "normalized" means that git will normalize it if added
62
+ has_cr two &&
63
+ twodiff=`git diff two` &&
64
+ test -n "$twodiff"
65
+'
66
+
67
test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
68
69
rm -f .gitattributes tmp one two three &&
@@ -101,11 +114,11 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' '
114
test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
115
'
116
104
-test_expect_success 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '
117
+test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' '
118
119
rm -f .gitattributes tmp one two three &&
120
git config core.autocrlf true &&
108
- echo "* crlf=auto" > .gitattributes &&
121
+ echo "* text=auto" > .gitattributes &&
122
git read-tree --reset -u HEAD &&
123
124
has_cr one &&
@@ -116,11 +129,11 @@ test_expect_success 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '
129
test -z "$onediff" -a -n "$twodiff" -a -z "$threediff"
130
'
131
119
-test_expect_success 'crlf=auto, autocrlf=true does not normalize binary files' '
132
+test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
133
134
rm -f .gitattributes tmp one two three &&
135
git config core.autocrlf true &&
123
- echo "* crlf=auto" > .gitattributes &&
136
+ echo "* text=auto" > .gitattributes &&
137
git read-tree --reset -u HEAD &&
138
139
! has_cr three &&