Quantcast

[PATCH v6] Add "core.eol" config variable

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH v6] Add "core.eol" config variable

Eyvind Bernhardsen-2
Introduce a new configuration variable, "core.eol", that allows the user
to set which line endings to use for end-of-line-normalized files in the
working directory.  It defaults to "native", which means CRLF on Windows
and LF everywhere else.

Note that "core.autocrlf" overrides core.eol.  This means that

[core]
        autocrlf = true

puts CRLFs in the working directory even if core.eol is set to "lf".

Signed-off-by: Eyvind Bernhardsen <[hidden email]>
---
As Clemens Buchacher noted, "core.autocrlf" doesn't work as a generic
"turn on automatic line ending normalization" setting since it doesn't
always normalize line endings.

This is a replacement for the 'Add "core.eol" config variable' commit
that's currently in pu (the last one in my series).  Instead of implying
that "core.autocrlf=true" is a replacement for "* text=auto", it makes
explicit the fact that autocrlf is only for users who want to work with
CRLFs in their working directory on a repository that doesn't have text
file normalization.  When it is enabled, "core.eol" is ignored.
--
Eyvind

 Documentation/config.txt        |   35 ++++++++++-------
 Documentation/gitattributes.txt |   28 +++++++------
 Makefile                        |    3 +
 cache.h                         |   13 ++++++
 config.c                        |   16 +++++++
 convert.c                       |   60 +++++++++++++++++-----------
 environment.c                   |    1 +
 t/t0026-eol-config.sh           |   83 +++++++++++++++++++++++++++++++++++++++
 8 files changed, 188 insertions(+), 51 deletions(-)
 create mode 100755 t/t0026-eol-config.sh

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 207351b..5a0737a 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -196,16 +196,13 @@ core.quotepath::
  quoted without `-z` regardless of the setting of this
  variable.
 
-core.autocrlf::
- If true, makes git convert `CRLF` at the end of lines in text files to
- `LF` when reading from the work tree, and convert in reverse when
- writing to the work tree.  The variable can be set to
- 'input', in which case the conversion happens only while
- 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 `text` attribute, or if `text` is unspecified,
- based on the file's contents.  See linkgit:gitattributes[5].
+core.eol::
+ Sets the line ending type to use in the working directory for
+ files that have the `text` property set.  Alternatives are
+ 'lf', 'crlf' and 'native', which uses the platform's native
+ line ending.  The default value is `native`.  See
+ linkgit:gitattributes[5] for more information on end-of-line
+ conversion.
 
 core.safecrlf::
  If true, makes git check if converting `CRLF` is reversible when
@@ -219,7 +216,7 @@ core.safecrlf::
  irreversible conversion but continue the operation.
 +
 CRLF conversion bears a slight chance of corrupting data.
-autocrlf=true will convert CRLF to LF during commit and LF to
+When it is enabled, git will convert CRLF to LF during commit and LF to
 CRLF during checkout.  A file that contains a mixture of LF and
 CRLF before the commit cannot be recreated by git.  For text
 files this is the right thing to do: it corrects line endings
@@ -243,15 +240,25 @@ converting CRLFs corrupts data.
 +
 Note, this safety check does not mean that a checkout will generate a
 file identical to the original file for a different setting of
-`core.autocrlf`, but only for the current one.  For example, a text
-file with `LF` would be accepted with `core.autocrlf=input` and could
-later be checked out with `core.autocrlf=true`, in which case the
+`core.eol` and `core.autocrlf`, but only for the current one.  For
+example, a text file with `LF` would be accepted with `core.eol=lf`
+and could later be checked out with `core.eol=crlf`, in which case the
 resulting file would contain `CRLF`, although the original file
 contained `LF`.  However, in both work trees the line endings would be
 consistent, that is either all `LF` or all `CRLF`, but never mixed.  A
 file with mixed line endings would be reported by the `core.safecrlf`
 mechanism.
 
+core.autocrlf::
+ Setting this variable to "true" is almost the same as setting
+ the `text` attribute to "auto" on all files except that text
+ files are not guaranteed to be normalized: files that contain
+ `CRLF` in the repository will not be touched.  Use this
+ setting if you want to have `CRLF` line endings in your
+ working directory even though the repository does not have
+ normalized line endings.  This variable can be set to 'input',
+ in which case no output conversion is performed.
+
 core.symlinks::
  If false, symbolic links are checked out as small plain files that
  contain the link text. linkgit:git-update-index[1] and
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index f091f08..fce203d 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -99,7 +99,7 @@ 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.
+`core.eol` configuration variable for all text files.
 
 Set::
 
@@ -120,9 +120,9 @@ Set to string value "auto"::
 
 Unspecified::
 
- 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.
+ If the `text` attribute is unspecified, git uses the
+ `core.autocrlf` configuration variable to determine if the
+ file should be converted.
 
 Any other value causes git to act as if `text` has been left
 unspecified.
@@ -132,19 +132,19 @@ 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 `text` attribute.
+content checks, effectively 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 `text` and `core.autocrlf`.
+ This setting forces git to normalize line endings for this
+ file on checkin and convert them to CRLF when the file is
+ checked out.
 
 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 `text` and `core.autocrlf`.
+ checked out.
 
 Backwards compatibility with `crlf` attribute
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -193,9 +193,7 @@ config variable "core.autocrlf" without changing any attributes.
 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.
+already normalized in the repository stay normalized.
 
 If you want to interoperate with a source code management system that
 enforces end-of-line normalization, or you simply want all text files
@@ -207,7 +205,11 @@ attribute to "auto" for _all_ files.
 ------------------------
 
 This ensures that all files that git considers to be text will have
-normalized (LF) line endings in the repository.
+normalized (LF) line endings in the repository.  The `core.eol`
+configuration variable controls which line endings git will use for
+normalized files in your working directory; the default is to use the
+native line ending for your platform, or CRLF if `core.autocrlf` is
+set.
 
 NOTE: When `text=auto` normalization is enabled in an existing
 repository, any text files containing CRLFs should be normalized.  If
diff --git a/Makefile b/Makefile
index 910f471..419532e 100644
--- a/Makefile
+++ b/Makefile
@@ -224,6 +224,8 @@ all::
 #
 # Define CHECK_HEADER_DEPENDENCIES to check for problems in the hard-coded
 # dependency rules.
+#
+# Define NATIVE_CRLF if your platform uses CRLF for line endings.
 
 GIT-VERSION-FILE: FORCE
  @$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -989,6 +991,7 @@ ifeq ($(uname_S),Windows)
  NO_CURL = YesPlease
  NO_PYTHON = YesPlease
  BLK_SHA1 = YesPlease
+ NATIVE_CRLF = YesPlease
 
  CC = compat/vcbuild/scripts/clink.pl
  AR = compat/vcbuild/scripts/lib.pl
diff --git a/cache.h b/cache.h
index d1f669e..ac6bfbd 100644
--- a/cache.h
+++ b/cache.h
@@ -568,6 +568,19 @@ enum auto_crlf {
 
 extern enum auto_crlf auto_crlf;
 
+enum eol {
+ EOL_UNSET,
+ EOL_CRLF,
+ EOL_LF,
+#ifdef NATIVE_CRLF
+ EOL_NATIVE = EOL_CRLF
+#else
+ EOL_NATIVE = EOL_LF
+#endif
+};
+
+extern enum eol eol;
+
 enum branch_track {
  BRANCH_TRACK_UNSPECIFIED = -1,
  BRANCH_TRACK_NEVER = 0,
diff --git a/config.c b/config.c
index b60a1ff..1479ee6 100644
--- a/config.c
+++ b/config.c
@@ -461,6 +461,8 @@ static int git_default_core_config(const char *var, const char *value)
 
  if (!strcmp(var, "core.autocrlf")) {
  if (value && !strcasecmp(value, "input")) {
+ if (eol == EOL_CRLF)
+ return error("core.autocrlf=input conflicts with core.eol=crlf");
  auto_crlf = AUTO_CRLF_INPUT;
  return 0;
  }
@@ -477,6 +479,20 @@ static int git_default_core_config(const char *var, const char *value)
  return 0;
  }
 
+ if (!strcmp(var, "core.eol")) {
+ if (value && !strcasecmp(value, "lf"))
+ eol = EOL_LF;
+ else if (value && !strcasecmp(value, "crlf"))
+ eol = EOL_CRLF;
+ else if (value && !strcasecmp(value, "native"))
+ eol = EOL_NATIVE;
+ else
+ eol = EOL_UNSET;
+ if (eol == EOL_CRLF && auto_crlf == AUTO_CRLF_INPUT)
+ return error("core.autocrlf=input conflicts with core.eol=crlf");
+ return 0;
+ }
+
  if (!strcmp(var, "core.notesref")) {
  notes_ref_name = xstrdup(value);
  return 0;
diff --git a/convert.c b/convert.c
index a309e07..915949e 100644
--- a/convert.c
+++ b/convert.c
@@ -8,7 +8,7 @@
  * 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 "crlf" attribute or "auto_crlf" option is set.
+ * translation when the "text" attribute or "auto_crlf" option is set.
  */
 
 enum action {
@@ -20,12 +20,6 @@ enum action {
  CRLF_AUTO,
 };
 
-enum eol {
- EOL_UNSET,
- EOL_LF,
- EOL_CRLF,
-};
-
 struct text_stat {
  /* NUL, CR, LF and CRLF counts */
  unsigned nul, cr, lf, crlf;
@@ -99,33 +93,55 @@ static int is_binary(unsigned long size, struct text_stat *stats)
  return 0;
 }
 
+static enum eol determine_output_conversion(enum action action) {
+ switch (action) {
+ case CRLF_BINARY:
+ return EOL_UNSET;
+ case CRLF_CRLF:
+ return EOL_CRLF;
+ case CRLF_INPUT:
+ return EOL_LF;
+ case CRLF_GUESS:
+ if (!auto_crlf)
+ return EOL_UNSET;
+ /* fall through */
+ case CRLF_TEXT:
+ case CRLF_AUTO:
+ if (auto_crlf == AUTO_CRLF_TRUE)
+ return EOL_CRLF;
+ else if (auto_crlf == AUTO_CRLF_INPUT)
+ return EOL_LF;
+ else if (eol == EOL_UNSET)
+ return EOL_NATIVE;
+ }
+ return eol;
+}
+
 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 ||
-    (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_INPUT)) {
+ if (determine_output_conversion(action) == EOL_LF) {
  /*
  * CRLFs would not be restored by checkout:
  * check if we'd remove CRLFs
  */
  if (stats->crlf) {
  if (checksafe == SAFE_CRLF_WARN)
- warning("CRLF will be replaced by LF in %s.", path);
+ warning("CRLF will be replaced by LF in %s.\nThe file will have its original line endings in your working directory.", path);
  else /* i.e. SAFE_CRLF_FAIL */
  die("CRLF would be replaced by LF in %s.", path);
  }
- } else if (action == CRLF_CRLF ||
-   (action == CRLF_GUESS && auto_crlf == AUTO_CRLF_TRUE)) {
+ } else if (determine_output_conversion(action) == EOL_CRLF) {
  /*
  * CRLFs would be added by checkout:
  * check if we have "naked" LFs
  */
  if (stats->lf != stats->crlf) {
  if (checksafe == SAFE_CRLF_WARN)
- warning("LF will be replaced by CRLF in %s", path);
+ warning("LF will be replaced by CRLF in %s.\nThe file will have its original line endings in your working directory.", path);
  else /* i.e. SAFE_CRLF_FAIL */
  die("LF would be replaced by CRLF in %s", path);
  }
@@ -244,11 +260,7 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,
  char *to_free = NULL;
  struct text_stat stats;
 
- if ((action == CRLF_BINARY) || (action == CRLF_INPUT) ||
-    (action != CRLF_CRLF && auto_crlf != AUTO_CRLF_TRUE))
- return 0;
-
- if (!len)
+ if (!len || determine_output_conversion(action) != EOL_CRLF)
  return 0;
 
  gather_stats(src, len, &stats);
@@ -670,7 +682,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
 {
  struct git_attr_check check[5];
  enum action action = CRLF_GUESS;
- enum eol eol = EOL_UNSET;
+ enum eol eol_attr = EOL_UNSET;
  int ident = 0, ret = 0;
  const char *filter = NULL;
 
@@ -682,7 +694,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
  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);
+ eol_attr = git_path_check_eol(path, check + 3);
  if (drv && drv->clean)
  filter = drv->clean;
  }
@@ -692,7 +704,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
  src = dst->buf;
  len = dst->len;
  }
- action = determine_action(action, eol);
+ action = determine_action(action, eol_attr);
  ret |= crlf_to_git(path, src, len, dst, action, checksafe);
  if (ret) {
  src = dst->buf;
@@ -705,7 +717,7 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
 {
  struct git_attr_check check[5];
  enum action action = CRLF_GUESS;
- enum eol eol = EOL_UNSET;
+ enum eol eol_attr = EOL_UNSET;
  int ident = 0, ret = 0;
  const char *filter = NULL;
 
@@ -717,7 +729,7 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
  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);
+ eol_attr = git_path_check_eol(path, check + 3);
  if (drv && drv->smudge)
  filter = drv->smudge;
  }
@@ -727,7 +739,7 @@ int convert_to_working_tree(const char *path, const char *src, size_t len, struc
  src = dst->buf;
  len = dst->len;
  }
- action = determine_action(action, eol);
+ action = determine_action(action, eol_attr);
  ret |= crlf_to_worktree(path, src, len, dst, action);
  if (ret) {
  src = dst->buf;
diff --git a/environment.c b/environment.c
index db4a5e9..83d38d3 100644
--- a/environment.c
+++ b/environment.c
@@ -40,6 +40,7 @@ const char *editor_program;
 const char *excludes_file;
 enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
 int read_replace_refs = 1;
+enum eol eol = EOL_UNSET;
 enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
 unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
 enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
diff --git a/t/t0026-eol-config.sh b/t/t0026-eol-config.sh
new file mode 100755
index 0000000..f37ac8f
--- /dev/null
+++ b/t/t0026-eol-config.sh
@@ -0,0 +1,83 @@
+#!/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 &&
+
+ echo "one text" > .gitattributes
+
+ 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; done >two &&
+ git add . &&
+
+ git commit -m initial &&
+
+ one=`git rev-parse HEAD:one` &&
+ two=`git rev-parse HEAD:two` &&
+
+ echo happy.
+'
+
+test_expect_success 'eol=lf puts LFs in normalized file' '
+
+ rm -f .gitattributes tmp one two &&
+ git config core.eol lf &&
+ 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_success 'eol=crlf puts CRLFs in normalized file' '
+
+ rm -f .gitattributes tmp one two &&
+ git config core.eol crlf &&
+ 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_success 'autocrlf=true overrides eol=lf' '
+
+ rm -f .gitattributes tmp one two &&
+ git config core.eol lf &&
+ 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_success 'autocrlf=true overrides unset eol' '
+
+ rm -f .gitattributes tmp one two &&
+ git config --unset-all core.eol &&
+ 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_done
--
1.7.1.5.g82828

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH master] convert: The native line-ending is \r\n on MinGW

Jonathan Nieder-2
If you try this:

 1. Install Git for Windows (from the msysgit project)
 2. Put

        [core]
                autocrlf = false
                eol = native

    in your .gitconfig.
 3. Clone a project with

        *.txt text

    in its .gitattributes.

Then with current git, any text files checked out have LF line
endings, instead of the expected CRLF.

Cc: Johannes Schindelin <[hidden email]>
Cc: Johannes Sixt <[hidden email]>
Signed-off-by: Jonathan Nieder <[hidden email]>
---
Eyvind Bernhardsen wrote:

> Introduce a new configuration variable, "core.eol", that allows the user
> to set which line endings to use for end-of-line-normalized files in the
> working directory.  It defaults to "native", which means CRLF on Windows
> and LF everywhere else.

The following fixup has been sitting in my tree (but not tested on
Windows) for a couple of weeks.  Sensible?

I don't know what the right choice for Cygwin is; probably LF unless
there is some way to detect the systemwide setting at run time.

 Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index 40fbcae..ba08051 100644
--- a/Makefile
+++ b/Makefile
@@ -1125,6 +1125,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
  compat/win32/pthread.o
  EXTLIBS += -lws2_32
  PTHREAD_LIBS =
+ NATIVE_CRLF = YesPlease
  X = .exe
 ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
  htmldir=doc/git/html/
--
1.7.2.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Junio C Hamano
Jonathan Nieder <[hidden email]> writes:

> If you try this:
>
>  1. Install Git for Windows (from the msysgit project)
>  2. Put
>
> [core]
> autocrlf = false
> eol = native
>
>     in your .gitconfig.
>  3. Clone a project with
>
> *.txt text
>
>     in its .gitattributes.
>
> Then with current git, any text files checked out have LF line
> endings, instead of the expected CRLF.
>
> Cc: Johannes Schindelin <[hidden email]>
> Cc: Johannes Sixt <[hidden email]>
> Signed-off-by: Jonathan Nieder <[hidden email]>
> ---
> Eyvind Bernhardsen wrote:
>
>> Introduce a new configuration variable, "core.eol", that allows the user
>> to set which line endings to use for end-of-line-normalized files in the
>> working directory.  It defaults to "native", which means CRLF on Windows
>> and LF everywhere else.
>
> The following fixup has been sitting in my tree (but not tested on
> Windows) for a couple of weeks.  Sensible?
>
> I don't know what the right choice for Cygwin is; probably LF unless
> there is some way to detect the systemwide setting at run time.

Has anybody in Windows land any input?  I don't think what I do before
1.7.3 in my tree would matter much, so I am not applying this myself.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Ramsay Jones
Junio C Hamano wrote:
> Jonathan Nieder <[hidden email]> writes:
>

>>
>>> Introduce a new configuration variable, "core.eol", that allows the user
>>> to set which line endings to use for end-of-line-normalized files in the
>>> working directory.  It defaults to "native", which means CRLF on Windows
>>> and LF everywhere else.
>> The following fixup has been sitting in my tree (but not tested on
>> Windows) for a couple of weeks.  Sensible?
>>
>> I don't know what the right choice for Cygwin is; probably LF unless
>> there is some way to detect the systemwide setting at run time.
>
> Has anybody in Windows land any input?  I don't think what I do before
> 1.7.3 in my tree would matter much, so I am not applying this myself.

Sorry for the late reply to this; I've only just noticed that I hadn't
replied! ;-)

FWIW, I suspect that anything other than LF as the eol on Cygwin would
be *insane*. ;-D

ATB,
Ramsay Jones


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Mr_and_Mrs_D
In reply to this post by Junio C Hamano
I am on windows 7 Pro - mingwin

I decided to turn autocrlf to false and use .gitattributes instead and was bitten by this bug :

http://stackoverflow.com/questions/13531988/git-line-endings-renormalize-does-not-seem-to-checkout-the-right-line-endings

It took me 2 days to figure this out

Please fix
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Brice Lambson
Mr_and_Mrs_D <the.ubik <at> gmail.com> writes:



>

> I am on windows 7 Pro - mingwin

>

> I decided to turn autocrlf to false and use .gitattributes instead and was

> bitten by this bug :

>

> http://stackoverflow.com/questions/13531988/git-line-endings-renormalize-
does-not-seem-to-checkout-the-right-line-endings

>

> It took me 2 days to figure this out

>

> Please fix

>

> --

> View this message in context: http://git.661346.n2.nabble.com/PATCH-v6-
Add-core-eol-config-variable-tp5140844p7571889.html

> Sent from the git mailing list archive at Nabble.com.

>



+1, this is a significant issue downstream in Git for Windows:



https://github.com/msysgit/git/issues/57



Effectively this renders .gitattributes useless for the scenario of
enforcing normalized line ending characters.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Junio C Hamano
In reply to this post by Junio C Hamano
Junio C Hamano <[hidden email]> writes:

> Jonathan Nieder <[hidden email]> writes:
>
>> If you try this:
>>
>>  1. Install Git for Windows (from the msysgit project)
>>  2. Put
>>
>> [core]
>> autocrlf = false
>> eol = native
>>
>>     in your .gitconfig.
>>  3. Clone a project with
>>
>> *.txt text
>>
>>     in its .gitattributes.
>>
>> Then with current git, any text files checked out have LF line
>> endings, instead of the expected CRLF.
>>
>> Cc: Johannes Schindelin <[hidden email]>
>> Cc: Johannes Sixt <[hidden email]>
>> Signed-off-by: Jonathan Nieder <[hidden email]>
>> ---
>> Eyvind Bernhardsen wrote:
>>
>>> Introduce a new configuration variable, "core.eol", that allows the user
>>> to set which line endings to use for end-of-line-normalized files in the
>>> working directory.  It defaults to "native", which means CRLF on Windows
>>> and LF everywhere else.
>>
>> The following fixup has been sitting in my tree (but not tested on
>> Windows) for a couple of weeks.  Sensible?
>>
>> I don't know what the right choice for Cygwin is; probably LF unless
>> there is some way to detect the systemwide setting at run time.
>
> Has anybody in Windows land any input?  I don't think what I do before
> 1.7.3 in my tree would matter much, so I am not applying this myself.

Pinging MsysGit folk again ...


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Erik Faye-Lund-2
On Mon, Apr 15, 2013 at 11:00 PM, Junio C Hamano <[hidden email]> wrote:

> Junio C Hamano <[hidden email]> writes:
>
>> Jonathan Nieder <[hidden email]> writes:
>>
>>> If you try this:
>>>
>>>  1. Install Git for Windows (from the msysgit project)
>>>  2. Put
>>>
>>>      [core]
>>>              autocrlf = false
>>>              eol = native
>>>
>>>     in your .gitconfig.
>>>  3. Clone a project with
>>>
>>>      *.txt text
>>>
>>>     in its .gitattributes.
>>>
>>> Then with current git, any text files checked out have LF line
>>> endings, instead of the expected CRLF.
>>>
>>> Cc: Johannes Schindelin <[hidden email]>
>>> Cc: Johannes Sixt <[hidden email]>
>>> Signed-off-by: Jonathan Nieder <[hidden email]>
>>> ---
>>> Eyvind Bernhardsen wrote:
>>>
>>>> Introduce a new configuration variable, "core.eol", that allows the user
>>>> to set which line endings to use for end-of-line-normalized files in the
>>>> working directory.  It defaults to "native", which means CRLF on Windows
>>>> and LF everywhere else.
>>>
>>> The following fixup has been sitting in my tree (but not tested on
>>> Windows) for a couple of weeks.  Sensible?
>>>
>>> I don't know what the right choice for Cygwin is; probably LF unless
>>> there is some way to detect the systemwide setting at run time.
>>
>> Has anybody in Windows land any input?  I don't think what I do before
>> 1.7.3 in my tree would matter much, so I am not applying this myself.
>
> Pinging MsysGit folk again ...
>
>

This is absolutely the right thing to do. However, stuff have changed
a bit since the patch was written; this change now needs to go in
config.mak.uname instead of config.mak.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Junio C Hamano
Erik Faye-Lund <[hidden email]> writes:

> This is absolutely the right thing to do. However, stuff have changed
> a bit since the patch was written; this change now needs to go in
> config.mak.uname instead of config.mak.

Thanks for a quick response.

What's your preference?  I could just ignore a patch I won't be able
to test myself and have you guys carry it in your tree forever, but
I do not think that is necessary for something small like this.

I think this is low impact enough that it can directly go to
'master' or even 'maint' if I were to apply to my tree.

Thanks.

-- >8 --
From: Jonathan Nieder <[hidden email]>
Date: Sat, 4 Sep 2010 03:25:09 -0500
Subject: [PATCH] convert: The native line-ending is \r\n on MinGW

If you try this:

 1. Install Git for Windows (from the msysgit project)

 2. Put

        [core]
                autocrlf = false
                eol = native

    in your .gitconfig.

 3. Clone a project with

        *.txt text

    in its .gitattributes.

Then with current git, any text files checked out have LF line
endings, instead of the expected CRLF.

Cc: Johannes Schindelin <[hidden email]>
Cc: Johannes Sixt <[hidden email]>
Signed-off-by: Jonathan Nieder <[hidden email]>
Signed-off-by: Junio C Hamano <[hidden email]>
---
 config.mak.uname | 1 +
 1 file changed, 1 insertion(+)

diff --git a/config.mak.uname b/config.mak.uname
index 9080054..d78fd3d 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -507,6 +507,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
  compat/win32/dirent.o
  EXTLIBS += -lws2_32
  PTHREAD_LIBS =
+ NATIVE_CRLF = YesPlease
  X = .exe
  SPARSE_FLAGS = -Wno-one-bit-signed-bitfield
 ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
--
1.8.2.1-542-g3613165

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Erik Faye-Lund-2
On Mon, Apr 15, 2013 at 11:43 PM, Junio C Hamano <[hidden email]> wrote:

> Erik Faye-Lund <[hidden email]> writes:
>
>> This is absolutely the right thing to do. However, stuff have changed
>> a bit since the patch was written; this change now needs to go in
>> config.mak.uname instead of config.mak.
>
> Thanks for a quick response.
>
> What's your preference?  I could just ignore a patch I won't be able
> to test myself and have you guys carry it in your tree forever, but
> I do not think that is necessary for something small like this.

I should probably clarify; conceptually, this is the right thing to
do. Git for Windows is a Windows application, and should have CRLF as
the native newline. I hadn't tested this patch myself, though. Our
tree is currently way behind yours, and I tried to do a rebase, but it
turned out much trickier than I was hoping for.

I've given it a go on top of your tree + some essential patches I'll
need to get things to run, and it seems to do what it claims to do.
However, I haven't been able to run the test-suite, because I need a
bunch more patches from the msysGit-tree for that.

> I think this is low impact enough that it can directly go to
> 'master' or even 'maint' if I were to apply to my tree.
>

I agree. I don't think we need it in maint; we don't track that branch
for msysGit.

> Thanks.
>
> -- >8 --
> From: Jonathan Nieder <[hidden email]>
> Date: Sat, 4 Sep 2010 03:25:09 -0500
> Subject: [PATCH] convert: The native line-ending is \r\n on MinGW
>
> If you try this:
>
>  1. Install Git for Windows (from the msysgit project)
>
>  2. Put
>
>         [core]
>                 autocrlf = false
>                 eol = native
>
>     in your .gitconfig.
>
>  3. Clone a project with
>
>         *.txt text
>
>     in its .gitattributes.
>
> Then with current git, any text files checked out have LF line
> endings, instead of the expected CRLF.
>
> Cc: Johannes Schindelin <[hidden email]>
> Cc: Johannes Sixt <[hidden email]>
> Signed-off-by: Jonathan Nieder <[hidden email]>
> Signed-off-by: Junio C Hamano <[hidden email]>
> ---
>  config.mak.uname | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/config.mak.uname b/config.mak.uname
> index 9080054..d78fd3d 100644
> --- a/config.mak.uname
> +++ b/config.mak.uname
> @@ -507,6 +507,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
>                 compat/win32/dirent.o
>         EXTLIBS += -lws2_32
>         PTHREAD_LIBS =
> +       NATIVE_CRLF = YesPlease
>         X = .exe
>         SPARSE_FLAGS = -Wno-one-bit-signed-bitfield
>  ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
> --
> 1.8.2.1-542-g3613165
>

Looks fine to me.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Johannes Sixt-3
Am 16.04.2013 16:39, schrieb Erik Faye-Lund:

> On Mon, Apr 15, 2013 at 11:43 PM, Junio C Hamano <[hidden email]> wrote:
>> Erik Faye-Lund <[hidden email]> writes:
>>
>>> This is absolutely the right thing to do. However, stuff have changed
>>> a bit since the patch was written; this change now needs to go in
>>> config.mak.uname instead of config.mak.
>>
>> Thanks for a quick response.
>>
>> What's your preference?  I could just ignore a patch I won't be able
>> to test myself and have you guys carry it in your tree forever, but
>> I do not think that is necessary for something small like this.
>
> I should probably clarify; conceptually, this is the right thing to
> do. Git for Windows is a Windows application, and should have CRLF as
> the native newline. I hadn't tested this patch myself, though. Our
> tree is currently way behind yours, and I tried to do a rebase, but it
> turned out much trickier than I was hoping for.
>
> I've given it a go on top of your tree + some essential patches I'll
> need to get things to run, and it seems to do what it claims to do.
> However, I haven't been able to run the test-suite, because I need a
> bunch more patches from the msysGit-tree for that.

I have been using this patch or an equivalent one since at least one and
a half years (until a month or two ago, as I discovered today, but that
is only by accident). But I do not use any text attributes or eol
configuration, so I can only say that it does not regress this use case.

>
>> I think this is low impact enough that it can directly go to
>> 'master' or even 'maint' if I were to apply to my tree.
>>
>
> I agree. I don't think we need it in maint; we don't track that branch
> for msysGit.

Yes, master is good enough.

Thanks.

>
>> Thanks.
>>
>> -- >8 --
>> From: Jonathan Nieder <[hidden email]>
>> Date: Sat, 4 Sep 2010 03:25:09 -0500
>> Subject: [PATCH] convert: The native line-ending is \r\n on MinGW
>>
>> If you try this:
>>
>>  1. Install Git for Windows (from the msysgit project)
>>
>>  2. Put
>>
>>         [core]
>>                 autocrlf = false
>>                 eol = native
>>
>>     in your .gitconfig.
>>
>>  3. Clone a project with
>>
>>         *.txt text
>>
>>     in its .gitattributes.
>>
>> Then with current git, any text files checked out have LF line
>> endings, instead of the expected CRLF.
>>
>> Cc: Johannes Schindelin <[hidden email]>
>> Cc: Johannes Sixt <[hidden email]>
>> Signed-off-by: Jonathan Nieder <[hidden email]>
>> Signed-off-by: Junio C Hamano <[hidden email]>
>> ---
>>  config.mak.uname | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/config.mak.uname b/config.mak.uname
>> index 9080054..d78fd3d 100644
>> --- a/config.mak.uname
>> +++ b/config.mak.uname
>> @@ -507,6 +507,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
>>                 compat/win32/dirent.o
>>         EXTLIBS += -lws2_32
>>         PTHREAD_LIBS =
>> +       NATIVE_CRLF = YesPlease
>>         X = .exe
>>         SPARSE_FLAGS = -Wno-one-bit-signed-bitfield
>>  ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
>> --
>> 1.8.2.1-542-g3613165
>>
>
> Looks fine to me.
>

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Junio C Hamano
Johannes Sixt <[hidden email]> writes:

>> I agree. I don't think we need it in maint; we don't track that branch
>> for msysGit.
>
> Yes, master is good enough.

Thanks to all those involved.  Applied.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Tvangeste
In reply to this post by Brice Lambson
Brice Lambson <bricelam <at> live.com> writes:
> +1, this is a significant issue downstream in Git for Windows:
>
> https://github.com/msysgit/git/issues/57
>
> Effectively this renders .gitattributes useless for the scenario of
> enforcing normalized line ending characters.

+100

Folks, the problem is still there, with the very latest Git built with MinGW
on Windows. Having eol=native in gitattributes means *LF* EOLs on
Windows/MinGW.

So, essentially, eol=native is completely broken. And this is the most useful
option to put into gitattributes and share among those working on the project.

Currently, I have to put eol=crlf there, and that means that those working on
Linux will end up with CRLF files in their working copies.

The link quoted above does contain an additional fix that resolves the
problem.

Thanks,
  --Tvangeste

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH master] convert: The native line-ending is \r\n on MinGW

Junio C Hamano
Tvangeste <[hidden email]> writes:

> Brice Lambson <bricelam <at> live.com> writes:
>> +1, this is a significant issue downstream in Git for Windows:
>>
>> https://github.com/msysgit/git/issues/57
>>
>> Effectively this renders .gitattributes useless for the scenario of
>> enforcing normalized line ending characters.
>
> +100
>
> Folks, the problem is still there, with the very latest Git built with MinGW
> on Windows. Having eol=native in gitattributes means *LF* EOLs on
> Windows/MinGW.

The patch in the thread you are responding to is v1.8.3-rc0~65, so
as far as the upstream git.git is concerned the issue is closed, but
I cannot say that inter-project coordination between us and Git for
Windows are stellar (no we are not fighting against each other, but
being less intimate with what the other is doing than we could be).

Judging from how the original thread ended:

  http://thread.gmane.org/gmane.comp.version-control.git/148436/focus=221438

Eric and J6t (cc'ed) are aware of this patch that went into 1.8.3,
so...
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Loading...