5
5
import re
6
6
import subprocess
7
7
from urllib .parse import unquote
8
- from codecs import decode , escape_decode
9
8
10
9
import pexpect
11
10
import tornado
@@ -169,14 +168,14 @@ async def changed_files(self, base=None, remote=None, single_commit=None):
169
168
}
170
169
"""
171
170
if single_commit :
172
- cmd = ["git" , "diff" , "{}^!" .format (single_commit ), "--name-only" ]
171
+ cmd = ["git" , "diff" , "{}^!" .format (single_commit ), "--name-only" , "-z" ]
173
172
elif base and remote :
174
173
if base == "WORKING" :
175
- cmd = ["git" , "diff" , remote , "--name-only" ]
174
+ cmd = ["git" , "diff" , remote , "--name-only" , "-z" ]
176
175
elif base == "INDEX" :
177
- cmd = ["git" , "diff" , "--staged" , remote , "--name-only" ]
176
+ cmd = ["git" , "diff" , "--staged" , remote , "--name-only" , "-z" ]
178
177
else :
179
- cmd = ["git" , "diff" , base , remote , "--name-only" ]
178
+ cmd = ["git" , "diff" , base , remote , "--name-only" , "-z" ]
180
179
else :
181
180
raise tornado .web .HTTPError (
182
181
400 , "Either single_commit or (base and remote) must be provided"
@@ -194,7 +193,7 @@ async def changed_files(self, base=None, remote=None, single_commit=None):
194
193
response ["command" ] = " " .join (cmd )
195
194
response ["message" ] = error
196
195
else :
197
- response ["files" ] = output .strip ().split ("\n " )
196
+ response ["files" ] = output .strip (" \x00 " ).split ("\x00 " )
198
197
199
198
return response
200
199
@@ -237,7 +236,7 @@ async def status(self, current_path):
237
236
"""
238
237
Execute git status command & return the result.
239
238
"""
240
- cmd = ["git" , "status" , "--porcelain" , "-u" ]
239
+ cmd = ["git" , "status" , "--porcelain" , "-u" , "-z" ]
241
240
code , my_output , my_error = await execute (
242
241
cmd , cwd = os .path .join (self .root_dir , current_path ),
243
242
)
@@ -250,22 +249,24 @@ async def status(self, current_path):
250
249
}
251
250
252
251
result = []
253
- line_array = my_output .splitlines ()
254
- for line in line_array :
255
- to1 = None
256
- from_path = line [3 :]
257
- if line [0 ] == "R" :
258
- to0 = line [3 :].split (" -> " )
259
- to1 = to0 [len (to0 ) - 1 ]
252
+ line_iterable = iter (my_output .strip ("\x00 " ).split ('\x00 ' ))
253
+ result = []
254
+ for line in line_iterable :
255
+ x = line [0 ]
256
+ y = line [1 ]
257
+ if line [0 ]== 'R' :
258
+ #If file was renamed then we need both this line
259
+ #and the next line, then we want to move onto the subsequent
260
+ #line. We can accomplish this by calling next on the iterable
261
+ to = line [3 :]
262
+ from_path = next (line_iterable )
260
263
else :
261
- to1 = line [3 :]
262
- if to1 .startswith ('"' ):
263
- to1 = to1 [1 :]
264
- if to1 .endswith ('"' ):
265
- to1 = to1 [:- 1 ]
266
- to1 = decode (escape_decode (to1 )[0 ],'utf-8' )
267
- from_path = decode (escape_decode (from_path )[0 ],'utf-8' )
268
- result .append ({"x" : line [0 ], "y" : line [1 ], "to" : to1 , "from" : from_path })
264
+ #to and from_path are the same
265
+ from_path = line [3 :]
266
+ to = line [3 :]
267
+ result .append ({"x" : x , "y" : y , "to" : to , "from" : from_path })
268
+
269
+
269
270
return {"code" : code , "files" : result }
270
271
271
272
async def log (self , current_path , history_count = 10 ):
@@ -314,10 +315,10 @@ async def log(self, current_path, history_count=10):
314
315
315
316
async def detailed_log (self , selected_hash , current_path ):
316
317
"""
317
- Execute git log -1 --stat --numstat --oneline command (used to get
318
+ Execute git log -1 --stat --numstat --oneline -z command (used to get
318
319
insertions & deletions per file) & return the result.
319
320
"""
320
- cmd = ["git" , "log" , "-1" , "--stat" , "--numstat" , "--oneline" , selected_hash ]
321
+ cmd = ["git" , "log" , "-1" , "--stat" , "--numstat" , "--oneline" , "-z" , selected_hash ]
321
322
code , my_output , my_error = await execute (
322
323
cmd , cwd = os .path .join (self .root_dir , current_path ),
323
324
)
@@ -329,7 +330,7 @@ async def detailed_log(self, selected_hash, current_path):
329
330
note = [0 ] * 3
330
331
count = 0
331
332
temp = ""
332
- line_array = my_output . splitlines ( )
333
+ line_array = re . split ( " \x00 | \n | \r \n | \r " , my_output )
333
334
length = len (line_array )
334
335
INSERTION_INDEX = 0
335
336
DELETION_INDEX = 1
@@ -342,7 +343,7 @@ async def detailed_log(self, selected_hash, current_path):
342
343
note [count ] = words [i ]
343
344
count += 1
344
345
for num in range (1 , int (length / 2 )):
345
- line_info = line_array [num ].split (maxsplit = 2 )
346
+ line_info = line_array [num ].split (' \t ' , maxsplit = 2 )
346
347
words = line_info [2 ].split ("/" )
347
348
length = len (words )
348
349
result .append (
@@ -373,14 +374,14 @@ async def diff(self, top_repo_path):
373
374
"""
374
375
Execute git diff command & return the result.
375
376
"""
376
- cmd = ["git" , "diff" , "--numstat" ]
377
+ cmd = ["git" , "diff" , "--numstat" , "-z" ]
377
378
code , my_output , my_error = await execute (cmd , cwd = top_repo_path )
378
379
379
380
if code != 0 :
380
381
return {"code" : code , "command" : " " .join (cmd ), "message" : my_error }
381
382
382
383
result = []
383
- line_array = my_output .splitlines ( )
384
+ line_array = my_output .strip ( ' \x00 ' ). split ( ' \x00 ' )
384
385
for line in line_array :
385
386
linesplit = line .split ()
386
387
result .append (
0 commit comments