[darcs-users] Re: Line endings opinion poll (with bonus option)

Kannan Goundan cakoose at yahoo.com
Wed Nov 3 20:29:34 UTC 2004

Martin Schaffner wrote:

> Kannan Goundan wrote:
> > 1. Hunk patches can specify their line-ending.  This can be done
> > by either
> >    - Keeping the line endings on the '+' hunk entries.
> This is the current behaviour:
> Example on Unix:
>    before: " line1 \n line2",
>    after: " lineA \n lineB ",
>    patch: "- line1 \n- line 2 \n+ line A \n+ lineB "
> Same example on Windows:
>    before: " line1 \r\n line2",
>    after: " lineA \r\n lineB ",
>    patch: "- line1 \r\n- line 2 \n+ line A \r\n+ lineB "

Hmm...so when you pull a patch, is it converted to the native
line-ending format or left alone?

> > 2. When Darcs modifies a working copy of an existing (non-empty)
> > file, it should detect the line ending of the working copy and
> > preserve it.

> * Does not work for mixed-endings files.

Correct.  For mixed-ending files Darcs could keep doing whatever it
is doing now.

> * What if the ending is already "wrong"?

I'm assuming that "wrong" means "not what the user wants".  Well, if
the file in the user's directory is in the wrong format *before*
applying the patch, then there's no reason to expect Darcs to fix
that automatically.

> > 3. When Darcs has to add content to a new file (or add to an
> > empty one), it has to decide what line-ending to use.
> If I want to add a line to file foo.c, then the patch for this will
> look different depending on which platform I did "darcs get" to 
> checkout the repo on which I work.

Correct.  This is why it would be nice for hunk patches to be
line-ending agnostic.  99% of the time, that's what people want. 
Maybe if the source file has mixed line-endings, Darcs could be
explicit about the line-endings for each line in the hunk.
> >  This preference
> > setting can be one of:
> >   [...]
> >    Patch - Use same line-endings as the latest hunk patch.
> The orders with which I pull from the repos will therefore matter, 
> which is against darcs' philosophy

True...I thought that this option might be a useful way to explicitly
control line-endings through patches, but I guess it's not worth it.

> > I think that this will minimize the chances that Darcs will
> > change the line-ending format on you.
> It is still there, I still have to worry about it.
> Now, for some constructive criticism:
> If a line-ending feature is desired, then IMO it should be as
> simple as 
> possible:
> How about a single --using-dos-line-endings option for all relevant
> commands, that is disabled by default, can be added to 
> _darcs/prefs/defaults, and does:
> * Turn '\n' into '\r\n' when adding lines from patches into working
> * Turn '\r\n' into '\n' when creating patches from working
> This way, DOS-line-ending-utilites-using users could enable this 
> option, knowing about its potential problems, and the user
> interface 
> complexity of darcs (as well as the implementation complexity) is 
> increased by a minimum.
> Maybe this option should even be enabled by default for the windows
> build, so Hacker Hal does not get annoyed by Newbie Ned's carriage 
> return characters, but then again, this would require a second 
> --not-using-dos-line-endings option.

The behavior you describe can be emulated if Darcs behaves as I
described.  If you want DOS line-endings:
  - Run unix2dos on all the files in your repo.  When Darcs modifies
them, it will preserve the line-endings.
  - Set the "new files" configuration option to DOS.  This will tell
Darcs that empty files and new files should be set to the DOS
line-ending format.

This is simpler and more transparent than a "--use-dos-line-endings"
option.  The other advantage is that you can use Unix line endings
for certain files by running "dos2unix" on them.

As long as Darcs starts ignoring line-endings on patches, Hacker Hal
won't have to know that Newbie Ned's repo is using DOS line endings.

> > BTW, Visual Studio seems to allow mixing both types of
> > line-endings in a single file.  If you open up a Unix file,
> > change some lines, and save it, all the unmodified lines
> > will be Unix and the modified ones will be DOS.  Not sure
> > if Darcs should handle this or not
> This is no problem for darcs.

Right now it isn't, but I was trying to figure out what Darcs should
do if it adopts the policy of trying to preserve existing
line-endings.  When you have a hunk that replaces a segment of text,
should the added lines be changed to use the line-endings of the
deleted lines?  I don't use text files with mixed line-endings so I
don't really care what Darcs does, but people who do used mixed
line-endings may have requirements on how patching should work.

> > (Vim doesn't).
> The version of vi that comes with Mac OS X 10.3.5 has no problem 
> either: it even adds the same new newlines as the ones it finds 
> already.

Well, I shouldn't have said that Vim *doesn't* handle these files. 
It can edit them just fine...it's just that it shows the "\r"
characters as "^M", which is annoying to look at.  Though this might
be the right thing to do (since you shouldn't be using mixed-endings
files anyway), but it's annoying to look at :)  Then again, it makes
it easier to see what's going on with line-endings in Darcs patch files.

Do you Yahoo!? 
Check out the new Yahoo! Front Page. 

More information about the darcs-users mailing list