Skip to contentSkip to conversation

git-gui: support for $FILENAMES in tool definitions

PATCH In review Alex Riesen 2 participants 3 messages Jun 28, 2016 – Oct 3, 2016 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 git-gui: support for $FILENAMES in tool definitions

This addes a FILENAMES environment variable, which contains the repository pathnames of all selected files the list.
The variable contains the names separated by LF (\n, \x0a).

If the file names contain LF characters, the tool command might be unable to unambiguosly split the value of $FILENAME into the separate names.

Note that the file marked and diffed immediately after starting the GUI up, is not actually selected. One must click on it once to really select it.

---
 lib/tools.tcl | 3 +++
 1 file changed, 3 insertions(+)
lib/tools.tcl +3 -0
index 6ec9411..413f1a1 100644
@@ -69,6 +69,7 @@ proc tools_populate_one {fullname} {
 proc tools_exec {fullname} {
 	global repo_config env current_diff_path
 	global current_branch is_detached
+	global selected_paths
 
 	if {[is_config_true "guitool.$fullname.needsfile"]} {
 		if {$current_diff_path eq {}} {
@@ -100,6 +101,7 @@ proc tools_exec {fullname} {
 
 	set env(GIT_GUITOOL) $fullname
 	set env(FILENAME) $current_diff_path
+	set env(FILENAMES) [join [array names selected_paths] \n]
 	if {$is_detached} {
 		set env(CUR_BRANCH) ""
 	} else {
@@ -121,6 +123,7 @@ proc tools_exec {fullname} {
 
 	unset env(GIT_GUITOOL)
 	unset env(FILENAME)
+	unset env(FILENAMES)
 	unset env(CUR_BRANCH)
 	catch { unset env(ARGS) }
 	catch { unset env(REVISION) }
Signature · 6 lines
2.9.0.45.g28c608e.dirty


---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus
#1 lore raw

PATCH 2/2 git-gui: ensure the file in the diff pane is in the list of selected files

It is very confusing that the file which diff is displayed is marked as selected, but it is not in fact selected (that means the array of selected files does not include the file in question).

Fixing this also improves the use of $FILENAMES in custom defined tools: one does not have to click the file in the list to make it selected.

---
 lib/diff.tcl | 3 +++
 1 file changed, 3 insertions(+)
lib/diff.tcl +3 -0
index 0d56986..30bdd69 100644
@@ -127,6 +127,9 @@ proc show_diff {path w {lno {}} {scroll_pos {}} {callback {}}} {
 	} else {
 		start_show_diff $cont_info
 	}
+
+	global current_diff_path selected_paths
+	set selected_paths($current_diff_path) 1
 }
 
 proc show_unmerged_diff {cont_info} {
Signature · 6 lines
2.9.0.45.g28c608e.dirty


---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus
#2 lore raw

Re: [PATCH 2/2] git-gui: ensure the file in the diff pane is in the list of selected files

Quoted 17 lines · Alex Riesen

It is very confusing that the file which diff is displayed is marked as selected, but it is not in fact selected (that means the array of selected files does not include the file in question).

Fixing this also improves the use of $FILENAMES in custom defined tools: one does not have to click the file in the list to make it selected.

---
lib/diff.tcl | 3 +++

1 file changed, 3 insertions(+)
lib/diff.tcl +0 -0
index 0d56986..30bdd69 100644

lib/diff.tcl proc show_diff {path w {lno {}} {scroll_pos {}} {callback {}}} { · line 135

Quoted 9 lines
lib/diff.tcl +3 -0
@@ -127,6 +127,9 @@ proc show_diff {path w {lno {}} {scroll_pos {}} {callback {}}} {
 	} else {
 		start_show_diff $cont_info
 	}
+
+	global current_diff_path selected_paths
+	set selected_paths($current_diff_path) 1
 }
 
 proc show_unmerged_diff {cont_info} {

These both look good. Applied with minor changes to the commit message for patch 1.

Thank you,

Signature · 2 lines
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD