There was an error while loading. Please reload this page.
1 parent bb6b1c3 commit 333ea75Copy full SHA for 333ea75
1 file changed
pre_commit/xargs.py
@@ -13,9 +13,8 @@ def _get_platform_max_length():
13
return 4 * 1024
14
15
16
-def _get_command_length(command, arg):
17
- parts = command + (arg,)
18
- full_cmd = ' '.join(parts)
+def _command_length(*cmd):
+ full_cmd = ' '.join(cmd)
19
20
# win32 uses the amount of characters, more details at:
21
# https://blogs.msdn.microsoft.com/oldnewthing/20031210-00/?p=41553/
@@ -38,17 +37,21 @@ def partition(cmd, varargs, _max_length=None):
38
37
# Reversed so arguments are in order
39
varargs = list(reversed(varargs))
40
+ total_length = _command_length(*cmd)
41
while varargs:
42
arg = varargs.pop()
43
44
- if _get_command_length(cmd + tuple(ret_cmd), arg) <= _max_length:
+ arg_length = _command_length(arg) + 1
45
+ if total_length + arg_length <= _max_length:
46
ret_cmd.append(arg)
47
+ total_length += arg_length
48
elif not ret_cmd:
49
raise ArgumentTooLongError(arg)
50
else:
51
# We've exceeded the length, yield a command
52
ret.append(cmd + tuple(ret_cmd))
53
ret_cmd = []
54
55
varargs.append(arg)
56
57
0 commit comments