From d1fd1353f85201f4bb5e9c387917ee203032a9d2 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Sat, 25 Jan 2020 10:16:20 -0500 Subject: [PATCH] Execute git checkout in batches to avoid overlong argument lists Closes: #195 Closes: #194 Closes: #150 --- commands.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/commands.cpp b/commands.cpp index d25c4cc..9c19b3c 100644 --- a/commands.cpp +++ b/commands.cpp @@ -183,15 +183,19 @@ static void deconfigure_git_filters (const char* key_name) } } -static bool git_checkout (const std::vector& paths) +static bool git_checkout_batch (std::vector::const_iterator paths_begin, std::vector::const_iterator paths_end) { + if (paths_begin == paths_end) { + return true; + } + std::vector command; command.push_back("git"); command.push_back("checkout"); command.push_back("--"); - for (std::vector::const_iterator path(paths.begin()); path != paths.end(); ++path) { + for (auto path(paths_begin); path != paths_end; ++path) { command.push_back(*path); } @@ -202,6 +206,18 @@ static bool git_checkout (const std::vector& paths) return true; } +static bool git_checkout (const std::vector& paths) +{ + auto paths_begin(paths.begin()); + while (paths.end() - paths_begin >= 100) { + if (!git_checkout_batch(paths_begin, paths_begin + 100)) { + return false; + } + paths_begin += 100; + } + return git_checkout_batch(paths_begin, paths.end()); +} + static bool same_key_name (const char* a, const char* b) { return (!a && !b) || (a && b && std::strcmp(a, b) == 0);