git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] gitk: merge views with existing ones

From
Max Kirillov <max@max630.net>
Date
Sep 11, 2014, 05:21 UTC
Message-ID
<1410412888-10187-4-git-send-email-max@max630.net>
In-Reply-To
<1410412888-10187-1-git-send-email-max@max630.net>

Only new and modified views are saved; old ones are saved also if there are no new, modified or deleted view with same name.

This allows editing view list in concurrent gitk sessions without losing the changes.

Signed-off-by: Max Kirillov <max@max630.net>
---
 gitk | 42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/gitk b/gitk
index 6e22024..3394415 100755
--- a/gitk
+++ b/gitk
@@ -2807,7 +2807,11 @@ proc doprogupdate {} {
 proc config_variable_change_cb {name name2 op} {
     global config_variable_changed
     if {$op eq "write"} {
-	set config_variable_changed($name) 1
+	if {$name2 eq ""} {
+	    set config_variable_changed($name) 1
+	} else {
+	    set config_variable_changed($name,$name2) 1
+	}
     }
 }
 
@@ -2861,12 +2865,38 @@ proc savestuff {w} {
 	puts $f "set geometry(botwidth) [winfo width .bleft]"
 	puts $f "set geometry(botheight) [winfo height .bleft]"
 
+	array set view_save {}
+	array set views {}
+	foreach view $permviews {
+	    set view_save([lindex $view 0]) 1
+	    set views([lindex $view 0]) $view
+	}
 	puts -nonewline $f "set permviews {"
 	for {set v 0} {$v < $current_nextviewnum} {incr v} {
-	    if {$current_viewperm($v)} {
-		puts $f "{[list $current_viewname($v) $current_viewfiles($v) $current_viewargs($v) $current_viewargscmd($v)]}"
+	    if {$config_variable_changed(viewname,$v) ||
+		$config_variable_changed(viewfiles,$v) ||
+		$config_variable_changed(viewargs,$v) ||
+		$config_variable_changed(viewargscmd,$v) ||
+		$config_variable_changed(viewperm,$v)} {
+		if {$current_viewperm($v)} {
+		    set views($current_viewname($v)) [list $current_viewname($v) $current_viewfiles($v) $current_viewargs($v) $current_viewargscmd($v)]
+		} else {
+		    set view_save($current_viewname($v)) 0
+		}
+		lappend views_modified_names $current_viewname($v)
 	    }
 	}
+	# write old and updated view to their places and append remaining to the end
+	foreach view $permviews {
+	    set view_name [lindex $view 0]
+	    if {$view_save($view_name)} {
+		puts $f "{$views($view_name)}"
+	    }
+	    unset views($view_name)
+	}
+	foreach view_name [array names views] {
+	    puts $f "{$views($view_name)}"
+	}
 	puts $f "}"
 	close $f
 	file rename -force $config_file_tmp $config_file
@@ -12828,6 +12858,12 @@ if {[info exists permviews]} {
 	addviewmenu $n
     }
 }
+foreach var {viewname viewfiles viewargs viewargscmd viewperm} {
+    for {set v 0} {$v < $nextviewnum} {incr v} {
+	set config_variable_changed($var,$v) 0
+    }
+    trace add variable $var write config_variable_change_cb
+}
 
 if {[tk windowingsystem] eq "win32"} {
     focus -force .
-- 
2.0.1.1697.g73c6810
Previous: Junio C Hamano
Message 7 of 7 in “gitk: save only changed configuration on exit”
  1. 0/3 gitk: save only changed configuration on exitMax Kirillov, Sep 11, 2014
  2. 1/3 gitk refactor: remove boilerplate for configuration variablesMax Kirillov, Sep 11, 2014
  3. 2/3 gitk: write only changed configuration variablesMax Kirillov, Sep 11, 2014
  4. Junio C HamanoSep 11, 2014
  5. Max KirillovSep 11, 2014
  6. Junio C HamanoSep 11, 2014
  7. 3/3 gitk: merge views with existing onesMax Kirillov, Sep 11, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.