]> Cypherpunks repositories - dsc.git/commitdiff
Committed/Current -> Saved/Stash
authorSergey Matveev <stargrave@stargrave.org>
Thu, 14 Aug 2025 08:06:25 +0000 (11:06 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 14 Aug 2025 08:06:26 +0000 (11:06 +0300)
Shorter and equal length.

dsc

diff --git a/dsc b/dsc
index 5d2e8604e956f3996ff5f0c6d6319e80960e3e8cb349a8dcd40654e37c5d9cf9..e2f68ef2d08b4da62f91bcd7a0269d742293f8cd6859c32e230b3ff0b37c39ad 100755 (executable)
--- a/dsc
+++ b/dsc
@@ -25,16 +25,16 @@ if {$argc == 0} {
     dsc set opt ""    -- unset value, make it default one
     dsc get opt       -- get option's value, maybe default one
     dsc get opt/*     -- list /*/ sections
-    dsc diff [prefix] -- show the difference between committed and current
+    dsc diff [prefix] -- show the difference between saved and stash
     dsc revert opt    -- revert opt's configuration
     dsc commit        -- commit (save) configuration
     dsc export >file.txtar -- export whole configuration
     dsc import <file.txtar -- import it
 
 Environmental variables:
-    $DSC_SCHEMA    -- path to the schema definition
-    $DSC_CURRENT   -- path to current/unsaved configuration state
-    $DSC_COMMITTED -- path to committed/saved state
+    $DSC_SCHEMA -- path to the schema definition
+    $DSC_STASH  -- path to stashed/unsaved state
+    $DSC_SAVED  -- path to committed/saved state
 
 There are two kinds of options:
     * array/list ones, which are identified with /*/ in "list"'s
@@ -45,8 +45,8 @@ There are two kinds of options:
 }
 
 if {[catch {set Schema $env(DSC_SCHEMA)}]} {set Schema schema}
-if {[catch {set Curr $env(DSC_CURRENT)}]} {set Curr current}
-if {[catch {set Comm $env(DSC_COMMITTED)}]} {set Comm committed}
+if {[catch {set Stash $env(DSC_STASH)}]} {set Stash stash}
+if {[catch {set Saved $env(DSC_SAVED)}]} {set Saved saved}
 
 proc walk {root typ} {
     set rv [list]
@@ -104,8 +104,8 @@ proc run-checker {opt v} {
 }
 
 proc assure-exists {opt} {
-    global Curr
-    if {! [file exists $Curr/$opt]} {
+    global Stash
+    if {! [file exists $Stash/$opt]} {
         puts stderr "not found"
         exit 1
     }
@@ -145,14 +145,14 @@ switch [lindex $argv 0] {
         set dir [file dirname $opt]
         set tail [run-checker $opt [file tail $opt]]
         set tail [string trimright $tail "\n"]
-        file mkdir $Curr/$dir/$tail
+        file mkdir $Stash/$dir/$tail
         puts $dir/$tail
     }
     del {
         if {$opt != ""} {
             assure-exists $opt
         }
-        file delete -force $Curr/$opt
+        file delete -force $Stash/$opt
     }
     set {
         if {[llength $argv] == 2} {
@@ -161,12 +161,12 @@ switch [lindex $argv 0] {
             set v [lindex $argv 2]
         }
         if {$v == ""} {
-            file delete $Curr/$opt
+            file delete $Stash/$opt
             exit
         }
         set v [run-checker $opt $v]
-        file mkdir "$Curr/[file dirname $opt]"
-        set fh [open $Curr/$opt w]
+        file mkdir "$Stash/[file dirname $opt]"
+        set fh [open $Stash/$opt w]
         puts -nonewline $fh $v
         close $fh
     }
@@ -180,60 +180,59 @@ switch [lindex $argv 0] {
         if {[file tail $opt] == "*"} {
             set opt [file dirname $opt]
             assure-exists $opt
-            set dirs [glob -directory $Curr/$opt -types d -tails -nocomplain -- *]
+            set dirs [glob -directory $Stash/$opt -types d -tails -nocomplain -- *]
             foreach dir [lsort $dirs] {
                 puts $dir
             }
             exit
         }
-        if {[file exists $Curr/$opt]} {
-            puts -nonewline [fileread $Curr/$opt]
+        if {[file exists $Stash/$opt]} {
+            puts -nonewline [fileread $Stash/$opt]
             exit
         }
         puts -nonewline [run-checker $opt ""]
     }
     diff {
-        set fh [file tempfile dirsComm]
-        foreach fn [walk $Comm/$opt d] {
-            puts $fh [string range $fn [string length $Comm]+1 end]
+        set fh [file tempfile dirsSaved]
+        foreach fn [walk $Saved/$opt d] {
+            puts $fh [string range $fn [string length $Saved]+1 end]
         }
         close $fh
-        set fh [file tempfile dirsCurr]
-        foreach fn [walk $Curr/$opt d] {
-            puts $fh [string range $fn [string length $Curr]+1 end]
+        set fh [file tempfile dirsStash]
+        foreach fn [walk $Stash/$opt d] {
+            puts $fh [string range $fn [string length $Stash]+1 end]
         }
         close $fh
-        set fh [open "| diff -u -L dirs/committed -L dirs/current
-            $dirsComm $dirsCurr" r]
+        set fh [open "| diff -u -L dirs -L dirs $dirsSaved $dirsStash" r]
         puts -nonewline [read $fh]
         catch {close $fh}
-        file delete $dirsComm
-        file delete $dirsCurr
-        set fh [open "| diff -urN $Comm/$opt $Curr/$opt" r]
+        file delete $dirsSaved
+        file delete $dirsStash
+        set fh [open "| diff -urN $Saved/$opt $Stash/$opt" r]
         puts -nonewline [read $fh]
         catch {close $fh}
     }
     revert {
-        catch {file delete -force $Curr/$opt}
-        catch {file copy $Comm/$opt $Curr/$opt}
+        catch {file delete -force $Stash/$opt}
+        catch {file copy $Saved/$opt $Stash/$opt}
     }
     commit {
-        file delete -force $Comm.bak
-        set tmp $Comm.[expr {int(rand() * 1000000)}]
-        file copy $Curr $tmp
-        file rename $Comm $Comm.bak
-        file rename $tmp $Comm
-        file delete -force $Comm.bak
+        file delete -force $Saved.bak
+        set tmp $Saved.[expr {int(rand() * 1000000)}]
+        file copy $Stash $tmp
+        file rename $Saved $Saved.bak
+        file rename $tmp $Saved
+        file delete -force $Saved.bak
     }
     export {
-        set dirs [walk $Comm d]
+        set dirs [walk $Saved d]
         puts "-- .dirs --"
         foreach fn $dirs {
-            puts [string range $fn [string length $Comm]+1 end]
+            puts [string range $fn [string length $Saved]+1 end]
         }
         foreach dir $dirs {
             foreach fn [walk $dir f] {
-                puts "-- [string range $fn [string length $Comm]+1 end] --"
+                puts "-- [string range $fn [string length $Saved]+1 end] --"
                 puts -nonewline [fileread $fn]
             }
         }
@@ -242,18 +241,18 @@ switch [lindex $argv 0] {
         set fn ""
         set lines [list]
         proc filewrite {fn v} {
-            global Curr
+            global Stash
             if {[llength $v] == 0} {
                 return
             }
             if {$fn == ".dirs"} {
                 foreach dir $v {
-                    file mkdir $Curr/$dir
+                    file mkdir $Stash/$dir
                 }
                 return
             }
-            file mkdir [file dirname $Curr/$fn]
-            set fh [open $Curr/$fn w]
+            file mkdir [file dirname $Stash/$fn]
+            set fh [open $Stash/$fn w]
             puts $fh [join $v "\n"]
             close $fh
         }