@@ -25,7 +25,7 @@ async def execute(
25
25
password : "Optional[str]" = None ,
26
26
) -> "Tuple[int, str, str]" :
27
27
"""Asynchronously execute a command.
28
-
28
+
29
29
Args:
30
30
cmdline (List[str]): Command line to be executed
31
31
cwd (Optional[str]): Current working directory
@@ -101,6 +101,12 @@ def call_subprocess(
101
101
102
102
return code , output , error
103
103
104
+ def strip_and_split (s ):
105
+ """strip trailing \x00 and split on \x00
106
+
107
+ Useful for parsing output of git commands with -z flag.
108
+ """
109
+ return s .strip ("\x00 " ).split ("\x00 " )
104
110
105
111
class Git :
106
112
"""
@@ -110,17 +116,10 @@ class Git:
110
116
def __init__ (self , contents_manager ):
111
117
self .contents_manager = contents_manager
112
118
self .root_dir = os .path .expanduser (contents_manager .root_dir )
113
-
114
- def strip_and_split (self , s ):
115
- """strip trailing \x00 and split on \x00
116
-
117
- Useful for parsing output of git commands with -z flag.
118
- """
119
- return s .strip ("\x00 " ).split ("\x00 " )
120
119
121
120
async def config (self , top_repo_path , ** kwargs ):
122
121
"""Get or set Git options.
123
-
122
+
124
123
If no kwargs, all options are returned. Otherwise kwargs are set.
125
124
"""
126
125
response = {"code" : 1 }
@@ -161,12 +160,12 @@ async def changed_files(self, base=None, remote=None, single_commit=None):
161
160
There are two reserved "refs" for the base
162
161
1. WORKING : Represents the Git working tree
163
162
2. INDEX: Represents the Git staging area / index
164
-
163
+
165
164
Keyword Arguments:
166
165
single_commit {string} -- The single commit ref
167
166
base {string} -- the base Git ref
168
167
remote {string} -- the remote Git ref
169
-
168
+
170
169
Returns:
171
170
dict -- the response of format {
172
171
"code": int, # Command status code
@@ -200,7 +199,7 @@ async def changed_files(self, base=None, remote=None, single_commit=None):
200
199
response ["command" ] = " " .join (cmd )
201
200
response ["message" ] = error
202
201
else :
203
- response ["files" ] = self . strip_and_split (output )
202
+ response ["files" ] = strip_and_split (output )
204
203
205
204
return response
206
205
@@ -256,23 +255,15 @@ async def status(self, current_path):
256
255
}
257
256
258
257
result = []
259
- line_iterable = iter (self .strip_and_split (my_output ))
260
- result = []
258
+ line_iterable = iter (strip_and_split (my_output ))
261
259
for line in line_iterable :
262
- x = line [0 ]
263
- y = line [1 ]
260
+ from_path = line [3 :]
264
261
if line [0 ]== 'R' :
265
262
#If file was renamed then we need both this line
266
263
#and the next line, then we want to move onto the subsequent
267
264
#line. We can accomplish this by calling next on the iterable
268
- to = line [3 :]
269
265
from_path = next (line_iterable )
270
- else :
271
- #to and from_path are the same
272
- from_path = line [3 :]
273
- to = line [3 :]
274
- result .append ({"x" : x , "y" : y , "to" : to , "from" : from_path })
275
-
266
+ result .append ({"x" : line [0 ], "y" : line [1 ], "to" : line [3 :], "from" : from_path })
276
267
277
268
return {"code" : code , "files" : result }
278
269
@@ -336,7 +327,7 @@ async def detailed_log(self, selected_hash, current_path):
336
327
total_insertions = 0
337
328
total_deletions = 0
338
329
result = []
339
- line_iterable = iter (self . strip_and_split (my_output )[1 :])
330
+ line_iterable = iter (strip_and_split (my_output )[1 :])
340
331
for line in line_iterable :
341
332
insertions , deletions , file = line .split ('\t ' )
342
333
0 commit comments