Skip to content

Preserve windows line endings in pubspec.lock if they are already there #2489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

sigurdm
Copy link
Contributor

@sigurdm sigurdm commented May 12, 2020

Fixes: #2487

@sigurdm sigurdm requested a review from jonasfj May 12, 2020 10:05
Copy link
Member

@jonasfj jonasfj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just nits :D

@@ -98,6 +107,7 @@ class LockFile {
Uri sourceUrl;
if (filePath != null) sourceUrl = p.toUri(filePath);
var parsed = loadYamlNode(contents, sourceUrl: sourceUrl);
final windowsLineEndings = contents.contains('\r\n');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to be a bit more robust we do count(contents, '\r\n') > count(contents, '\n'), using:

int count(String s, Pattern p) {
  int c = 0;
  int i = -1;
  while ((i = s.indexOf(p, i + 1)) != -1) {
    c++;
  }
  return c;
}

So if there is more CRLF's than LFs we use CRLF, otherwise we use LF.

It's hard to imagine things getting mixed.. But maybe if someone edits the pubspec.lock or manually resolves a merge conflict? (I suspect most editors would normalize line endings, but just in case it might be nice).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We at least have to make it count(contents, '\r\n') > count(contents, '[^\r]\n').

But yes, it would probably be safer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sigurdm sigurdm requested a review from jonasfj May 14, 2020 09:13
Copy link
Member

@jonasfj jonasfj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet!

var lockFilePath = root.path('pubspec.lock');
writeTextFile(lockFilePath, _lockFile.serialize(root.dir));
_lockFile =
result.lockFile(windowsLineEndings: lockFile.windowsLineEndings);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you miss something here, didn't you remove the windowsLineEndings state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - I think I made a bad merge...

Fixed

@sigurdm sigurdm merged commit 27bc4f7 into dart-lang:master May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pub get (flutter) changes pubspec.lock EOL to LF even when on windows
3 participants