diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-04-02 00:30:36 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-04-02 00:31:36 -0400 |
commit | 7989943d6a58d14ef1fa02f46067743468137eb5 (patch) | |
tree | 89ebb63e2e1af2a0f97b1eb1eae64a504eef0e6f /Utility/SafeCommand.hs | |
parent | 5492d8f4ddbd398e0188da9daed840908d1198c0 (diff) |
make segmentXargs preserve order
Diffstat (limited to 'Utility/SafeCommand.hs')
-rw-r--r-- | Utility/SafeCommand.hs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Utility/SafeCommand.hs b/Utility/SafeCommand.hs index 22ec883ba..59e9f5f29 100644 --- a/Utility/SafeCommand.hs +++ b/Utility/SafeCommand.hs @@ -101,12 +101,15 @@ prop_idempotent_shellEscape s = [s] == (shellUnEscape . shellEscape) s prop_idempotent_shellEscape_multiword :: [String] -> Bool prop_idempotent_shellEscape_multiword s = s == (shellUnEscape . unwords . map shellEscape) s -{- Segements a list of filenames into groups that are all below the manximum - - command-line length limit. Does not preserve order. -} -segmentXargs :: [FilePath] -> [[FilePath]] -segmentXargs l = go l [] 0 [] +{- Segments a list of filenames into groups that are all below the maximum + - command-line length limit. -} +segmentXargsOrdered :: [FilePath] -> [[FilePath]] +segmentXargsOrdered = reverse . map reverse . segmentXargsUnordered + +segmentXargsUnordered :: [FilePath] -> [[FilePath]] +segmentXargsUnordered l = go l [] 0 [] where - go [] c _ r = c:r + go [] c _ r = (c:r) go (f:fs) c accumlen r | len < maxlen && newlen > maxlen = go (f:fs) [] 0 (c:r) | otherwise = go fs (f:c) newlen r |