Re: [PATCH 1/2] gitk: show part of submodule log instead of empty pane when listing trees

2018-05-09 Thread Alex Riesen
Stefan Beller, Tue, May 08, 2018 19:07:29 +0200:
> On Tue, May 8, 2018 at 5:22 AM, Alex Riesen
>  wrote:
> > Currently, the submodules either are not shown at all (if listing a
> > committed tree) or a Tcl error appears (when clicking on a submodule
> > from the index list).
> 
> I do not understand where this appears, yet.
> Where do I have to click to see the effects of this patch?

Er. I meant to say the file list panel (bottom right panel). Sorry,
didn't come out clear. I'll reword the commit message next time.

> > @@ -7659,21 +7660,42 @@ proc showfile {f} {
> >  global ctext_file_names ctext_file_lines
> >  global ctext commentend
> >
> > +set submodlog "git\\ log\\ --format='%h\\ %aN:\\ %s'\\ -100"
> 
> Do we want to respect the config option diff.submodule here?

Probably not. It is already done when the file list panel is in "Patch" mode.
The "Tree" mode of the panel shows the files in full, so the submodules should
be shown similarly: in a format resembling their full (referenced) contents.

> The -100 is chosen rather arbitrarily. Ideally we'd only walk to the
> previous entry?

Yes, the limit is indeed arbitrary. I'm reluctant of listing full history,
though: it might take too long a while (and does, in my line of work). Maybe
an option in the settings? Or some kind of a more natural limit (for 1 second?
Until the end of panel?)

> > -   if {[catch {set bf [open $f r]} err]} {
> > -   puts "oops, can't read $f: $err"
> > -   return
> > +   if {[file isdirectory $f]} {
> > +   # a submodule
> > +   if {[catch {set bf [open "| sh -c cd\\ \"$f\"&&$submodlog" r]} 
> > err]} {
> 
> Can we have $submodlog use the "git -C  command"
> option, then we could save the "cd &&" part, which might even
> save us from spawning a shell?

That's because I forgot about that option. Of course, I'll fix this.
Also need a shellquote for the path.

Thanks!
Alex

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



Re: [PATCH 1/2] gitk: show part of submodule log instead of empty pane when listing trees

2018-05-08 Thread Stefan Beller
On Tue, May 8, 2018 at 5:22 AM, Alex Riesen
 wrote:
> From: Alex Riesen 
>
> Currently, the submodules either are not shown at all (if listing a
> committed tree) or a Tcl error appears (when clicking on a submodule
> from the index list).

I do not understand where this appears, yet.
Where do I have to click to see the effects of this patch?

>
> This will make it show first arbitrarily chosen number of commits,
> which might be only marginally better.
>
> Signed-off-by: Alex Riesen 
> ---
>  gitk | 42 --
>  1 file changed, 32 insertions(+), 10 deletions(-)
>
> diff --git a/gitk b/gitk
> index a14d7a1..d34833f 100755
> --- a/gitk
> +++ b/gitk
> @@ -7627,9 +7627,10 @@ proc gettreeline {gtf id} {
> if {$i < 0} continue
> set fname [string range $line [expr {$i+1}] end]
> set line [string range $line 0 [expr {$i-1}]]
> -   if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
> +   set objtype [lindex $line 1]
> +   if {$diffids ne $nullid2 && $objtype ne "blob" && $objtype ne 
> "commit" } { continue }
> set sha1 [lindex $line 2]
> -   lappend treeidlist($id) $sha1
> +   lappend treeidlist($id) "$sha1 $objtype"
> }
> if {[string index $fname 0] eq "\""} {
> set fname [lindex $fname 0]
> @@ -7659,21 +7660,42 @@ proc showfile {f} {
>  global ctext_file_names ctext_file_lines
>  global ctext commentend
>
> +set submodlog "git\\ log\\ --format='%h\\ %aN:\\ %s'\\ -100"

Do we want to respect the config option diff.submodule here?
The -100 is chosen rather arbitrarily. Ideally we'd only walk to the
previous entry?

> +set fcmt ""
>  set i [lsearch -exact $treefilelist($diffids) $f]
>  if {$i < 0} {
> puts "oops, $f not in list for id $diffids"
> return
>  }
>  if {$diffids eq $nullid} {
> -   if {[catch {set bf [open $f r]} err]} {
> -   puts "oops, can't read $f: $err"
> -   return
> +   if {[file isdirectory $f]} {
> +   # a submodule
> +   if {[catch {set bf [open "| sh -c cd\\ \"$f\"&&$submodlog" r]} 
> err]} {

Can we have $submodlog use the "git -C  command"
option, then we could save the "cd &&" part, which might even
save us from spawning a shell?

Thanks,
Stefan


[PATCH 1/2] gitk: show part of submodule log instead of empty pane when listing trees

2018-05-08 Thread Alex Riesen
From: Alex Riesen 

Currently, the submodules either are not shown at all (if listing a
committed tree) or a Tcl error appears (when clicking on a submodule
from the index list).

This will make it show first arbitrarily chosen number of commits,
which might be only marginally better.

Signed-off-by: Alex Riesen 
---
 gitk | 42 --
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/gitk b/gitk
index a14d7a1..d34833f 100755
--- a/gitk
+++ b/gitk
@@ -7627,9 +7627,10 @@ proc gettreeline {gtf id} {
if {$i < 0} continue
set fname [string range $line [expr {$i+1}] end]
set line [string range $line 0 [expr {$i-1}]]
-   if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
+   set objtype [lindex $line 1]
+   if {$diffids ne $nullid2 && $objtype ne "blob" && $objtype ne 
"commit" } { continue }
set sha1 [lindex $line 2]
-   lappend treeidlist($id) $sha1
+   lappend treeidlist($id) "$sha1 $objtype"
}
if {[string index $fname 0] eq "\""} {
set fname [lindex $fname 0]
@@ -7659,21 +7660,42 @@ proc showfile {f} {
 global ctext_file_names ctext_file_lines
 global ctext commentend
 
+set submodlog "git\\ log\\ --format='%h\\ %aN:\\ %s'\\ -100"
+set fcmt ""
 set i [lsearch -exact $treefilelist($diffids) $f]
 if {$i < 0} {
puts "oops, $f not in list for id $diffids"
return
 }
 if {$diffids eq $nullid} {
-   if {[catch {set bf [open $f r]} err]} {
-   puts "oops, can't read $f: $err"
-   return
+   if {[file isdirectory $f]} {
+   # a submodule
+   if {[catch {set bf [open "| sh -c cd\\ \"$f\"&&$submodlog" r]} 
err]} {
+   puts "oops, can't read submodule $f: $err"
+   return
+   }
+} else {
+   if {[catch {set bf [open $f r]} err]} {
+   puts "oops, can't read $f: $err"
+   return
+   }
}
 } else {
-   set blob [lindex $treeidlist($diffids) $i]
-   if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
-   puts "oops, error reading blob $blob: $err"
-   return
+   set bo [lindex $treeidlist($diffids) $i]
+   set blob [lindex $bo 0]
+   set objtype [lindex $bo 1]
+   if { "$objtype" eq "blob" } {
+   if {[catch {set bf [open [concat | git cat-file blob $blob] r]} 
err]} {
+   puts "oops, error reading blob $blob: $err"
+   return
+   }
+   } else {
+   # also a submodule
+   if {[catch {set bf [open "| sh -c cd\\ \"$f\"&&$submodlog\\ $blob" 
r]} err]} {
+   puts "oops, error reading submodule commit: $err"
+   return
+   }
+   set fcmt "/"
}
 }
 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
@@ -7683,7 +7705,7 @@ proc showfile {f} {
 lappend ctext_file_names $f
 lappend ctext_file_lines [lindex [split $commentend "."] 0]
 $ctext insert end "\n"
-$ctext insert end "$f\n" filesep
+$ctext insert end "$f$fcmt\n" filesep
 $ctext config -state disabled
 $ctext yview $commentend
 settabs 0
-- 
2.17.0.rc1.56.gb9824190bd


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