forked from 0ad/0ad
Revert changes in check_diff.py in batches
This is to avoid running into errors caused by the limited length of command line input when reverting lots of files.
This commit is contained in:
parent
fce48ca4be
commit
10e7513bba
@ -21,6 +21,7 @@
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from itertools import islice
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from i18n_helper import PROJECT_ROOT_DIRECTORY
|
from i18n_helper import PROJECT_ROOT_DIRECTORY
|
||||||
@ -87,15 +88,30 @@ def check_diff(diff: io.StringIO) -> List[str]:
|
|||||||
|
|
||||||
|
|
||||||
def revert_files(files: List[str], verbose=False):
|
def revert_files(files: List[str], verbose=False):
|
||||||
revert_process = subprocess.run(["svn", "revert", *files], capture_output=True, check=False)
|
def batched(iterable, n):
|
||||||
if revert_process.returncode != 0:
|
"""Split an iterable in equally sized chunks.
|
||||||
print(
|
|
||||||
"Warning: Some files could not be reverted. "
|
Can be removed in favor of itertools.batched(), once Python
|
||||||
f"Error: {revert_process.stderr.decode('utf-8')}"
|
3.12 is the minimum required Python version.
|
||||||
|
"""
|
||||||
|
iterable = iter(iterable)
|
||||||
|
return iter(lambda: tuple(islice(iterable, n)), ())
|
||||||
|
|
||||||
|
errors = []
|
||||||
|
for batch in batched(files, 100):
|
||||||
|
revert_process = subprocess.run(
|
||||||
|
["svn", "revert", *batch], capture_output=True, check=False
|
||||||
)
|
)
|
||||||
|
if revert_process.returncode != 0:
|
||||||
|
errors.append(revert_process.stderr.decode())
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
for file in files:
|
for file in files:
|
||||||
print(f"Reverted {file}")
|
print(f"Reverted {file}")
|
||||||
|
if errors:
|
||||||
|
print()
|
||||||
|
print("Warning: Some files could not be reverted. Errors:")
|
||||||
|
print("\n".join(errors))
|
||||||
|
|
||||||
|
|
||||||
def add_untracked(verbose=False):
|
def add_untracked(verbose=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user