about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-12-15 08:29:01 +0000
committerEric Wong <e@80x24.org>2015-12-15 08:31:02 +0000
commitace243f12ecc14e4432e5b763deefb30e4c5a39c (patch)
treea4b977f780a179e81dacf4375ef005a5123ec65d
parent918f3298510be4505306813bd71699b61ec8dfc5 (diff)
downloaddtas-ace243f12ecc14e4432e5b763deefb30e4c5a39c.tar.gz
Having sequential track IDs can improve readability, so complicate
our code a bit to ensure users get nicer looking track IDs.

Followup to commit 90dcf561fd22c8a53c03d97292f86a82e74ca4a3
('Revert "dtas-tl: simplify existing addtail/addhead while we're at it"')
-rwxr-xr-xbin/dtas-tl10
1 files changed, 7 insertions, 3 deletions
diff --git a/bin/dtas-tl b/bin/dtas-tl
index 30821a1..76efb8f 100755
--- a/bin/dtas-tl
+++ b/bin/dtas-tl
@@ -86,10 +86,14 @@ def do_edit(c)
   orig.each do |track_id|
     edit_idx[track_id] or c.req("tl remove #{track_id}")
   end
-  add.reverse_each do |path, after_id|
+
+  prev_added_id = last_after_id = nil
+  add.each do |path, after_id|
     cmd = %W(tl add #{path})
-    cmd << after_id.to_s if after_id
-    c.req(cmd)
+    id = after_id == last_after_id ? prev_added_id : after_id
+    cmd << id.to_s if id
+    prev_added_id = c.req(cmd).to_i
+    last_after_id = after_id
   end
 ensure
   tmp.close! if tmp