git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/3] gitk: save only changed configuration on exit
@ 2014-09-11  5:21 Max Kirillov
  2014-09-11  5:21 ` [PATCH 1/3] gitk refactor: remove boilerplate for configuration variables Max Kirillov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Max Kirillov @ 2014-09-11  5:21 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: git, Max Kirillov

gitk rewrites whole its config on exit. This is inconvenient when there are
several instances running - if user changes something in one instance, it may
be discarded depending of the order of closing that instances.

Change saving so that it saves only changed data and tried to preserve other
existing data in configuration.

Max Kirillov (3):
  gitk refactor: remove boilerplate for configuration variables
  gitk: write only changed configuration variables
  gitk: merge views with existing ones

 gitk | 159 ++++++++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 86 insertions(+), 73 deletions(-)

-- 
2.0.1.1697.g73c6810

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] gitk refactor: remove boilerplate for configuration variables
  2014-09-11  5:21 [PATCH 0/3] gitk: save only changed configuration on exit Max Kirillov
@ 2014-09-11  5:21 ` Max Kirillov
  2014-09-11  5:21 ` [PATCH 2/3] gitk: write only changed " Max Kirillov
  2014-09-11  5:21 ` [PATCH 3/3] gitk: merge views with existing ones Max Kirillov
  2 siblings, 0 replies; 7+ messages in thread
From: Max Kirillov @ 2014-09-11  5:21 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: git, Max Kirillov

Signed-off-by: Max Kirillov <max@max630.net>
---
 gitk | 88 ++++++++++++++++----------------------------------------------------
 1 file changed, 20 insertions(+), 68 deletions(-)

diff --git a/gitk b/gitk
index 6fb6cb3..6069afe 100755
--- a/gitk
+++ b/gitk
@@ -2805,23 +2805,11 @@ proc doprogupdate {} {
 }
 
 proc savestuff {w} {
-    global canv canv2 canv3 mainfont textfont uifont tabstop
-    global stuffsaved findmergefiles maxgraphpct
-    global maxwidth showneartags showlocalchanges
     global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
-    global cmitmode wrapcomment datetimeformat limitdiffs
-    global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
-    global uifgcolor uifgdisabledcolor
-    global headbgcolor headfgcolor headoutlinecolor remotebgcolor
-    global tagbgcolor tagfgcolor tagoutlinecolor
-    global reflinecolor filesepbgcolor filesepfgcolor
-    global mergecolors foundbgcolor currentsearchhitbgcolor
-    global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor circlecolors
-    global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
-    global linkfgcolor circleoutlinecolor
-    global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
-    global hideremotes want_ttk maxrefs visiblerefs
+    global use_ttk
+    global stuffsaved
     global config_file config_file_tmp
+    global config_variables
 
     if {$stuffsaved} return
     if {![winfo viewable .]} return
@@ -2833,59 +2821,10 @@ proc savestuff {w} {
 	if {$::tcl_platform(platform) eq {windows}} {
 	    file attributes $config_file_tmp -hidden true
 	}
-	puts $f [list set mainfont $mainfont]
-	puts $f [list set textfont $textfont]
-	puts $f [list set uifont $uifont]
-	puts $f [list set tabstop $tabstop]
-	puts $f [list set findmergefiles $findmergefiles]
-	puts $f [list set maxgraphpct $maxgraphpct]
-	puts $f [list set maxwidth $maxwidth]
-	puts $f [list set cmitmode $cmitmode]
-	puts $f [list set wrapcomment $wrapcomment]
-	puts $f [list set autoselect $autoselect]
-	puts $f [list set autosellen $autosellen]
-	puts $f [list set showneartags $showneartags]
-	puts $f [list set maxrefs $maxrefs]
-	puts $f [list set visiblerefs $visiblerefs]
-	puts $f [list set hideremotes $hideremotes]
-	puts $f [list set showlocalchanges $showlocalchanges]
-	puts $f [list set datetimeformat $datetimeformat]
-	puts $f [list set limitdiffs $limitdiffs]
-	puts $f [list set uicolor $uicolor]
-	puts $f [list set want_ttk $want_ttk]
-	puts $f [list set bgcolor $bgcolor]
-	puts $f [list set fgcolor $fgcolor]
-	puts $f [list set uifgcolor $uifgcolor]
-	puts $f [list set uifgdisabledcolor $uifgdisabledcolor]
-	puts $f [list set colors $colors]
-	puts $f [list set diffcolors $diffcolors]
-	puts $f [list set mergecolors $mergecolors]
-	puts $f [list set markbgcolor $markbgcolor]
-	puts $f [list set diffcontext $diffcontext]
-	puts $f [list set selectbgcolor $selectbgcolor]
-	puts $f [list set foundbgcolor $foundbgcolor]
-	puts $f [list set currentsearchhitbgcolor $currentsearchhitbgcolor]
-	puts $f [list set extdifftool $extdifftool]
-	puts $f [list set perfile_attrs $perfile_attrs]
-	puts $f [list set headbgcolor $headbgcolor]
-	puts $f [list set headfgcolor $headfgcolor]
-	puts $f [list set headoutlinecolor $headoutlinecolor]
-	puts $f [list set remotebgcolor $remotebgcolor]
-	puts $f [list set tagbgcolor $tagbgcolor]
-	puts $f [list set tagfgcolor $tagfgcolor]
-	puts $f [list set tagoutlinecolor $tagoutlinecolor]
-	puts $f [list set reflinecolor $reflinecolor]
-	puts $f [list set filesepbgcolor $filesepbgcolor]
-	puts $f [list set filesepfgcolor $filesepfgcolor]
-	puts $f [list set linehoverbgcolor $linehoverbgcolor]
-	puts $f [list set linehoverfgcolor $linehoverfgcolor]
-	puts $f [list set linehoveroutlinecolor $linehoveroutlinecolor]
-	puts $f [list set mainheadcirclecolor $mainheadcirclecolor]
-	puts $f [list set workingfilescirclecolor $workingfilescirclecolor]
-	puts $f [list set indexcirclecolor $indexcirclecolor]
-	puts $f [list set circlecolors $circlecolors]
-	puts $f [list set linkfgcolor $linkfgcolor]
-	puts $f [list set circleoutlinecolor $circleoutlinecolor]
+	foreach var_name $config_variables {
+	    upvar #0 $var_name var
+	    puts $f [list set $var_name $var]
+	}
 
 	puts $f "set geometry(main) [wm geometry .]"
 	puts $f "set geometry(state) [wm state .]"
@@ -12649,6 +12588,19 @@ catch {
     source $config_file
 }
 
+set config_variables {
+    mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth
+    cmitmode wrapcomment autoselect autosellen showneartags maxrefs visiblerefs
+    hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk
+    bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors
+    markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor
+    extdifftool perfile_attrs headbgcolor headfgcolor headoutlinecolor
+    remotebgcolor tagbgcolor tagfgcolor tagoutlinecolor reflinecolor
+    filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor
+    linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
+    indexcirclecolor circlecolors linkfgcolor circleoutlinecolor
+}
+
 parsefont mainfont $mainfont
 eval font create mainfont [fontflags mainfont]
 eval font create mainfontbold [fontflags mainfont 1]
-- 
2.0.1.1697.g73c6810

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] gitk: write only changed configuration variables
  2014-09-11  5:21 [PATCH 0/3] gitk: save only changed configuration on exit Max Kirillov
  2014-09-11  5:21 ` [PATCH 1/3] gitk refactor: remove boilerplate for configuration variables Max Kirillov
@ 2014-09-11  5:21 ` Max Kirillov
  2014-09-11 17:19   ` Junio C Hamano
  2014-09-11  5:21 ` [PATCH 3/3] gitk: merge views with existing ones Max Kirillov
  2 siblings, 1 reply; 7+ messages in thread
From: Max Kirillov @ 2014-09-11  5:21 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: git, Max Kirillov

If a variable is changed in a concurrent gitk or manually it is
preserved unless it has changed in this instance

This change does not affect geometry and views save; geometry does not
need it, and views need special merging, which treats each view
separately rather that fully replace the shole list.

Signed-off-by: Max Kirillov <max@max630.net>
---
 gitk | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/gitk b/gitk
index 6069afe..6e22024 100755
--- a/gitk
+++ b/gitk
@@ -2804,12 +2804,25 @@ proc doprogupdate {} {
     }
 }
 
+proc config_variable_change_cb {name name2 op} {
+    global config_variable_changed
+    if {$op eq "write"} {
+	set config_variable_changed($name) 1
+    }
+}
+
 proc savestuff {w} {
-    global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
-    global use_ttk
     global stuffsaved
     global config_file config_file_tmp
-    global config_variables
+    global config_variables config_variable_changed
+
+    upvar #0 viewname current_viewname
+    upvar #0 viewfiles current_viewfiles
+    upvar #0 viewargs current_viewargs
+    upvar #0 viewargscmd current_viewargscmd
+    upvar #0 viewperm current_viewperm
+    upvar #0 nextviewnum current_nextviewnum
+    upvar #0 use_ttk current_use_ttk
 
     if {$stuffsaved} return
     if {![winfo viewable .]} return
@@ -2821,16 +2834,24 @@ proc savestuff {w} {
 	if {$::tcl_platform(platform) eq {windows}} {
 	    file attributes $config_file_tmp -hidden true
 	}
+	if {[file exists $config_file]} {
+	    source $config_file
+	}
 	foreach var_name $config_variables {
 	    upvar #0 $var_name var
-	    puts $f [list set $var_name $var]
+	    upvar 0 $var_name old_var
+	    if {!$config_variable_changed($var_name) && [info exists old_var]} {
+		puts $f [list set $var_name $old_var]
+	    } else {
+		puts $f [list set $var_name $var]
+	    }
 	}
 
 	puts $f "set geometry(main) [wm geometry .]"
 	puts $f "set geometry(state) [wm state .]"
 	puts $f "set geometry(topwidth) [winfo width .tf]"
 	puts $f "set geometry(topheight) [winfo height .tf]"
-	if {$use_ttk} {
+	if {$current_use_ttk} {
 	    puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
 	    puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
 	} else {
@@ -2841,9 +2862,9 @@ proc savestuff {w} {
 	puts $f "set geometry(botheight) [winfo height .bleft]"
 
 	puts -nonewline $f "set permviews {"
-	for {set v 0} {$v < $nextviewnum} {incr v} {
-	    if {$viewperm($v)} {
-		puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
+	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)]}"
 	    }
 	}
 	puts $f "}"
@@ -12600,6 +12621,10 @@ set config_variables {
     linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
     indexcirclecolor circlecolors linkfgcolor circleoutlinecolor
 }
+foreach var $config_variables {
+    set config_variable_changed($var) 0
+    trace add variable $var write config_variable_change_cb
+}
 
 parsefont mainfont $mainfont
 eval font create mainfont [fontflags mainfont]
-- 
2.0.1.1697.g73c6810

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] gitk: merge views with existing ones
  2014-09-11  5:21 [PATCH 0/3] gitk: save only changed configuration on exit Max Kirillov
  2014-09-11  5:21 ` [PATCH 1/3] gitk refactor: remove boilerplate for configuration variables Max Kirillov
  2014-09-11  5:21 ` [PATCH 2/3] gitk: write only changed " Max Kirillov
@ 2014-09-11  5:21 ` Max Kirillov
  2 siblings, 0 replies; 7+ messages in thread
From: Max Kirillov @ 2014-09-11  5:21 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: git, Max Kirillov

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] gitk: write only changed configuration variables
  2014-09-11  5:21 ` [PATCH 2/3] gitk: write only changed " Max Kirillov
@ 2014-09-11 17:19   ` Junio C Hamano
  2014-09-11 19:17     ` Max Kirillov
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2014-09-11 17:19 UTC (permalink / raw)
  To: Max Kirillov; +Cc: Paul Mackerras, git

Max Kirillov <max@max630.net> writes:

> If a variable is changed in a concurrent gitk or manually it is
> preserved unless it has changed in this instance

It would have been easier to understand why this is a desirable
change if you stated what problem you are trying to solve before
that sentence.  "If I do X, Y happens, which is bad for reason Z.
With this change, Y no longer happens as long as I do not do W."

> This change does not affect geometry and views save; geometry does not
> need it, and views need special merging, which treats each view
> separately rather that fully replace the shole list.

s/sh/wh/ I presume?

>
> Signed-off-by: Max Kirillov <max@max630.net>
> ---
>  gitk | 41 +++++++++++++++++++++++++++++++++--------
>  1 file changed, 33 insertions(+), 8 deletions(-)
>
> diff --git a/gitk b/gitk
> index 6069afe..6e22024 100755
> --- a/gitk
> +++ b/gitk
> @@ -2804,12 +2804,25 @@ proc doprogupdate {} {
>      }
>  }
>  
> +proc config_variable_change_cb {name name2 op} {
> +    global config_variable_changed
> +    if {$op eq "write"} {
> +	set config_variable_changed($name) 1
> +    }
> +}

Hmm, wouldn't it make more sense to save the original value where
you set up the variable trace, and make the savestuff procedure do a
3-way merge?  That way, when you and the other party changed a
variable to a different value, you can give a better diagnosis to
the user to know what is going on. If both of you changed to the
same value, then the end result would be the same, of course.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] gitk: write only changed configuration variables
  2014-09-11 17:19   ` Junio C Hamano
@ 2014-09-11 19:17     ` Max Kirillov
  2014-09-11 20:26       ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Max Kirillov @ 2014-09-11 19:17 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Paul Mackerras, git

On Thu, Sep 11, 2014 at 10:19:56AM -0700, Junio C Hamano wrote:
> Max Kirillov <max@max630.net> writes:
> 
>> If a variable is changed in a concurrent gitk or manually it is
>> preserved unless it has changed in this instance
> 
> It would have been easier to understand why this is a desirable
> change if you stated what problem you are trying to solve before
> that sentence.  "If I do X, Y happens, which is bad for reason Z.
> With this change, Y no longer happens as long as I do not do W."

Something like:

"""
When gitk contains some changed parameter, and there is
existing instance of gitk where the parameter is still old,
it is reverted to that old value when the instance exits.

After the change, a parameter is stored in config only it is
has been modified in the exiting instance. Otherwise, the
value which currently is in file is preserved. This allows
editing the configuration when several instances are
running, and don't get rollback of the modification if some
other instance where the cinfiguration was not edited is
closed last.
"""

Does it looks appropriate?

(Actually, the main motivation was the 3/3 part, for views,
scalar parameters merging was just low hanging fruit by the
way)

>> This change does not affect geometry and views save; geometry does not
>> need it, and views need special merging, which treats each view
>> separately rather that fully replace the shole list.
> 
> s/sh/wh/ I presume?

Sure. Thanks

>> +proc config_variable_change_cb {name name2 op} {
>> +    global config_variable_changed
>> +    if {$op eq "write"} {
>> +	set config_variable_changed($name) 1
>> +    }
>> +}
> 
> Hmm, wouldn't it make more sense to save the original value where
> you set up the variable trace, and make the savestuff procedure do a
> 3-way merge?  That way, when you and the other party changed a
> variable to a different value, you can give a better diagnosis to
> the user to know what is going on. If both of you changed to the
> same value, then the end result would be the same, of course.

This is going to complicate UI, something like "closing
confirmation dialog". Not nice. And, I am actually not sure
it is really needed, because "the other party" is me again,
in another gitk window, and most probably I would want the
same change.

Though storing the old value and comparing to it makes sanse
to do anyway, because trace may produce bogus events, so it
would be better to doublecheck has the value actually been
changed.

-- 
Max

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] gitk: write only changed configuration variables
  2014-09-11 19:17     ` Max Kirillov
@ 2014-09-11 20:26       ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2014-09-11 20:26 UTC (permalink / raw)
  To: Max Kirillov; +Cc: Paul Mackerras, git

Max Kirillov <max@max630.net> writes:

> On Thu, Sep 11, 2014 at 10:19:56AM -0700, Junio C Hamano wrote:
>> Max Kirillov <max@max630.net> writes:
>> 
>>> If a variable is changed in a concurrent gitk or manually it is
>>> preserved unless it has changed in this instance
>> 
>> It would have been easier to understand why this is a desirable
>> change if you stated what problem you are trying to solve before
>> that sentence.  "If I do X, Y happens, which is bad for reason Z.
>> With this change, Y no longer happens as long as I do not do W."
>
> Something like:
>
> """
> When gitk contains some changed parameter, and there is
> existing instance of gitk where the parameter is still old,
> it is reverted to that old value when the instance exits.
>
> After the change, a parameter is stored in config only it is
> has been modified in the exiting instance. Otherwise, the
> value which currently is in file is preserved. This allows
> editing the configuration when several instances are
> running, and don't get rollback of the modification if some
> other instance where the cinfiguration was not edited is
> closed last.
> """
>
> Does it looks appropriate?

Yeah, except for the phrase "after the change" may give me a hiccup
or two while reading, because it is unclear if "the change" refers
to this patch (which is the intended interpretation) or the change
made in one of these two instances of gitk process.

Expressing the behaviour your patch modifies in the imperative mood,
as if you are ordering our codebase "to become like so", would avoid
such a hiccup, i.e./e.g.

	Re-read the current on-disk configuration variables and
	overwrite only the ones changed in this process when saving
	the file, to preserve the changes made by other instances.

or something like that, perhaps?

> Though storing the old value and comparing to it makes sanse
> to do anyway, because trace may produce bogus events, so it
> would be better to doublecheck has the value actually been
> changed.

Exactly.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-09-11 20:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-11  5:21 [PATCH 0/3] gitk: save only changed configuration on exit Max Kirillov
2014-09-11  5:21 ` [PATCH 1/3] gitk refactor: remove boilerplate for configuration variables Max Kirillov
2014-09-11  5:21 ` [PATCH 2/3] gitk: write only changed " Max Kirillov
2014-09-11 17:19   ` Junio C Hamano
2014-09-11 19:17     ` Max Kirillov
2014-09-11 20:26       ` Junio C Hamano
2014-09-11  5:21 ` [PATCH 3/3] gitk: merge views with existing ones Max Kirillov

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).