summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fd6cce9)
raw | patch | inline | side by side (parent: fd6cce9)
author | Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com> | |
Wed, 19 May 2010 20:43:11 +0000 (22:43 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 20 May 2010 03:42:34 +0000 (20:42 -0700) |
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>
suggested "text", which is much better.
Signed-off-by: Eyvind Bernhardsen <eyvind.bernhardsen@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
index c6cc7abe3e500efa3477afaccfe398479f7cfa56..35569a0a77bfbe28cf5af48ebce70e14a68b0ad8 100644 (file)
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
reading from the filesystem but files are written out 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::
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
index dbb053ee17fbc9e254aac42bf87d204655e00614..086485763c40761dc9136f48127ce6f0e24f7212 100644 (file)
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
index f621b23b841e52360d89670fa2274ae69b874d53..1120b90a58ca3ce06b45462c9f9866663c586bf9 100644 (file)
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
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`
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
^^^^^^^^^^^^^^^^^^^^^^
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
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
$ 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
-------------------------------------------------
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
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
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
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
macro "binary" is equivalent to:
------------
-[attr]binary -diff -crlf
+[attr]binary -diff -text
------------
index f5346ed32a1b5caf908021805214fd97e033eb27..bf00469ecce6a3f74f7ef87f362b768b2bd9f05c 100644 (file)
--- a/attr.c
+++ b/attr.c
}
static const char *builtin_attr[] = {
- "[attr]binary -diff -crlf",
+ "[attr]binary -diff -text",
NULL,
};
diff --git a/convert.c b/convert.c
index 1144e0b4f5539172eb4043edc8013fb8e69f135d..c61c02b190459bcfba60f085e103b0e99711b622 100644 (file)
--- a/convert.c
+++ b/convert.c
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");
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)
@@ -651,20 +654,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;
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);
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;
@@ -706,7 +711,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 13751db882dd2c40e2c78503eba0d3f941297644..4e55041ec79c6cb128ba2e8ebe30a3a7037ce29c 100755 (executable)
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
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 2781f15302eb0575fcd3218c049281a5689a82eb..f5f67a6337320c11a285b78be299fa955663991d 100755 (executable)
--- a/t/t0025-crlf-auto.sh
+++ b/t/t0025-crlf-auto.sh
test_expect_success 'crlf=true causes a CRLF file to be normalized' '
+ # Backwards compatibility check
rm -f .gitattributes tmp one two three &&
echo "two crlf" > .gitattributes &&
git read-tree --reset -u HEAD &&
test -n "$twodiff"
'
+test_expect_success 'text=true causes a CRLF file to be normalized' '
+
+ rm -f .gitattributes tmp one two three &&
+ 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 three &&
test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
'
-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 three &&
git config core.autocrlf true &&
- echo "* crlf=auto" > .gitattributes &&
+ echo "* text=auto" > .gitattributes &&
git read-tree --reset -u HEAD &&
has_cr one &&
test -z "$onediff" -a -n "$twodiff" -a -z "$threediff"
'
-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 &&