]> arthur.barton.de Git - bup.git/commitdiff
ls: make multiple arguments match real ls
authorJohannes Berg <johannes@sipsolutions.net>
Tue, 28 Jul 2020 20:42:46 +0000 (22:42 +0200)
committerRob Browning <rlb@defaultvalue.org>
Sun, 18 Apr 2021 18:38:13 +0000 (13:38 -0500)
Currently, passing multiple arguments to ls causes it to print
them all in a single list, which can be very confusing as it'll
even columnate them together.

Make this match real ls behaviour (at least as observed on my
system) that prints which path it's giving the output for.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/ls.py

index 970995dfd7e2a5cedc961ba8e1796a9dc498470e..2dbe99d67ad5fd078e1f62b41f07e4423df83f28 100644 (file)
@@ -115,9 +115,13 @@ def within_repo(repo, opt, out, pwd=b''):
 
     ret = 0
     pending = []
-    for path in opt.paths:
-        path = posixpath.join(pwd, path)
+    last_n = len(opt.paths) - 1
+    for n, printpath in enumerate(opt.paths):
+        path = posixpath.join(pwd, printpath)
         try:
+            if last_n > 0:
+                out.write(b'%s:\n' % printpath)
+
             if opt.directory:
                 resolved = vfs.resolve(repo, path, follow=False)
             else:
@@ -167,8 +171,12 @@ def within_repo(repo, opt, out, pwd=b''):
             log('bup: %s\n' % ex)
             ret = 1
 
-    if pending:
-        out.write(columnate(pending, b''))
+        if pending:
+            out.write(columnate(pending, b''))
+            pending = []
+
+        if n < last_n:
+            out.write(b'\n')
 
     return ret