From b81258f7ef1203761a504367995eb3ea0e0657cf Mon Sep 17 00:00:00 2001
From: Vedant Kumar <vsk@apple.com>
Date: Sat, 10 Dec 2016 00:54:13 +0000
Subject: [PATCH] [clang-format] Another attempt at python 3 compatibility

The entries in vim.current.buffer appear to be decoded strings, which
means that python3 won't allow invoking 'decode' on them. Keep the old
behavior when running under python2, but skip the error-inducing decode
step with python3..

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289308 91177308-0d34-0410-b5e6-96231b3b80d8
---
 tools/clang-format/clang-format.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/clang-format/clang-format.py b/tools/clang-format/clang-format.py
index aded301781..ae8a6ebf74 100644
--- a/tools/clang-format/clang-format.py
+++ b/tools/clang-format/clang-format.py
@@ -29,6 +29,7 @@ from __future__ import print_function
 
 import difflib
 import json
+import platform
 import subprocess
 import sys
 import vim
@@ -48,10 +49,15 @@ fallback_style = None
 if vim.eval('exists("g:clang_format_fallback_style")') == "1":
   fallback_style = vim.eval('g:clang_format_fallback_style')
 
+def get_buffer(encoding):
+  if platform.python_version_tuple()[0] == '3':
+    return vim.current.buffer
+  return [ line.decode(encoding) for line in vim.current.buffer ]
+
 def main():
   # Get the current text.
   encoding = vim.eval("&encoding")
-  buf = [ line.decode(encoding) for line in vim.current.buffer ]
+  buf = get_buffer(encoding)
   text = '\n'.join(buf)
 
   # Determine range to format.
-- 
2.40.0