[PATCH] D51444: [git-llvm] Fix eol conversion on Windows for explicit CRLF files
Zachary Turner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 7 21:26:03 PDT 2018
zturner updated this revision to Diff 168608.
zturner added a comment.
I never got around to getting this committed, but incidentally I built a new machine over the weekend and ran into the same problem *plus* an additional problem which is that with Python 3, `git apply` doesn't like it when `universal_newlines` is set to true. Without this additional changes, it is impossible to push anything using the following configuration:
Windows 10
Git 2.18.0.windows.1
Python 3.7.0 32-bit
Running `git llvm push` from a `cmd` prompt.
https://reviews.llvm.org/D51444
Files:
llvm/utils/git-svn/git-llvm
Index: llvm/utils/git-svn/git-llvm
===================================================================
--- llvm/utils/git-svn/git-llvm
+++ llvm/utils/git-svn/git-llvm
@@ -97,22 +97,30 @@
def shell(cmd, strip=True, cwd=None, stdin=None, die_on_failure=True,
- ignore_errors=False):
+ ignore_errors=False, force_binary_stdin=False):
log_verbose('Running: %s' % ' '.join(cmd))
err_pipe = subprocess.PIPE
if ignore_errors:
# Silence errors if requested.
err_pipe = get_dev_null()
+ if force_binary_stdin and stdin:
+ stdin = stdin.encode('utf-8')
+
start = time.time()
+ text = not force_binary_stdin
p = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=err_pipe,
- stdin=subprocess.PIPE, universal_newlines=True)
+ stdin=subprocess.PIPE, universal_newlines=text)
stdout, stderr = p.communicate(input=stdin)
elapsed = time.time() - start
log_verbose('Command took %0.1fs' % elapsed)
+ if not text:
+ stdout = stdout.decode('utf-8')
+ stderr = stderr.decode('utf-8')
+
if p.returncode == 0 or ignore_errors:
if stderr and not ignore_errors:
eprint('`%s` printed to stderr:' % ' '.join(cmd))
@@ -223,7 +231,7 @@
crlf_files = []
if len(files) == 1:
# No need to split propget output on ' - ' when we have one file.
- if eol_props.strip() == 'native':
+ if eol_props.strip() in ['native', 'CRLF']:
crlf_files = files
else:
for eol_prop in eol_props.split('\n'):
@@ -239,11 +247,11 @@
(f, eol_style) = prop_parts
if eol_style == 'native':
crlf_files.append(f)
- # Reformat all files with native SVN line endings to Unix format. SVN knows
- # files with native line endings are text files. It will commit just the
- # diff, and not a mass line ending change.
- shell(['dos2unix', '-q'] + crlf_files, cwd=svn_sr_path)
-
+ if crlf_files:
+ # Reformat all files with native SVN line endings to Unix format. SVN knows
+ # files with native line endings are text files. It will commit just the
+ # diff, and not a mass line ending change.
+ shell(['dos2unix'] + crlf_files, ignore_errors=True, cwd=svn_sr_path)
def svn_push_one_rev(svn_repo, rev, dry_run):
files = git('diff-tree', '--no-commit-id', '--name-only', '-r',
@@ -265,8 +273,10 @@
# git is the only thing that can handle its own patches...
log_verbose('Apply patch: %s' % diff)
try:
+ # If we allow python to apply the diff in text mode, it will silently
+ # convert \n to \r\n which git doesn't like.
shell(['git', 'apply', '-p2', '-'], cwd=svn_sr_path, stdin=diff,
- die_on_failure=False)
+ die_on_failure=False, force_binary_stdin=True)
except RuntimeError as e:
eprint("Patch doesn't apply: maybe you should try `git pull -r` "
"first?")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51444.168608.patch
Type: text/x-patch
Size: 3087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181008/3b0d0f98/attachment.bin>
More information about the llvm-commits
mailing list