From 50b44eceed2105db0bee194904649249cc5f0308 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Tue, 4 Apr 2006 10:16:22 +1000 Subject: gitk: Implement multiple views With this, gitk can know about the graphs for multiple sets of files and directories of interest. Each set of files/dirs and its graph is called a "view". There is always the "All files" view, which is the complete graph showing all commits. If files or dirs are specified on the command line, a "Command line" view is automatically created. Users can create new views and switch between them, and can delete any view except the "All files" view. This required a bit of reengineering. In particular, some more things that were arrays have now become lists. The idrowranges array is still used while the graph is being laid out, but for rows that have been laid out we use the rowrangelist list instead. The cornercrossings and crossings arrays no longer exist, and instead we compute the crossings when needed (in assigncolor). Still to be done: make the back/forward buttons switch views as necessary; make the updatecommits function work right; preserve the selection if possible when the new view has to be read in; fix the case when the user switches away from the current view while we are still reading it in and laying it out; further optimizations. Signed-off-by: Paul Mackerras --- gitk | 452 +++++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 334 insertions(+), 118 deletions(-) diff --git a/gitk b/gitk index 90afec92df..961b582a4d 100755 --- a/gitk +++ b/gitk @@ -17,19 +17,38 @@ proc gitdir {} { } proc parse_args {rargs} { - global parsed_args + global parsed_args cmdline_files + set parsed_args {} + set cmdline_files {} if {[catch { set parse_args [concat --default HEAD $rargs] - set parsed_args [split [eval exec git-rev-parse $parse_args] "\n"] + set args [split [eval exec git-rev-parse $parse_args] "\n"] + set i 0 + foreach arg $args { + if {![regexp {^[0-9a-f]{40}$} $arg]} { + if {$arg eq "--"} { + incr i + } + set cmdline_files [lrange $args $i end] + break + } + lappend parsed_args $arg + incr i + } }]} { # if git-rev-parse failed for some reason... + set i [lsearch -exact $rargs "--"] + if {$i >= 0} { + set cmdline_files [lrange $rargs [expr {$i+1}] end] + set rargs [lrange $rargs 0 [expr {$i-1}]] + } if {$rargs == {}} { - set rargs HEAD + set parsed_args HEAD + } else { + set parsed_args $rargs } - set parsed_args $rargs } - return $parsed_args } proc start_rev_list {rlargs} { @@ -65,7 +84,7 @@ proc getcommits {rargs} { global phase canv mainfont set phase getcommits - start_rev_list [parse_args $rargs] + start_rev_list $rargs $canv delete all $canv create text 3 3 -anchor nw -text "Reading commits..." \ -font $mainfont -tags textitems @@ -141,11 +160,12 @@ proc getcommitlines {commfd} { set id [lindex $ids 0] if {$listed} { set olds [lrange $ids 1 end] - if {[llength $olds] > 1} { - set olds [lsort -unique $olds] - } + set i 0 foreach p $olds { - lappend children($p) $id + if {$i == 0 || [lsearch -exact $olds $p] >= $i} { + lappend children($p) $id + } + incr i } } else { set olds {} @@ -196,18 +216,18 @@ proc readcommit {id} { parsecommit $id $contents 0 } -proc updatecommits {rargs} { +proc updatecommits {} { + global parsed_args + + unselectline stopfindproc - foreach v {colormap selectedline matchinglines treediffs - mergefilelist currentid rowtextx commitrow - rowidlist rowoffsets idrowranges idrangedrawn iddrawn - linesegends crossings cornercrossings} { + foreach v {matchinglines treediffs currentid} { global $v catch {unset $v} } - allcanvs delete all + clear_display readrefs - getcommits $rargs + getcommits $parsed_args } proc parsecommit {id contents listed} { @@ -344,12 +364,18 @@ proc makewindow {rargs} { menu .bar .bar add cascade -label "File" -menu .bar.file menu .bar.file - .bar.file add command -label "Update" -command [list updatecommits $rargs] + .bar.file add command -label "Update" -command updatecommits .bar.file add command -label "Reread references" -command rereadrefs .bar.file add command -label "Quit" -command doquit menu .bar.edit .bar add cascade -label "Edit" -menu .bar.edit .bar.edit add command -label "Preferences" -command doprefs + menu .bar.view + .bar add cascade -label "View" -menu .bar.view + .bar.view add command -label "New view..." -command newview + .bar.view add command -label "Delete view" -command delview -state disabled + .bar.view add separator + .bar.view add command -label "All files" -command {showview 0} menu .bar.help .bar add cascade -label "Help" -menu .bar.help .bar.help add command -label "About gitk" -command about @@ -718,6 +744,169 @@ Use and redistribute under the terms of the GNU General Public License} \ pack $w.ok -side bottom } +proc newview {} { + global newviewname nextviewnum newviewtop + + set top .gitkview + if {[winfo exists $top]} { + raise $top + return + } + set newviewtop $top + toplevel $top + wm title $top "Gitk view definition" + label $top.nl -text "Name" + entry $top.name -width 20 -textvariable newviewname + set newviewname "View $nextviewnum" + grid $top.nl $top.name -sticky w + label $top.l -text "Files and directories to include:" + grid $top.l - -sticky w -pady 10 + text $top.t -width 30 -height 10 + grid $top.t - -sticky w + frame $top.buts + button $top.buts.ok -text "OK" -command newviewok + button $top.buts.can -text "Cancel" -command newviewcan + grid $top.buts.ok $top.buts.can + grid columnconfigure $top.buts 0 -weight 1 -uniform a + grid columnconfigure $top.buts 1 -weight 1 -uniform a + grid $top.buts - -pady 10 -sticky ew + focus $top.t +} + +proc newviewok {} { + global newviewtop nextviewnum + global viewname viewfiles + + set n $nextviewnum + incr nextviewnum + set viewname($n) [$newviewtop.name get] + set files {} + foreach f [split [$newviewtop.t get 0.0 end] "\n"] { + set ft [string trim $f] + if {$ft ne {}} { + lappend files $ft + } + } + set viewfiles($n) $files + catch {destroy $newviewtop} + unset newviewtop + .bar.view add command -label $viewname($n) -command [list showview $n] + after idle showview $n +} + +proc newviewcan {} { + global newviewtop + + catch {destroy $newviewtop} + unset newviewtop +} + +proc delview {} { + global curview viewdata + + if {$curview == 0} return + set nmenu [.bar.view index end] + set targetcmd [list showview $curview] + for {set i 5} {$i <= $nmenu} {incr i} { + if {[.bar.view entrycget $i -command] eq $targetcmd} { + .bar.view delete $i + break + } + } + set viewdata($curview) {} + showview 0 +} + +proc saveview {} { + global curview viewdata + global displayorder parentlist childlist rowidlist rowoffsets + global rowrangelist commitlisted + +} + +proc showview {n} { + global curview viewdata viewfiles + global displayorder parentlist childlist rowidlist rowoffsets + global colormap rowtextx commitrow + global numcommits rowrangelist commitlisted idrowranges + global selectedline currentid canv canvy0 + global matchinglines treediffs + global parsed_args + + if {$n == $curview} return + set selid {} + if {[info exists selectedline]} { + set selid $currentid + set y [yc $selectedline] + set ymax [lindex [$canv cget -scrollregion] 3] + set span [$canv yview] + set ytop [expr {[lindex $span 0] * $ymax}] + set ybot [expr {[lindex $span 1] * $ymax}] + if {$ytop < $y && $y < $ybot} { + set yscreen [expr {$y - $ytop}] + } else { + set yscreen [expr {($ybot - $ytop) / 2}] + } + } + unselectline + stopfindproc + if {![info exists viewdata($curview)]} { + set viewdata($curview) \ + [list $displayorder $parentlist $childlist $rowidlist \ + $rowoffsets $rowrangelist $commitlisted] + } + catch {unset matchinglines} + catch {unset treediffs} + clear_display + + set curview $n + .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}] + + if {![info exists viewdata($n)]} { + set args $parsed_args + if {$viewfiles($n) ne {}} { + set args [concat $args "--" $viewfiles($n)] + } + getcommits $args + return + } + + set displayorder [lindex $viewdata($n) 0] + set parentlist [lindex $viewdata($n) 1] + set childlist [lindex $viewdata($n) 2] + set rowidlist [lindex $viewdata($n) 3] + set rowoffsets [lindex $viewdata($n) 4] + set rowrangelist [lindex $viewdata($n) 5] + set commitlisted [lindex $viewdata($n) 6] + set numcommits [llength $displayorder] + catch {unset colormap} + catch {unset rowtextx} + catch {unset commitrow} + catch {unset idrowranges} + set curview $n + set row 0 + foreach id $displayorder { + set commitrow($id) $row + incr row + } + setcanvscroll + set yf 0 + set row 0 + if {$selid ne {} && [info exists commitrow($selid)]} { + set row $commitrow($selid) + # try to get the selected row in the same position on the screen + set ymax [lindex [$canv cget -scrollregion] 3] + set ytop [expr {[yc $row] - $yscreen}] + if {$ytop < 0} { + set ytop 0 + } + set yf [expr {$ytop * 1.0 / $ymax}] + } + allcanvs yview moveto $yf + drawvisible + selectline $row 0 +} + proc shortids {ids} { set res {} foreach id $ids { @@ -834,10 +1023,12 @@ proc makeuparrow {oid x y z} { proc initlayout {} { global rowidlist rowoffsets displayorder commitlisted global rowlaidout rowoptim - global idinlist rowchk + global idinlist rowchk rowrangelist idrowranges global commitidx numcommits canvxmax canv global nextcolor global parentlist childlist children + global colormap rowtextx commitrow + global linesegends set commitidx 0 set numcommits 0 @@ -845,6 +1036,7 @@ proc initlayout {} { set commitlisted {} set parentlist {} set childlist {} + set rowrangelist {{}} catch {unset children} set nextcolor 0 set rowidlist {{}} @@ -854,6 +1046,11 @@ proc initlayout {} { set rowlaidout 0 set rowoptim 0 set canvxmax [$canv cget -width] + catch {unset colormap} + catch {unset rowtextx} + catch {unset commitrow} + catch {unset idrowranges} + catch {unset linesegends} } proc setcanvscroll {} { @@ -892,7 +1089,6 @@ proc layoutmore {} { set rowlaidout [layoutrows $row $commitidx 0] set orow [expr {$rowlaidout - $uparrowlen - 1}] if {$orow > $rowoptim} { - checkcrossings $rowoptim $orow optimize_rows $rowoptim 0 $orow set rowoptim $orow } @@ -947,7 +1143,7 @@ proc layoutrows {row endrow last} { global childlist parentlist global idrowranges linesegends global commitidx - global idinlist rowchk + global idinlist rowchk rowrangelist set idlist [lindex $rowidlist $row] set offs [lindex $rowoffsets $row] @@ -1008,6 +1204,7 @@ proc layoutrows {row endrow last} { } if {[info exists idrowranges($id)]} { lappend idrowranges($id) $row + lappend rowrangelist $idrowranges($id) } incr row set offs [ntimes [llength $idlist] 0] @@ -1068,7 +1265,7 @@ proc addextraid {id row} { proc layouttail {} { global rowidlist rowoffsets idinlist commitidx - global idrowranges + global idrowranges rowrangelist set row $commitidx set idlist [lindex $rowidlist $row] @@ -1078,6 +1275,7 @@ proc layouttail {} { addextraid $id $row unset idinlist($id) lappend idrowranges($id) $row + lappend rowrangelist $idrowranges($id) incr row set offs [ntimes $col 0] set idlist [lreplace $idlist $col $col] @@ -1091,6 +1289,7 @@ proc layouttail {} { lset rowoffsets $row 0 makeuparrow $id 0 $row 0 lappend idrowranges($id) $row + lappend rowrangelist $idrowranges($id) incr row lappend rowidlist {} lappend rowoffsets {} @@ -1107,7 +1306,7 @@ proc insert_pad {row col npad} { } proc optimize_rows {row col endrow} { - global rowidlist rowoffsets idrowranges linesegends displayorder + global rowidlist rowoffsets idrowranges displayorder for {} {$row < $endrow} {incr row} { set idlist [lindex $rowidlist $row] @@ -1240,13 +1439,33 @@ proc linewidth {id} { return $wid } +proc rowranges {id} { + global idrowranges commitrow numcommits rowrangelist + + set ranges {} + if {[info exists commitrow($id)] && $commitrow($id) < $numcommits} { + set ranges [lindex $rowrangelist $commitrow($id)] + } elseif {[info exists idrowranges($id)]} { + set ranges $idrowranges($id) + } + return $ranges +} + proc drawlineseg {id i} { - global rowoffsets rowidlist idrowranges + global rowoffsets rowidlist global displayorder global canv colormap linespc + global numcommits commitrow - set startrow [lindex $idrowranges($id) [expr {2 * $i}]] - set row [lindex $idrowranges($id) [expr {2 * $i + 1}]] + set ranges [rowranges $id] + set downarrow 1 + if {[info exists commitrow($id)] && $commitrow($id) < $numcommits} { + set downarrow [expr {$i < [llength $ranges] / 2 - 1}] + } else { + set downarrow 1 + } + set startrow [lindex $ranges [expr {2 * $i}]] + set row [lindex $ranges [expr {2 * $i + 1}]] if {$startrow == $row} return assigncolor $id set coords {} @@ -1290,8 +1509,7 @@ proc drawlineseg {id i} { } } if {[llength $coords] < 4} return - set last [expr {[llength $idrowranges($id)] / 2 - 1}] - if {$i < $last} { + if {$downarrow} { # This line has an arrow at the lower end: check if the arrow is # on a diagonal segment, and if so, work around the Tk 8.4 # refusal to draw arrows on diagonal lines. @@ -1311,7 +1529,7 @@ proc drawlineseg {id i} { } } } - set arrow [expr {2 * ($i > 0) + ($i < $last)}] + set arrow [expr {2 * ($i > 0) + $downarrow}] set arrow [lindex {none first last both} $arrow] set t [$canv create line $coords -width [linewidth $id] \ -fill $colormap($id) -tags lines.$id -arrow $arrow] @@ -1320,7 +1538,7 @@ proc drawlineseg {id i} { } proc drawparentlinks {id row col olds} { - global rowidlist canv colormap idrowranges + global rowidlist canv colormap set row2 [expr {$row + 1}] set x [xc $row $col] @@ -1339,9 +1557,9 @@ proc drawparentlinks {id row col olds} { if {$x2 > $rmx} { set rmx $x2 } - if {[info exists idrowranges($p)] && - $row2 == [lindex $idrowranges($p) 0] && - $row2 < [lindex $idrowranges($p) 1]} { + set ranges [rowranges $p] + if {$ranges ne {} && $row2 == [lindex $ranges 0] + && $row2 < [lindex $ranges 1]} { # drawlineseg will do this one for us continue } @@ -1364,11 +1582,11 @@ proc drawparentlinks {id row col olds} { proc drawlines {id} { global colormap canv - global idrowranges idrangedrawn + global idrangedrawn global childlist iddrawn commitrow rowidlist $canv delete lines.$id - set nr [expr {[llength $idrowranges($id)] / 2}] + set nr [expr {[llength [rowranges $id]] / 2}] for {set i 0} {$i < $nr} {incr i} { if {[info exists idrangedrawn($id,$i)]} { drawlineseg $id $i @@ -1431,14 +1649,13 @@ proc drawcmittext {id row col rmx} { proc drawcmitrow {row} { global displayorder rowidlist - global idrowranges idrangedrawn iddrawn + global idrangedrawn iddrawn global commitinfo commitlisted parentlist numcommits if {$row >= $numcommits} return foreach id [lindex $rowidlist $row] { - if {![info exists idrowranges($id)]} continue set i -1 - foreach {s e} $idrowranges($id) { + foreach {s e} [rowranges $id] { incr i if {$row < $s} continue if {$e eq {}} break @@ -1507,10 +1724,50 @@ proc clear_display {} { catch {unset idrangedrawn} } +proc findcrossings {id} { + global rowidlist parentlist numcommits rowoffsets displayorder + + set cross {} + set ccross {} + foreach {s e} [rowranges $id] { + if {$e >= $numcommits} { + set e [expr {$numcommits - 1}] + if {$e < $s} continue + } + set x [lsearch -exact [lindex $rowidlist $e] $id] + if {$x < 0} { + puts "findcrossings: oops, no [shortids $id] in row $e" + continue + } + for {set row $e} {[incr row -1] >= $s} {} { + set olds [lindex $parentlist $row] + set kid [lindex $displayorder $row] + set kidx [lsearch -exact [lindex $rowidlist $row] $kid] + if {$kidx < 0} continue + set nextrow [lindex $rowidlist [expr {$row + 1}]] + foreach p $olds { + set px [lsearch -exact $nextrow $p] + if {$px < 0} continue + if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} { + if {[lsearch -exact $ccross $p] >= 0} continue + if {$x == $px + ($kidx < $px? -1: 1)} { + lappend ccross $p + } elseif {[lsearch -exact $cross $p] < 0} { + lappend cross $p + } + } + } + set inc [lindex $rowoffsets $row $x] + if {$inc eq {}} break + incr x $inc + } + } + return [concat $ccross {{}} $cross] +} + proc assigncolor {id} { global colormap colors nextcolor global commitrow parentlist children childlist - global cornercrossings crossings if {[info exists colormap($id)]} return set ncolors [llength $colors] @@ -1530,32 +1787,22 @@ proc assigncolor {id} { } } set badcolors {} - if {[info exists cornercrossings($id)]} { - foreach x $cornercrossings($id) { - if {[info exists colormap($x)] - && [lsearch -exact $badcolors $colormap($x)] < 0} { - lappend badcolors $colormap($x) - } + set origbad {} + foreach x [findcrossings $id] { + if {$x eq {}} { + # delimiter between corner crossings and other crossings + if {[llength $badcolors] >= $ncolors - 1} break + set origbad $badcolors } - if {[llength $badcolors] >= $ncolors} { - set badcolors {} + if {[info exists colormap($x)] + && [lsearch -exact $badcolors $colormap($x)] < 0} { + lappend badcolors $colormap($x) } } - set origbad $badcolors - if {[llength $badcolors] < $ncolors - 1} { - if {[info exists crossings($id)]} { - foreach x $crossings($id) { - if {[info exists colormap($x)] - && [lsearch -exact $badcolors $colormap($x)] < 0} { - lappend badcolors $colormap($x) - } - } - if {[llength $badcolors] >= $ncolors} { - set badcolors $origbad - } - } - set origbad $badcolors + if {[llength $badcolors] >= $ncolors} { + set badcolors $origbad } + set origbad $badcolors if {[llength $badcolors] < $ncolors - 1} { foreach child $kids { if {[info exists colormap($child)] @@ -1659,55 +1906,6 @@ proc drawtags {id x xt y1} { return $xt } -proc checkcrossings {row endrow} { - global displayorder parentlist rowidlist - - for {} {$row < $endrow} {incr row} { - set id [lindex $displayorder $row] - set i [lsearch -exact [lindex $rowidlist $row] $id] - if {$i < 0} continue - set idlist [lindex $rowidlist [expr {$row+1}]] - foreach p [lindex $parentlist $row] { - set j [lsearch -exact $idlist $p] - if {$j > 0} { - if {$j < $i - 1} { - notecrossings $row $p $j $i [expr {$j+1}] - } elseif {$j > $i + 1} { - notecrossings $row $p $i $j [expr {$j-1}] - } - } - } - } -} - -proc notecrossings {row id lo hi corner} { - global rowidlist crossings cornercrossings - - for {set i $lo} {[incr i] < $hi} {} { - set p [lindex [lindex $rowidlist $row] $i] - if {$p == {}} continue - if {$i == $corner} { - if {![info exists cornercrossings($id)] - || [lsearch -exact $cornercrossings($id) $p] < 0} { - lappend cornercrossings($id) $p - } - if {![info exists cornercrossings($p)] - || [lsearch -exact $cornercrossings($p) $id] < 0} { - lappend cornercrossings($p) $id - } - } else { - if {![info exists crossings($id)] - || [lsearch -exact $crossings($id) $p] < 0} { - lappend crossings($id) $p - } - if {![info exists crossings($p)] - || [lsearch -exact $crossings($p) $id] < 0} { - lappend crossings($p) $id - } - } - } -} - proc xcoord {i level ln} { global canvx0 xspc1 xspc2 @@ -1763,7 +1961,7 @@ proc drawrest {} { showstuff $commitidx set drawmsecs [expr {[clock clicks -milliseconds] - $startmsecs}] - puts "overall $drawmsecs ms for $numcommits commits" + #puts "overall $drawmsecs ms for $numcommits commits" } proc findmatches {f} { @@ -2433,9 +2631,10 @@ proc selnextline {dir} { } proc unselectline {} { - global selectedline + global selectedline currentid catch {unset selectedline} + catch {unset currentid} allcanvs delete secsel } @@ -2948,12 +3147,13 @@ proc linehover {} { } proc clickisonarrow {id y} { - global lthickness idrowranges + global lthickness + set ranges [rowranges $id] set thresh [expr {2 * $lthickness + 6}] - set n [expr {[llength $idrowranges($id)] - 1}] + set n [expr {[llength $ranges] - 1}] for {set i 1} {$i < $n} {incr i} { - set row [lindex $idrowranges($id) $i] + set row [lindex $ranges $i] if {abs([yc $row] - $y) < $thresh} { return $i } @@ -2962,11 +3162,11 @@ proc clickisonarrow {id y} { } proc arrowjump {id n y} { - global idrowranges canv + global canv # 1 <-> 2, 3 <-> 4, etc... set n [expr {(($n - 1) ^ 1) + 1}] - set row [lindex $idrowranges($id) $n] + set row [lindex [rowranges $id] $n] set yt [yc $row] set ymax [lindex [$canv cget -scrollregion] 3] if {$ymax eq {} || $ymax <= 0} return @@ -3819,10 +4019,26 @@ set historyindex 0 set optim_delay 16 +set nextviewnum 1 +set curview 0 +set viewfiles(0) {} + set stopped 0 set stuffsaved 0 set patchnum 0 setcoords makewindow $revtreeargs readrefs -getcommits $revtreeargs +parse_args $revtreeargs +set args $parsed_args +if {$cmdline_files ne {}} { + # create a view for the files/dirs specified on the command line + set curview 1 + set nextviewnum 2 + set viewname(1) "Command line" + set viewfiles(1) $cmdline_files + .bar.view add command -label $viewname(1) -command {showview 1} + .bar.view entryconf 2 -state normal + set args [concat $args "--" $cmdline_files] +} +getcommits $args -- cgit v1.2.1 From d94f8cd6adc746b850aad421e30d5f90f7f11ee4 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Thu, 6 Apr 2006 10:18:23 +1000 Subject: gitk: Make File->Update work properly again If a view is selected it will now just update that view. Also fixed a few other things - if you switch away from a view while gitk is still reading it in, then switch back, gitk will re-read it from scratch. We now re-read the references when switching views. If something was selected before a view change, and we need to read in the new view, we now select the previously-selected commit when we come across it. Fixed a bug in setting of rowrangelist plus a couple of other minor things. Signed-off-by: Paul Mackerras --- gitk | 59 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/gitk b/gitk index 961b582a4d..c6649a56d4 100755 --- a/gitk +++ b/gitk @@ -22,8 +22,8 @@ proc parse_args {rargs} { set parsed_args {} set cmdline_files {} if {[catch { - set parse_args [concat --default HEAD $rargs] - set args [split [eval exec git-rev-parse $parse_args] "\n"] + set args [concat --default HEAD $rargs] + set args [split [eval exec git-rev-parse $args] "\n"] set i 0 foreach arg $args { if {![regexp {^[0-9a-f]{40}$} $arg]} { @@ -217,17 +217,13 @@ proc readcommit {id} { } proc updatecommits {} { - global parsed_args + global viewdata curview revtreeargs - unselectline - stopfindproc - foreach v {matchinglines treediffs currentid} { - global $v - catch {unset $v} - } - clear_display - readrefs - getcommits $parsed_args + set n $curview + set curview -1 + catch {unset viewdata($n)} + parse_args $revtreeargs + showview $n } proc parsecommit {id contents listed} { @@ -354,7 +350,7 @@ proc error_popup msg { tkwait window $w } -proc makewindow {rargs} { +proc makewindow {} { global canv canv2 canv3 linespc charspc ctext cflist textfont global findtype findtypemenu findloc findstring fstring geometry global entries sha1entry sha1string sha1but @@ -817,13 +813,6 @@ proc delview {} { showview 0 } -proc saveview {} { - global curview viewdata - global displayorder parentlist childlist rowidlist rowoffsets - global rowrangelist commitlisted - -} - proc showview {n} { global curview viewdata viewfiles global displayorder parentlist childlist rowidlist rowoffsets @@ -832,6 +821,7 @@ proc showview {n} { global selectedline currentid canv canvy0 global matchinglines treediffs global parsed_args + global pending_select phase if {$n == $curview} return set selid {} @@ -850,7 +840,7 @@ proc showview {n} { } unselectline stopfindproc - if {![info exists viewdata($curview)]} { + if {$curview >= 0 && $phase eq {} && ![info exists viewdata($curview)]} { set viewdata($curview) \ [list $displayorder $parentlist $childlist $rowidlist \ $rowoffsets $rowrangelist $commitlisted] @@ -858,6 +848,7 @@ proc showview {n} { catch {unset matchinglines} catch {unset treediffs} clear_display + readrefs set curview $n .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}] @@ -867,6 +858,7 @@ proc showview {n} { if {$viewfiles($n) ne {}} { set args [concat $args "--" $viewfiles($n)] } + set pending_select $selid getcommits $args return } @@ -1036,7 +1028,7 @@ proc initlayout {} { set commitlisted {} set parentlist {} set childlist {} - set rowrangelist {{}} + set rowrangelist {} catch {unset children} set nextcolor 0 set rowidlist {{}} @@ -1099,7 +1091,7 @@ proc layoutmore {} { } proc showstuff {canshow} { - global numcommits + global numcommits commitrow pending_select global linesegends idrowranges idrangedrawn if {$numcommits == 0} { @@ -1113,6 +1105,7 @@ proc showstuff {canshow} { set rows [visiblerows] set r0 [lindex $rows 0] set r1 [lindex $rows 1] + set selrow -1 for {set r $row} {$r < $canshow} {incr r} { if {[info exists linesegends($r)]} { foreach id $linesegends($r) { @@ -1135,6 +1128,11 @@ proc showstuff {canshow} { drawcmitrow $row incr row } + if {[info exists pending_select] && + [info exists commitrow($pending_select)] && + $commitrow($pending_select) < $numcommits} { + selectline $commitrow($pending_select) 1 + } } proc layoutrows {row endrow last} { @@ -1202,10 +1200,12 @@ proc layoutrows {row endrow last} { } else { unset idinlist($id) } + set ranges {} if {[info exists idrowranges($id)]} { lappend idrowranges($id) $row - lappend rowrangelist $idrowranges($id) + set ranges $idrowranges($id) } + lappend rowrangelist $ranges incr row set offs [ntimes [llength $idlist] 0] set l [llength $newolds] @@ -1732,8 +1732,8 @@ proc findcrossings {id} { foreach {s e} [rowranges $id] { if {$e >= $numcommits} { set e [expr {$numcommits - 1}] - if {$e < $s} continue } + if {$e <= $s} continue set x [lsearch -exact [lindex $rowidlist $e] $id] if {$x < 0} { puts "findcrossings: oops, no [shortids $id] in row $e" @@ -2360,7 +2360,7 @@ proc donefilediff {} { } } -proc findcont {id} { +proc findcont {} { global findid treediffs parentlist global ffileline findstartline finddidsel global displayorder numcommits matchinglines findinprogress @@ -2493,8 +2493,9 @@ proc selectline {l isnew} { global canvy0 linespc parentlist childlist global cflist currentid sha1entry global commentend idtags linknum - global mergemax numcommits + global mergemax numcommits pending_select + catch {unset pending_select} $canv delete hover normalline if {$l < 0 || $l >= $numcommits} return @@ -2784,7 +2785,7 @@ proc getmergediffline {mdf id np} { incr nextupdate 100 fileevent $mdf readable {} update - fileevent $mdf readable [list getmergediffline $mdf $id] + fileevent $mdf readable [list getmergediffline $mdf $id $np] } } @@ -4027,7 +4028,7 @@ set stopped 0 set stuffsaved 0 set patchnum 0 setcoords -makewindow $revtreeargs +makewindow readrefs parse_args $revtreeargs set args $parsed_args -- cgit v1.2.1 From fdedbcfb0d71d99f96e08c1903ce8bd5a8f51a39 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Thu, 6 Apr 2006 21:22:52 +1000 Subject: gitk: Fix various bugs in the view support - don't re-read refs when switching views, it's too slow; just do it if the user did File->Update - make the view menu use the uifont - if we have a graph line selected, unselect it before changing the view - if a row is selected and appears in the new view, but we have to read in the new view, select that row when we come across it - if no row was previously selected, or if we don't find the previously selected row in the new view, select the first row Signed-off-by: Paul Mackerras --- gitk | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/gitk b/gitk index cfd0a3a698..093213f24d 100755 --- a/gitk +++ b/gitk @@ -223,6 +223,7 @@ proc updatecommits {} { set curview -1 catch {unset viewdata($n)} parse_args $revtreeargs + readrefs showview $n } @@ -351,7 +352,8 @@ proc error_popup msg { } proc makewindow {} { - global canv canv2 canv3 linespc charspc ctext cflist textfont mainfont uifont + global canv canv2 canv3 linespc charspc ctext cflist + global textfont mainfont uifont global findtype findtypemenu findloc findstring fstring geometry global entries sha1entry sha1string sha1but global maincursor textcursor curtextcursor @@ -369,7 +371,7 @@ proc makewindow {} { .bar add cascade -label "Edit" -menu .bar.edit .bar.edit add command -label "Preferences" -command doprefs .bar.edit configure -font $uifont - menu .bar.view + menu .bar.view -font $uifont .bar add cascade -label "View" -menu .bar.view .bar.view add command -label "New view..." -command newview .bar.view add command -label "Delete view" -command delview -state disabled @@ -907,6 +909,7 @@ proc showview {n} { } } unselectline + normalline stopfindproc if {$curview >= 0 && $phase eq {} && ![info exists viewdata($curview)]} { set viewdata($curview) \ @@ -916,7 +919,6 @@ proc showview {n} { catch {unset matchinglines} catch {unset treediffs} clear_display - readrefs set curview $n .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}] @@ -1159,7 +1161,7 @@ proc layoutmore {} { } proc showstuff {canshow} { - global numcommits commitrow pending_select + global numcommits commitrow pending_select selectedline global linesegends idrowranges idrangedrawn if {$numcommits == 0} { @@ -1201,6 +1203,9 @@ proc showstuff {canshow} { $commitrow($pending_select) < $numcommits} { selectline $commitrow($pending_select) 1 } + if {![info exists selectedline] && ![info exists pending_select]} { + selectline 0 1 + } } proc layoutrows {row endrow last} { @@ -1989,7 +1994,7 @@ proc xcoord {i level ln} { proc finishcommits {} { global commitidx phase global canv mainfont ctext maincursor textcursor - global findinprogress + global findinprogress pending_select if {$commitidx > 0} { drawrest @@ -2003,6 +2008,7 @@ proc finishcommits {} { settextcursor $textcursor } set phase {} + catch {unset pending_select} } # Don't change the text pane cursor if it is currently the hand cursor, @@ -2021,12 +2027,16 @@ proc drawrest {} { global startmsecs global canvy0 numcommits linespc global rowlaidout commitidx + global pending_select set row $rowlaidout layoutrows $rowlaidout $commitidx 1 layouttail optimize_rows $row 0 $commitidx showstuff $commitidx + if {[info exists pending_select]} { + selectline 0 1 + } set drawmsecs [expr {[clock clicks -milliseconds] - $startmsecs}] #puts "overall $drawmsecs ms for $numcommits commits" -- cgit v1.2.1 From 22626ef4fd5a0b2cf1fc8e90bbb23f8ff0ed43ea Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 17 Apr 2006 09:56:02 +1000 Subject: gitk: Don't reread git-rev-list output from scratch on view switch Previously, if we switched away from a view before we had finished reading the git-rev-list output for it and laying out the graph, we would discard the partially-laid-out graph and reread it from scratch if we switched back to the view. With this, we preserve the state of the partially-laid-out graph in viewdata($view) and restore it if we switch back. The pipe to git-rev-list remains open but we just don't read from it any more until we switch back to that view. This also makes linesegends a list rather than an array, which turns out to be slightly faster, as well as being easier to save and restore. The `update' menu item now kills the git-rev-list process if there is one still running when we do the update. Signed-off-by: Paul Mackerras --- gitk | 157 +++++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 116 insertions(+), 41 deletions(-) diff --git a/gitk b/gitk index 093213f24d..85f426ab22 100755 --- a/gitk +++ b/gitk @@ -80,6 +80,18 @@ proc start_rev_list {rlargs} { settextcursor watch } +proc stop_rev_list {} { + global commfd + + if {![info exists commfd]} return + catch { + set pid [pid $commfd] + exec kill $pid + } + catch {close $commfd} + unset commfd +} + proc getcommits {rargs} { global phase canv mainfont @@ -173,6 +185,7 @@ proc getcommitlines {commfd} { lappend parentlist $olds if {[info exists children($id)]} { lappend childlist $children($id) + unset children($id) } else { lappend childlist {} } @@ -217,8 +230,12 @@ proc readcommit {id} { } proc updatecommits {} { - global viewdata curview revtreeargs + global viewdata curview revtreeargs phase + if {$phase ne {}} { + stop_rev_list + set phase {} + } set n $curview set curview -1 catch {unset viewdata($n)} @@ -883,6 +900,25 @@ proc delview {} { showview 0 } +proc flatten {var} { + global $var + + set ret {} + foreach i [array names $var] { + lappend ret $i [set $var\($i\)] + } + return $ret +} + +proc unflatten {var l} { + global $var + + catch {unset $var} + foreach {i v} $l { + set $var\($i\) $v + } +} + proc showview {n} { global curview viewdata viewfiles global displayorder parentlist childlist rowidlist rowoffsets @@ -892,6 +928,8 @@ proc showview {n} { global matchinglines treediffs global parsed_args global pending_select phase + global commitidx rowlaidout rowoptim linesegends leftover + global commfd nextupdate if {$n == $curview} return set selid {} @@ -911,10 +949,21 @@ proc showview {n} { unselectline normalline stopfindproc - if {$curview >= 0 && $phase eq {} && ![info exists viewdata($curview)]} { - set viewdata($curview) \ - [list $displayorder $parentlist $childlist $rowidlist \ - $rowoffsets $rowrangelist $commitlisted] + if {$curview >= 0} { + if {$phase ne {}} { + set viewdata($curview) \ + [list $phase $displayorder $parentlist $childlist $rowidlist \ + $rowoffsets $rowrangelist $commitlisted \ + [flatten children] [flatten idrowranges] \ + [flatten idinlist] \ + $commitidx $rowlaidout $rowoptim $numcommits \ + $linesegends $leftover $commfd] + fileevent $commfd readable {} + } elseif {![info exists viewdata($curview)]} { + set viewdata($curview) \ + [list {} $displayorder $parentlist $childlist $rowidlist \ + $rowoffsets $rowrangelist $commitlisted] + } } catch {unset matchinglines} catch {unset treediffs} @@ -933,18 +982,37 @@ proc showview {n} { return } - set displayorder [lindex $viewdata($n) 0] - set parentlist [lindex $viewdata($n) 1] - set childlist [lindex $viewdata($n) 2] - set rowidlist [lindex $viewdata($n) 3] - set rowoffsets [lindex $viewdata($n) 4] - set rowrangelist [lindex $viewdata($n) 5] - set commitlisted [lindex $viewdata($n) 6] - set numcommits [llength $displayorder] + set v $viewdata($n) + set phase [lindex $v 0] + set displayorder [lindex $v 1] + set parentlist [lindex $v 2] + set childlist [lindex $v 3] + set rowidlist [lindex $v 4] + set rowoffsets [lindex $v 5] + set rowrangelist [lindex $v 6] + set commitlisted [lindex $v 7] + if {$phase eq {}} { + set numcommits [llength $displayorder] + catch {unset idrowranges} + catch {unset children} + } else { + unflatten children [lindex $v 8] + unflatten idrowranges [lindex $v 9] + unflatten idinlist [lindex $v 10] + set commitidx [lindex $v 11] + set rowlaidout [lindex $v 12] + set rowoptim [lindex $v 13] + set numcommits [lindex $v 14] + set linesegends [lindex $v 15] + set leftover [lindex $v 16] + set commfd [lindex $v 17] + fileevent $commfd readable [list getcommitlines $commfd] + set nextupdate [expr {[clock clicks -milliseconds] + 100}] + } + catch {unset colormap} catch {unset rowtextx} catch {unset commitrow} - catch {unset idrowranges} set curview $n set row 0 foreach id $displayorder { @@ -1004,20 +1072,21 @@ proc ntimes {n o} { } proc usedinrange {id l1 l2} { - global children commitrow + global children commitrow childlist if {[info exists commitrow($id)]} { set r $commitrow($id) if {$l1 <= $r && $r <= $l2} { return [expr {$r - $l1 + 1}] } + set kids [lindex $childlist $r] + } else { + set kids $children($id) } - foreach c $children($id) { - if {[info exists commitrow($c)]} { - set r $commitrow($c) - if {$l1 <= $r && $r <= $l2} { - return [expr {$r - $l1 + 1}] - } + foreach c $kids { + set r $commitrow($c) + if {$l1 <= $r && $r <= $l2} { + return [expr {$r - $l1 + 1}] } } return 0 @@ -1112,7 +1181,7 @@ proc initlayout {} { catch {unset rowtextx} catch {unset commitrow} catch {unset idrowranges} - catch {unset linesegends} + set linesegends {} } proc setcanvscroll {} { @@ -1177,16 +1246,14 @@ proc showstuff {canshow} { set r1 [lindex $rows 1] set selrow -1 for {set r $row} {$r < $canshow} {incr r} { - if {[info exists linesegends($r)]} { - foreach id $linesegends($r) { - set i -1 - foreach {s e} $idrowranges($id) { - incr i - if {$e ne {} && $e < $numcommits && $s <= $r1 && $e >= $r0 - && ![info exists idrangedrawn($id,$i)]} { - drawlineseg $id $i - set idrangedrawn($id,$i) 1 - } + foreach id [lindex $linesegends [expr {$r+1}]] { + set i -1 + foreach {s e} [rowranges $id] { + incr i + if {$e ne {} && $e < $numcommits && $s <= $r1 && $e >= $r0 + && ![info exists idrangedrawn($id,$i)]} { + drawlineseg $id $i + set idrangedrawn($id,$i) 1 } } } @@ -1229,6 +1296,7 @@ proc layoutrows {row endrow last} { lappend oldolds $p } } + set lse {} set nev [expr {[llength $idlist] + [llength $newolds] + [llength $oldolds] - $maxwidth + 1}] if {$nev > 0} { @@ -1244,7 +1312,7 @@ proc layoutrows {row endrow last} { set offs [incrange $offs $x 1] set idinlist($i) 0 set rm1 [expr {$row - 1}] - lappend linesegends($rm1) $i + lappend lse $i lappend idrowranges($i) $rm1 if {[incr nev -1] <= 0} break continue @@ -1255,6 +1323,7 @@ proc layoutrows {row endrow last} { lset rowidlist $row $idlist lset rowoffsets $row $offs } + lappend linesegends $lse set col [lsearch -exact $idlist $id] if {$col < 0} { set col [llength $idlist] @@ -1275,8 +1344,9 @@ proc layoutrows {row endrow last} { } set ranges {} if {[info exists idrowranges($id)]} { - lappend idrowranges($id) $row set ranges $idrowranges($id) + lappend ranges $row + unset idrowranges($id) } lappend rowrangelist $ranges incr row @@ -1331,6 +1401,7 @@ proc addextraid {id row} { } if {[info exists children($id)]} { lappend childlist $children($id) + unset children($id) } else { lappend childlist {} } @@ -1349,6 +1420,7 @@ proc layouttail {} { unset idinlist($id) lappend idrowranges($id) $row lappend rowrangelist $idrowranges($id) + unset idrowranges($id) incr row set offs [ntimes $col 0] set idlist [lreplace $idlist $col $col] @@ -1363,6 +1435,7 @@ proc layouttail {} { makeuparrow $id 0 $row 0 lappend idrowranges($id) $row lappend rowrangelist $idrowranges($id) + unset idrowranges($id) incr row lappend rowidlist {} lappend rowoffsets {} @@ -1398,8 +1471,8 @@ proc optimize_rows {row col endrow} { set z0 [lindex $rowoffsets $y0 $x0] if {$z0 eq {}} { set id [lindex $idlist $col] - if {[info exists idrowranges($id)] && - $y0 > [lindex $idrowranges($id) 0]} { + set ranges [rowranges $id] + if {$ranges ne {} && $y0 > [lindex $ranges 0]} { set isarrow 1 } } @@ -1457,8 +1530,8 @@ proc optimize_rows {row col endrow} { if {$o eq {}} { # check if this is the link to the first child set id [lindex $idlist $col] - if {[info exists idrowranges($id)] && - $row == [lindex $idrowranges($id) 0]} { + set ranges [rowranges $id] + if {$ranges ne {} && $row == [lindex $ranges 0]} { # it is, work out offset to child set y0 [expr {$row - 1}] set id [lindex $displayorder $y0] @@ -1513,10 +1586,11 @@ proc linewidth {id} { } proc rowranges {id} { - global idrowranges commitrow numcommits rowrangelist + global phase idrowranges commitrow rowlaidout rowrangelist set ranges {} - if {[info exists commitrow($id)] && $commitrow($id) < $numcommits} { + if {$phase eq {} || + ([info exists commitrow($id)] && $commitrow($id) < $rowlaidout)} { set ranges [lindex $rowrangelist $commitrow($id)] } elseif {[info exists idrowranges($id)]} { set ranges $idrowranges($id) @@ -1727,6 +1801,7 @@ proc drawcmitrow {row} { if {$row >= $numcommits} return foreach id [lindex $rowidlist $row] { + if {$id eq {}} continue set i -1 foreach {s e} [rowranges $id] { incr i @@ -3142,7 +3217,7 @@ proc incrfont {inc} { foreach e $entries { $e conf -font $mainfont } - if {$phase == "getcommits"} { + if {$phase eq "getcommits"} { $canv itemconf textitems -font $mainfont } redisplay -- cgit v1.2.1 From 2516dae2f63b6e6c4f7dbe2eb1322ba32da092c5 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Fri, 21 Apr 2006 10:35:31 +1000 Subject: gitk: Remember the view in the history list When moving backwards or forwards through the history list, this automatically switches the view so that each point that we jump to is shown in the same view that it was originally displayed in. Signed-off-by: Paul Mackerras --- gitk | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/gitk b/gitk index 85f426ab22..305aa2ef08 100755 --- a/gitk +++ b/gitk @@ -959,7 +959,8 @@ proc showview {n} { $commitidx $rowlaidout $rowoptim $numcommits \ $linesegends $leftover $commfd] fileevent $commfd readable {} - } elseif {![info exists viewdata($curview)]} { + } elseif {![info exists viewdata($curview)] + || [lindex $viewdata($curview) 0] ne {}} { set viewdata($curview) \ [list {} $displayorder $parentlist $childlist $rowidlist \ $rowoffsets $rowrangelist $commitlisted] @@ -1035,6 +1036,14 @@ proc showview {n} { allcanvs yview moveto $yf drawvisible selectline $row 0 + if {$phase eq {}} { + global maincursor textcursor + . config -cursor $maincursor + settextcursor $textcursor + } else { + . config -cursor watch + settextcursor watch + } } proc shortids {ids} { @@ -2301,7 +2310,7 @@ proc stopfindproc {{done 0}} { } if {[info exists findinprogress]} { unset findinprogress - if {$phase != "incrdraw"} { + if {$phase eq {}} { . config -cursor $maincursor settextcursor $textcursor } @@ -2840,17 +2849,18 @@ proc unselectline {} { } proc addtohistory {cmd} { - global history historyindex + global history historyindex curview + set elt [list $curview $cmd] if {$historyindex > 0 - && [lindex $history [expr {$historyindex - 1}]] == $cmd} { + && [lindex $history [expr {$historyindex - 1}]] == $elt} { return } if {$historyindex < [llength $history]} { - set history [lreplace $history $historyindex end $cmd] + set history [lreplace $history $historyindex end $elt] } else { - lappend history $cmd + lappend history $elt } incr historyindex if {$historyindex > 1} { @@ -2861,13 +2871,23 @@ proc addtohistory {cmd} { .ctop.top.bar.rightbut conf -state disabled } +proc godo {elt} { + global curview + + set view [lindex $elt 0] + set cmd [lindex $elt 1] + if {$curview != $view} { + showview $view + } + eval $cmd +} + proc goback {} { global history historyindex if {$historyindex > 1} { incr historyindex -1 - set cmd [lindex $history [expr {$historyindex - 1}]] - eval $cmd + godo [lindex $history [expr {$historyindex - 1}]] .ctop.top.bar.rightbut conf -state normal } if {$historyindex <= 1} { @@ -2881,7 +2901,7 @@ proc goforw {} { if {$historyindex < [llength $history]} { set cmd [lindex $history $historyindex] incr historyindex - eval $cmd + godo $cmd .ctop.top.bar.leftbut conf -state normal } if {$historyindex >= [llength $history]} { -- cgit v1.2.1 From a8aaf19c419a30d335f0640ab644112ecda6dd12 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Sun, 23 Apr 2006 22:45:55 +1000 Subject: gitk: Use git-rev-parse only to identify file/dir names on cmd line This uses git-rev-parse --no-revs --no-flags to give us just the file and directory names on the command line, so that we can create the "Command line" view if any were specified. All other arguments just get passed to git-rev-list (without a pass through git-rev-parse). Signed-off-by: Paul Mackerras --- gitk | 73 ++++++++++++++++++++++---------------------------------------------- 1 file changed, 23 insertions(+), 50 deletions(-) diff --git a/gitk b/gitk index 305aa2ef08..6cefc87218 100755 --- a/gitk +++ b/gitk @@ -16,56 +16,26 @@ proc gitdir {} { } } -proc parse_args {rargs} { - global parsed_args cmdline_files - - set parsed_args {} - set cmdline_files {} - if {[catch { - set args [concat --default HEAD $rargs] - set args [split [eval exec git-rev-parse $args] "\n"] - set i 0 - foreach arg $args { - if {![regexp {^[0-9a-f]{40}$} $arg]} { - if {$arg eq "--"} { - incr i - } - set cmdline_files [lrange $args $i end] - break - } - lappend parsed_args $arg - incr i - } - }]} { - # if git-rev-parse failed for some reason... - set i [lsearch -exact $rargs "--"] - if {$i >= 0} { - set cmdline_files [lrange $rargs [expr {$i+1}] end] - set rargs [lrange $rargs 0 [expr {$i-1}]] - } - if {$rargs == {}} { - set parsed_args HEAD - } else { - set parsed_args $rargs - } - } -} - -proc start_rev_list {rlargs} { +proc start_rev_list {} { global startmsecs nextupdate ncmupdate global commfd leftover tclencoding datemode + global revtreeargs curview viewfiles set startmsecs [clock clicks -milliseconds] set nextupdate [expr {$startmsecs + 100}] set ncmupdate 1 initlayout + set args $revtreeargs + if {$viewfiles($curview) ne {}} { + set args [concat $args "--" $viewfiles($curview)] + } set order "--topo-order" if {$datemode} { set order "--date-order" } if {[catch { set commfd [open [concat | git-rev-list --header $order \ - --parents --boundary $rlargs] r] + --parents --boundary --default HEAD $args] r] } err]} { puts stderr "Error executing git-rev-list: $err" exit 1 @@ -92,11 +62,11 @@ proc stop_rev_list {} { unset commfd } -proc getcommits {rargs} { +proc getcommits {} { global phase canv mainfont set phase getcommits - start_rev_list $rargs + start_rev_list $canv delete all $canv create text 3 3 -anchor nw -text "Reading commits..." \ -font $mainfont -tags textitems @@ -239,7 +209,6 @@ proc updatecommits {} { set n $curview set curview -1 catch {unset viewdata($n)} - parse_args $revtreeargs readrefs showview $n } @@ -926,7 +895,6 @@ proc showview {n} { global numcommits rowrangelist commitlisted idrowranges global selectedline currentid canv canvy0 global matchinglines treediffs - global parsed_args global pending_select phase global commitidx rowlaidout rowoptim linesegends leftover global commfd nextupdate @@ -974,12 +942,8 @@ proc showview {n} { .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}] if {![info exists viewdata($n)]} { - set args $parsed_args - if {$viewfiles($n) ne {}} { - set args [concat $args "--" $viewfiles($n)] - } set pending_select $selid - getcommits $args + getcommits return } @@ -4252,8 +4216,18 @@ set patchnum 0 setcoords makewindow readrefs -parse_args $revtreeargs -set args $parsed_args + +set cmdline_files {} +catch { + set fileargs [eval exec git-rev-parse --no-revs --no-flags $revtreeargs] + set cmdline_files [split $fileargs "\n"] + set n [llength $cmdline_files] + set revtreeargs [lrange $revtreeargs 0 end-$n] +} +if {[lindex $revtreeargs end] eq "--"} { + set revtreeargs [lrange $revtreeargs 0 end-1] +} + if {$cmdline_files ne {}} { # create a view for the files/dirs specified on the command line set curview 1 @@ -4262,6 +4236,5 @@ if {$cmdline_files ne {}} { set viewfiles(1) $cmdline_files .bar.view add command -label $viewname(1) -command {showview 1} .bar.view entryconf 2 -state normal - set args [concat $args "--" $cmdline_files] } -getcommits $args +getcommits -- cgit v1.2.1 From a90a6d249bc4fe29c11ce3291f9ec90d8e5e67f4 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Tue, 25 Apr 2006 17:12:46 +1000 Subject: gitk: Implement "permanent" views (stored in ~/.gitk) With this the user can now mark a view as "permanent" and it will appear in the list every time gitk is started (until it is deleted). Also tidied up the view definition window, and changed the view menu to use radiobuttons for the view selections so there is some feedback as to which is the current view. Signed-off-by: Paul Mackerras --- gitk | 61 ++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/gitk b/gitk index 4ee51223b7..6d6a2f32c7 100755 --- a/gitk +++ b/gitk @@ -362,7 +362,8 @@ proc makewindow {} { .bar.view add command -label "New view..." -command newview .bar.view add command -label "Delete view" -command delview -state disabled .bar.view add separator - .bar.view add command -label "All files" -command {showview 0} + .bar.view add radiobutton -label "All files" -command {showview 0} \ + -variable selectedview -value 0 menu .bar.help .bar add cascade -label "Help" -menu .bar.help .bar.help add command -label "About gitk" -command about @@ -632,6 +633,7 @@ proc savestuff {w} { global canv canv2 canv3 ctext cflist mainfont textfont uifont global stuffsaved findmergefiles maxgraphpct global maxwidth + global viewname viewfiles viewperm nextviewnum if {$stuffsaved} return if {![winfo viewable .]} return @@ -655,6 +657,13 @@ proc savestuff {w} { set wid [expr {([winfo width $cflist] - 11) \ / [font measure [$cflist cget -font] "0"]}] puts $f "set geometry(cflistw) $wid" + puts -nonewline $f "set permviews {" + for {set v 0} {$v < $nextviewnum} {incr v} { + if {$viewperm($v)} { + puts $f "{[list $viewname($v) $viewfiles($v)]}" + } + } + puts $f "}" close $f file rename -force "~/.gitk-new" "~/.gitk" } @@ -797,7 +806,7 @@ f Scroll diff view to next file } proc newview {} { - global newviewname nextviewnum newviewtop + global newviewname nextviewnum newviewtop newviewperm uifont set top .gitkview if {[winfo exists $top]} { @@ -807,14 +816,18 @@ proc newview {} { set newviewtop $top toplevel $top wm title $top "Gitk view definition" - label $top.nl -text "Name" + label $top.nl -text "Name" -font $uifont entry $top.name -width 20 -textvariable newviewname set newviewname "View $nextviewnum" - grid $top.nl $top.name -sticky w - label $top.l -text "Files and directories to include:" - grid $top.l - -sticky w -pady 10 - text $top.t -width 30 -height 10 - grid $top.t - -sticky w + grid $top.nl $top.name -sticky w -pady 5 + set newviewperm 0 + checkbutton $top.perm -text "Remember this view" -variable newviewperm + grid $top.perm - -pady 5 -sticky w + message $top.l -aspect 500 -font $uifont \ + -text "Enter files and directories to include, one per line:" + grid $top.l - -sticky w + text $top.t -width 40 -height 10 -background white + grid $top.t - -sticky w -padx 5 frame $top.buts button $top.buts.ok -text "OK" -command newviewok button $top.buts.can -text "Cancel" -command newviewcan @@ -826,12 +839,13 @@ proc newview {} { } proc newviewok {} { - global newviewtop nextviewnum - global viewname viewfiles + global newviewtop nextviewnum newviewperm + global viewname viewfiles viewperm selectedview set n $nextviewnum incr nextviewnum set viewname($n) [$newviewtop.name get] + set viewperm($n) $newviewperm set files {} foreach f [split [$newviewtop.t get 0.0 end] "\n"] { set ft [string trim $f] @@ -842,7 +856,8 @@ proc newviewok {} { set viewfiles($n) $files catch {destroy $newviewtop} unset newviewtop - .bar.view add command -label $viewname($n) -command [list showview $n] + .bar.view add radiobutton -label $viewname($n) \ + -command [list showview $n] -variable selectedview -value $n after idle showview $n } @@ -854,7 +869,7 @@ proc newviewcan {} { } proc delview {} { - global curview viewdata + global curview viewdata viewperm if {$curview == 0} return set nmenu [.bar.view index end] @@ -866,6 +881,7 @@ proc delview {} { } } set viewdata($curview) {} + set viewperm($curview) 0 showview 0 } @@ -898,6 +914,7 @@ proc showview {n} { global pending_select phase global commitidx rowlaidout rowoptim linesegends leftover global commfd nextupdate + global selectedview if {$n == $curview} return set selid {} @@ -939,6 +956,7 @@ proc showview {n} { clear_display set curview $n + set selectedview $n .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}] if {![info exists viewdata($n)]} { @@ -4209,7 +4227,9 @@ set optim_delay 16 set nextviewnum 1 set curview 0 +set selectedview 0 set viewfiles(0) {} +set viewperm(0) 0 set stopped 0 set stuffsaved 0 @@ -4232,10 +4252,25 @@ if {[lindex $revtreeargs end] eq "--"} { if {$cmdline_files ne {}} { # create a view for the files/dirs specified on the command line set curview 1 + set selectedview 1 set nextviewnum 2 set viewname(1) "Command line" set viewfiles(1) $cmdline_files - .bar.view add command -label $viewname(1) -command {showview 1} + set viewperm(1) 0 + .bar.view add radiobutton -label $viewname(1) -command {showview 1} \ + -variable selectedview -value 1 .bar.view entryconf 2 -state normal } + +if {[info exists permviews]} { + foreach v $permviews { + set n $nextviewnum + incr nextviewnum + set viewname($n) [lindex $v 0] + set viewfiles($n) [lindex $v 1] + set viewperm($n) 1 + .bar.view add radiobutton -label $viewname($n) \ + -command [list showview $n] -variable selectedview -value $n + } +} getcommits -- cgit v1.2.1 From d16c0812a9472794175b2543c2aa2df45a927202 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Tue, 25 Apr 2006 21:21:10 +1000 Subject: gitk: add menu item for editing the current view This allows the user to change the name of the view, whether it is permanent, and the list of files/directories for the view. Signed-off-by: Paul Mackerras --- gitk | 127 +++++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 37 deletions(-) diff --git a/gitk b/gitk index 6d6a2f32c7..a33a1e8a94 100755 --- a/gitk +++ b/gitk @@ -360,6 +360,7 @@ proc makewindow {} { menu .bar.view -font $uifont .bar add cascade -label "View" -menu .bar.view .bar.view add command -label "New view..." -command newview + .bar.view add command -label "Edit view..." -command editview .bar.view add command -label "Delete view" -command delview -state disabled .bar.view add separator .bar.view add radiobutton -label "All files" -command {showview 0} \ @@ -806,31 +807,59 @@ f Scroll diff view to next file } proc newview {} { - global newviewname nextviewnum newviewtop newviewperm uifont + global nextviewnum newviewname newviewperm uifont set top .gitkview if {[winfo exists $top]} { raise $top return } - set newviewtop $top + set newviewname($nextviewnum) "View $nextviewnum" + set newviewperm($nextviewnum) 0 + vieweditor $top $nextviewnum "Gitk view definition" +} + +proc editview {} { + global curview + global viewname viewperm newviewname newviewperm + + set top .gitkvedit-$curview + if {[winfo exists $top]} { + raise $top + return + } + set newviewname($curview) $viewname($curview) + set newviewperm($curview) $viewperm($curview) + vieweditor $top $curview "Gitk: edit view $viewname($curview)" +} + +proc vieweditor {top n title} { + global newviewname newviewperm viewfiles + global uifont + toplevel $top - wm title $top "Gitk view definition" + wm title $top $title label $top.nl -text "Name" -font $uifont - entry $top.name -width 20 -textvariable newviewname - set newviewname "View $nextviewnum" + entry $top.name -width 20 -textvariable newviewname($n) grid $top.nl $top.name -sticky w -pady 5 - set newviewperm 0 - checkbutton $top.perm -text "Remember this view" -variable newviewperm + checkbutton $top.perm -text "Remember this view" -variable newviewperm($n) grid $top.perm - -pady 5 -sticky w message $top.l -aspect 500 -font $uifont \ -text "Enter files and directories to include, one per line:" grid $top.l - -sticky w text $top.t -width 40 -height 10 -background white + if {[info exists viewfiles($n)]} { + foreach f $viewfiles($n) { + $top.t insert end $f + $top.t insert end "\n" + } + $top.t delete {end - 1c} end + $top.t mark set insert 0.0 + } grid $top.t - -sticky w -padx 5 frame $top.buts - button $top.buts.ok -text "OK" -command newviewok - button $top.buts.can -text "Cancel" -command newviewcan + button $top.buts.ok -text "OK" -command [list newviewok $top $n] + button $top.buts.can -text "Cancel" -command [list destroy $top] grid $top.buts.ok $top.buts.can grid columnconfigure $top.buts 0 -weight 1 -uniform a grid columnconfigure $top.buts 1 -weight 1 -uniform a @@ -838,47 +867,64 @@ proc newview {} { focus $top.t } -proc newviewok {} { - global newviewtop nextviewnum newviewperm - global viewname viewfiles viewperm selectedview +proc viewmenuitem {n} { + set nmenu [.bar.view index end] + set targetcmd [list showview $n] + for {set i 6} {$i <= $nmenu} {incr i} { + if {[.bar.view entrycget $i -command] eq $targetcmd} { + return $i + } + } + return {} +} + +proc newviewok {top n} { + global nextviewnum newviewperm newviewname + global viewname viewfiles viewperm selectedview curview - set n $nextviewnum - incr nextviewnum - set viewname($n) [$newviewtop.name get] - set viewperm($n) $newviewperm set files {} - foreach f [split [$newviewtop.t get 0.0 end] "\n"] { + foreach f [split [$top.t get 0.0 end] "\n"] { set ft [string trim $f] if {$ft ne {}} { lappend files $ft } } - set viewfiles($n) $files - catch {destroy $newviewtop} - unset newviewtop - .bar.view add radiobutton -label $viewname($n) \ - -command [list showview $n] -variable selectedview -value $n - after idle showview $n -} - -proc newviewcan {} { - global newviewtop - - catch {destroy $newviewtop} - unset newviewtop + if {![info exists viewfiles($n)]} { + # creating a new view + incr nextviewnum + set viewname($n) $newviewname($n) + set viewperm($n) $newviewperm($n) + set viewfiles($n) $files + .bar.view add radiobutton -label $viewname($n) \ + -command [list showview $n] -variable selectedview -value $n + after idle showview $n + } else { + # editing an existing view + set viewperm($n) $newviewperm($n) + if {$newviewname($n) ne $viewname($n)} { + set viewname($n) $newviewname($n) + set i [viewmenuitem $n] + if {$i ne {}} { + .bar.view entryconf $i -label $viewname($n) + } + } + if {$files ne $viewfiles($n)} { + set viewfiles($n) $files + if {$curview == $n} { + after idle updatecommits + } + } + } + catch {destroy $top} } proc delview {} { global curview viewdata viewperm if {$curview == 0} return - set nmenu [.bar.view index end] - set targetcmd [list showview $curview] - for {set i 5} {$i <= $nmenu} {incr i} { - if {[.bar.view entrycget $i -command] eq $targetcmd} { - .bar.view delete $i - break - } + set i [viewmenuitem $curview] + if {$i ne {}} { + .bar.view delete $i } set viewdata($curview) {} set viewperm($curview) 0 @@ -958,6 +1004,7 @@ proc showview {n} { set curview $n set selectedview $n .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}] + .bar.view entryconf 3 -state [expr {$n == 0? "disabled": "normal"}] if {![info exists viewdata($n)]} { set pending_select $selid @@ -1025,6 +1072,11 @@ proc showview {n} { } else { . config -cursor watch settextcursor watch + if {$phase eq "getcommits"} { + global mainfont + $canv create text 3 3 -anchor nw -text "Reading commits..." \ + -font $mainfont -tags textitems + } } } @@ -4260,6 +4312,7 @@ if {$cmdline_files ne {}} { .bar.view add radiobutton -label $viewname(1) -command {showview 1} \ -variable selectedview -value 1 .bar.view entryconf 2 -state normal + .bar.view entryconf 3 -state normal } if {[info exists permviews]} { -- cgit v1.2.1 From a970fcf249534ca21ad721b289402c135722a24c Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Tue, 18 Apr 2006 23:53:07 +0200 Subject: [PATCH] gitk: Add a visual tag for remote refs This patch partly changes the background color for remote refs. It makes it easy to quickly distinguish remote refs from local developer branches. I ignore remote HEADs, as these really should be drawn as aliases to other heads. But there is no simple way to detect that HEADs really are aliases for other refs via "git-ls-remote". Signed-off-by: Josef Weidendorfer Signed-off-by: Paul Mackerras --- gitk | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gitk b/gitk index 5362b76bee..7e80a7b984 100755 --- a/gitk +++ b/gitk @@ -274,10 +274,16 @@ proc readrefs {} { match id path]} { continue } + if {[regexp {^remotes/.*/HEAD$} $path match]} { + continue + } if {![regexp {^(tags|heads)/(.*)$} $path match type name]} { set type others set name $path } + if {[regexp {^remotes/} $path match]} { + set type heads + } if {$type == "tags"} { set tagids($name) $id lappend idtags($id) $name @@ -1702,6 +1708,14 @@ proc drawtags {id x xt y1} { set xl [expr {$xl - $delta/2}] $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \ -width 1 -outline black -fill $col -tags tag.$id + if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} { + set rwid [font measure $mainfont $remoteprefix] + set xi [expr {$x + 1}] + set yti [expr {$yt + 1}] + set xri [expr {$x + $rwid}] + $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \ + -width 0 -fill "#ffddaa" -tags tag.$id + } } set t [$canv create text $xl $y1 -anchor w -text $tag \ -font $mainfont -tags tag.$id] -- cgit v1.2.1 From 7fcceed7a024f5e2868c123c4ace5b7894ea3423 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Thu, 27 Apr 2006 19:21:49 +1000 Subject: gitk: Use a text widget for the file list This lets us do things like highlighting all the entries for which the corresponding part of the diff is at least partly visible in the commit/patch display window, and in future it will let us display the file list in a hierarchical form rather than as a flat file list. Signed-off-by: Paul Mackerras --- gitk | 190 ++++++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 131 insertions(+), 59 deletions(-) diff --git a/gitk b/gitk index 7c25d2ef97..bd205f876a 100755 --- a/gitk +++ b/gitk @@ -481,7 +481,7 @@ proc makewindow {} { set ctext .ctop.cdet.left.ctext text $ctext -bg white -state disabled -font $textfont \ -width $geometry(ctextw) -height $geometry(ctexth) \ - -yscrollcommand ".ctop.cdet.left.sb set" -wrap none + -yscrollcommand scrolltext -wrap none scrollbar .ctop.cdet.left.sb -command "$ctext yview" pack .ctop.cdet.left.sb -side right -fill y pack $ctext -side left -fill both -expand 1 @@ -515,11 +515,16 @@ proc makewindow {} { frame .ctop.cdet.right set cflist .ctop.cdet.right.cfiles - listbox $cflist -bg white -selectmode extended -width $geometry(cflistw) \ - -yscrollcommand ".ctop.cdet.right.sb set" -font $mainfont + set indent [font measure $mainfont "nn"] + text $cflist -width $geometry(cflistw) -background white -font $mainfont \ + -tabs [list $indent [expr {2 * $indent}]] \ + -yscrollcommand ".ctop.cdet.right.sb set" \ + -cursor [. cget -cursor] \ + -spacing1 1 -spacing3 1 scrollbar .ctop.cdet.right.sb -command "$cflist yview" pack .ctop.cdet.right.sb -side right -fill y pack $cflist -side left -fill both -expand 1 + $cflist tag configure highlight -background yellow .ctop.cdet add .ctop.cdet.right bind .ctop.cdet {resizecdetpanes %W %w} @@ -571,12 +576,13 @@ proc makewindow {} { bind . {incrfont 1} bind . {incrfont -1} bind . {incrfont -1} - bind $cflist <> listboxsel bind . {savestuff %W} bind . "click %W" bind $fstring dofind bind $sha1entry gotocommit bind $sha1entry <> clearsha1 + bind $cflist <1> {sel_flist %W %x %y; break} + bind $cflist {sel_flist %W %x %y; break} set maincursor [. cget -cursor] set textcursor [$ctext cget -cursor] @@ -812,6 +818,101 @@ f Scroll diff view to next file pack $w.ok -side bottom } +# Procedures for manipulating the file list window at the +# bottom right of the overall window. +proc init_flist {first} { + global cflist cflist_top cflist_bot selectedline difffilestart + + $cflist conf -state normal + $cflist delete 0.0 end + if {$first ne {}} { + $cflist insert end $first + set cflist_top 1 + set cflist_bot 1 + $cflist tag add highlight 1.0 "1.0 lineend" + } else { + catch {unset cflist_top} + } + $cflist conf -state disabled + set difffilestart {} +} + +proc add_flist {f} { + global flistmode cflist + + $cflist conf -state normal + if {$flistmode eq "flat"} { + $cflist insert end "\n$f" + } + $cflist conf -state disabled +} + +proc sel_flist {w x y} { + global flistmode ctext difffilestart cflist cflist_top + + if {![info exists cflist_top]} return + set l [lindex [split [$w index "@$x,$y"] "."] 0] + if {$flistmode eq "flat"} { + if {$l == 1} { + $ctext yview 1.0 + } else { + catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]} + } + highlight_flist $l + } +} + +proc scrolltext {f0 f1} { + global cflist_top + + .ctop.cdet.left.sb set $f0 $f1 + if {[info exists cflist_top]} { + highlight_flist $cflist_top + } +} + +# Given an index $tl in the $ctext window, this works out which line +# of the $cflist window displays the filename whose patch is shown +# at the given point in the $ctext window. $ll is a hint about which +# line it might be, and is used as the starting point of the search. +proc ctext_index {tl ll} { + global ctext difffilestart + + while {$ll >= 2 && [$ctext compare $tl < \ + [lindex $difffilestart [expr {$ll - 2}]]]} { + incr ll -1 + } + set nfiles [llength $difffilestart] + while {$ll - 1 < $nfiles && [$ctext compare $tl >= \ + [lindex $difffilestart [expr {$ll - 1}]]]} { + incr ll + } + return $ll +} + +proc highlight_flist {ll} { + global ctext cflist cflist_top cflist_bot difffilestart + + if {![info exists difffilestart] || [llength $difffilestart] == 0} return + set ll [ctext_index [$ctext index @0,1] $ll] + set lb $cflist_bot + if {$lb < $ll} { + set lb $ll + } + set y [expr {[winfo height $ctext] - 2}] + set lb [ctext_index [$ctext index @0,$y] $lb] + if {$ll != $cflist_top || $lb != $cflist_bot} { + $cflist tag remove highlight $cflist_top.0 "$cflist_bot.0 lineend" + for {set l $ll} {$l <= $lb} {incr l} { + $cflist tag add highlight $l.0 "$l.0 lineend" + } + set cflist_top $ll + set cflist_bot $lb + } +} + +# Code to implement multiple views + proc newview {} { global nextviewnum newviewname newviewperm uifont @@ -2718,7 +2819,7 @@ proc selectline {l isnew} { global canv canv2 canv3 ctext commitinfo selectedline global displayorder linehtag linentag linedtag global canvy0 linespc parentlist childlist - global cflist currentid sha1entry + global currentid sha1entry global commentend idtags linknum global mergemax numcommits pending_select @@ -2841,8 +2942,7 @@ proc selectline {l isnew} { $ctext conf -state disabled set commentend [$ctext index "end - 1c"] - $cflist delete 0 end - $cflist insert end "Comments" + init_flist "Comments" if {[llength $olds] <= 1} { startdiff $id } else { @@ -2960,12 +3060,11 @@ proc goforw {} { proc mergediff {id l} { global diffmergeid diffopts mdifffd - global difffilestart diffids + global diffids global parentlist set diffmergeid $id set diffids $id - catch {unset difffilestart} # this doesn't seem to actually affect anything... set env(GIT_DIFF_OPTS) $diffopts set cmd [concat | git-diff-tree --no-commit-id --cc $id] @@ -3000,11 +3099,10 @@ proc getmergediffline {mdf id np} { # start of a new file $ctext insert end "\n" set here [$ctext index "end - 1c"] - set i [$cflist index end] - $ctext mark set fmark.$i $here - $ctext mark gravity fmark.$i left - set difffilestart([expr {$i-1}]) $here - $cflist insert end $fname + $ctext mark set f:$fname $here + $ctext mark gravity f:$fname left + lappend difffilestart $here + add_flist $fname set l [expr {(78 - [string length $fname]) / 2}] set pad [string range "----------------------------------------" 1 $l] $ctext insert end "$pad $fname $pad\n" filesep @@ -3075,7 +3173,7 @@ proc startdiff {ids} { proc addtocflist {ids} { global treediffs cflist foreach f $treediffs($ids) { - $cflist insert end $f + add_flist $f } getblobdiffs $ids } @@ -3115,7 +3213,7 @@ proc gettreediffline {gdtf ids} { proc getblobdiffs {ids} { global diffopts blobdifffd diffids env curdifftag curtagstart - global difffilestart nextupdate diffinhdr treediffs + global nextupdate diffinhdr treediffs set env(GIT_DIFF_OPTS) $diffopts set cmd [concat | git-diff-tree --no-commit-id -r -p -C $ids] @@ -3128,7 +3226,6 @@ proc getblobdiffs {ids} { set blobdifffd($ids) $bdf set curdifftag Comments set curtagstart 0.0 - catch {unset difffilestart} fileevent $bdf readable [list getblobdiffline $bdf $diffids] set nextupdate [expr {[clock clicks -milliseconds] + 100}] } @@ -3156,24 +3253,15 @@ proc getblobdiffline {bdf ids} { # start of a new file $ctext insert end "\n" $ctext tag add $curdifftag $curtagstart end - set curtagstart [$ctext index "end - 1c"] - set header $newname set here [$ctext index "end - 1c"] - set i [lsearch -exact $treediffs($diffids) $fname] - if {$i >= 0} { - set difffilestart($i) $here - incr i - $ctext mark set fmark.$i $here - $ctext mark gravity fmark.$i left - } + set curtagstart $here + set header $newname + lappend difffilestart $here + $ctext mark set f:$fname $here + $ctext mark gravity f:$fname left if {$newname != $fname} { - set i [lsearch -exact $treediffs($diffids) $newname] - if {$i >= 0} { - set difffilestart($i) $here - incr i - $ctext mark set fmark.$i $here - $ctext mark gravity fmark.$i left - } + $ctext mark set f:$newfname $here + $ctext mark gravity f:$newfname left } set curdifftag "f:$fname" $ctext tag delete $curdifftag @@ -3222,26 +3310,11 @@ proc getblobdiffline {bdf ids} { proc nextfile {} { global difffilestart ctext set here [$ctext index @0,0] - for {set i 0} {[info exists difffilestart($i)]} {incr i} { - if {[$ctext compare $difffilestart($i) > $here]} { - if {![info exists pos] - || [$ctext compare $difffilestart($i) < $pos]} { - set pos $difffilestart($i) - } + foreach loc $difffilestart { + if {[$ctext compare $loc > $here]} { + $ctext yview $loc } } - if {[info exists pos]} { - $ctext yview $pos - } -} - -proc listboxsel {} { - global ctext cflist currentid - if {![info exists currentid]} return - set sel [lsort [$cflist curselection]] - if {$sel eq {}} return - set first [lindex $sel 0] - catch {$ctext yview fmark.$first} } proc setcoords {} { @@ -3452,7 +3525,7 @@ proc arrowjump {id n y} { } proc lineclick {x y id isnew} { - global ctext commitinfo childlist commitrow cflist canv thickerline + global ctext commitinfo childlist commitrow canv thickerline if {![info exists commitinfo($id)] && ![getcommit $id]} return unmarkmatches @@ -3509,8 +3582,7 @@ proc lineclick {x y id isnew} { } } $ctext conf -state disabled - - $cflist delete 0 end + init_flist {} } proc normalline {} { @@ -3568,15 +3640,14 @@ proc diffvssel {dirn} { } proc doseldiff {oldid newid} { - global ctext cflist + global ctext global commitinfo $ctext conf -state normal $ctext delete 0.0 end $ctext mark set fmark.0 0.0 $ctext mark gravity fmark.0 left - $cflist delete 0 end - $cflist insert end "Top" + init_flist "Top" $ctext insert end "From " $ctext tag conf link -foreground blue -underline 1 $ctext tag bind link { %W configure -cursor hand2 } @@ -3862,7 +3933,7 @@ proc rereadrefs {} { } proc showtag {tag isnew} { - global ctext cflist tagcontents tagids linknum + global ctext tagcontents tagids linknum if {$isnew} { addtohistory [list showtag $tag 0] @@ -3877,7 +3948,7 @@ proc showtag {tag isnew} { } appendwithlinks $text $ctext conf -state disabled - $cflist delete 0 end + init_flist {} } proc doquit {} { @@ -4259,6 +4330,7 @@ set fastdate 0 set uparrowlen 7 set downarrowlen 7 set mingaplen 30 +set flistmode "flat" set colors {green red blue magenta darkgrey brown orange} -- cgit v1.2.1 From c74320872b445104fe5c265e60785d9d26d94cc5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 27 Apr 2006 15:37:18 -0700 Subject: built-in count-objects. Also it learned to do -v (verbose) to report: - number of loose objects - disk occupied by loose objects - number of objects in local packs - number of loose objects that are also in pack - unrecognised garbage in .git/objects/??/. Signed-off-by: Junio C Hamano --- Makefile | 2 +- builtin-count.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ builtin.h | 1 + git.c | 1 + 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 builtin-count.c diff --git a/Makefile b/Makefile index 8ce27a65fb..14193aa1e2 100644 --- a/Makefile +++ b/Makefile @@ -214,7 +214,7 @@ LIB_OBJS = \ $(DIFF_OBJS) BUILTIN_OBJS = \ - builtin-log.o builtin-help.o + builtin-log.o builtin-help.o builtin-count.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/builtin-count.c b/builtin-count.c new file mode 100644 index 0000000000..0256369d5b --- /dev/null +++ b/builtin-count.c @@ -0,0 +1,123 @@ +/* + * Builtin "git count-objects". + * + * Copyright (c) 2006 Junio C Hamano + */ + +#include "cache.h" +#include "builtin.h" + +static const char count_objects_usage[] = "git-count-objects [-v]"; + +static void count_objects(DIR *d, char *path, int len, int verbose, + unsigned long *loose, + unsigned long *loose_size, + unsigned long *packed_loose, + unsigned long *garbage) +{ + struct dirent *ent; + while ((ent = readdir(d)) != NULL) { + char hex[41]; + unsigned char sha1[20]; + const char *cp; + int bad = 0; + + if ((ent->d_name[0] == '.') && + (ent->d_name[1] == 0 || + ((ent->d_name[1] == '.') && (ent->d_name[2] == 0)))) + continue; + for (cp = ent->d_name; *cp; cp++) { + int ch = *cp; + if (('0' <= ch && ch <= '9') || + ('a' <= ch && ch <= 'f')) + continue; + bad = 1; + break; + } + if (cp - ent->d_name != 38) + bad = 1; + else { + struct stat st; + memcpy(path + len + 3, ent->d_name, 38); + path[len + 2] = '/'; + path[len + 41] = 0; + if (lstat(path, &st) || !S_ISREG(st.st_mode)) + bad = 1; + else + (*loose_size) += st.st_blocks; + } + if (bad) { + if (verbose) { + error("garbage found: %.*s/%s", + len + 2, path, ent->d_name); + (*garbage)++; + } + continue; + } + (*loose)++; + if (!verbose) + continue; + memcpy(hex, path+len, 2); + memcpy(hex+2, ent->d_name, 38); + hex[40] = 0; + if (get_sha1_hex(hex, sha1)) + die("internal error"); + if (has_sha1_pack(sha1)) + (*packed_loose)++; + } +} + +int cmd_count_objects(int ac, const char **av, char **ep) +{ + int i; + int verbose = 0; + const char *objdir = get_object_directory(); + int len = strlen(objdir); + char *path = xmalloc(len + 50); + unsigned long loose = 0, packed = 0, packed_loose = 0, garbage = 0; + unsigned long loose_size = 0; + + for (i = 1; i < ac; i++) { + const char *arg = av[i]; + if (*arg != '-') + break; + else if (!strcmp(arg, "-v")) + verbose = 1; + else + usage(count_objects_usage); + } + + /* we do not take arguments other than flags for now */ + if (i < ac) + usage(count_objects_usage); + memcpy(path, objdir, len); + if (len && objdir[len-1] != '/') + path[len++] = '/'; + for (i = 0; i < 256; i++) { + DIR *d; + sprintf(path + len, "%02x", i); + d = opendir(path); + if (!d) + continue; + count_objects(d, path, len, verbose, + &loose, &loose_size, &packed_loose, &garbage); + closedir(d); + } + if (verbose) { + struct packed_git *p; + for (p = packed_git; p; p = p->next) { + if (!p->pack_local) + continue; + packed += num_packed_objects(p); + } + printf("count: %lu\n", loose); + printf("size: %lu\n", loose_size / 2); + printf("in-pack: %lu\n", packed); + printf("prune-packable: %lu\n", packed_loose); + printf("garbage: %lu\n", garbage); + } + else + printf("%lu objects, %lu kilobytes\n", + loose, loose_size / 2); + return 0; +} diff --git a/builtin.h b/builtin.h index 47408a0585..76169e3f05 100644 --- a/builtin.h +++ b/builtin.h @@ -19,5 +19,6 @@ extern int cmd_version(int argc, const char **argv, char **envp); extern int cmd_whatchanged(int argc, const char **argv, char **envp); extern int cmd_show(int argc, const char **argv, char **envp); extern int cmd_log(int argc, const char **argv, char **envp); +extern int cmd_count_objects(int argc, const char **argv, char **envp); #endif diff --git a/git.c b/git.c index 01b7e28b8c..00fb399725 100644 --- a/git.c +++ b/git.c @@ -46,6 +46,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "log", cmd_log }, { "whatchanged", cmd_whatchanged }, { "show", cmd_show }, + { "count-objects", cmd_count_objects }, }; int i; -- cgit v1.2.1 From 65056021f2d2dcb7a72f05c5d6cbbd79a79b9d40 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 28 Apr 2006 23:20:52 -0700 Subject: built-in diff. This starts to replace the shell script version of "git diff". Signed-off-by: Junio C Hamano --- Makefile | 2 +- builtin-diff.c | 332 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ builtin.h | 1 + git.c | 1 + 4 files changed, 335 insertions(+), 1 deletion(-) create mode 100644 builtin-diff.c diff --git a/Makefile b/Makefile index 8ce27a65fb..277c1ac079 100644 --- a/Makefile +++ b/Makefile @@ -214,7 +214,7 @@ LIB_OBJS = \ $(DIFF_OBJS) BUILTIN_OBJS = \ - builtin-log.o builtin-help.o + builtin-log.o builtin-help.o builtin-diff.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/builtin-diff.c b/builtin-diff.c new file mode 100644 index 0000000000..196821294e --- /dev/null +++ b/builtin-diff.c @@ -0,0 +1,332 @@ +/* + * Builtin "git diff" + * + * Copyright (c) 2006 Junio C Hamano + */ +#include "cache.h" +#include "commit.h" +#include "blob.h" +#include "tag.h" +#include "diff.h" +#include "diffcore.h" +#include "revision.h" +#include "log-tree.h" +#include "builtin.h" + +/* NEEDSWORK: struct object has place for name but we _do_ + * know mode when we extracted the blob out of a tree, which + * we currently lose. + */ +struct blobinfo { + unsigned char sha1[20]; + const char *name; +}; + +static const char builtin_diff_usage[] = +"diff {0,2} -- *"; + +static int builtin_diff_files(struct rev_info *revs, + int argc, const char **argv) +{ + int silent = 0; + while (1 < argc) { + const char *arg = argv[1]; + if (!strcmp(arg, "--base")) + revs->max_count = 1; + else if (!strcmp(arg, "--ours")) + revs->max_count = 2; + else if (!strcmp(arg, "--theirs")) + revs->max_count = 3; + else if (!strcmp(arg, "-q")) + silent = 1; + else if (!strcmp(arg, "--raw")) + revs->diffopt.output_format = DIFF_FORMAT_RAW; + else + usage(builtin_diff_usage); + argv++; argc--; + } + /* + * Make sure there are NO revision (i.e. pending object) parameter, + * rev.max_count is reasonable (0 <= n <= 3), + * there is no other revision filtering parameters. + */ + if (revs->pending_objects || + revs->min_age != -1 || + revs->max_age != -1) + usage(builtin_diff_usage); + /* + * Backward compatibility wart - "diff-files -s" used to + * defeat the common diff option "-s" which asked for + * DIFF_FORMAT_NO_OUTPUT. + */ + if (revs->diffopt.output_format == DIFF_FORMAT_NO_OUTPUT) + revs->diffopt.output_format = DIFF_FORMAT_RAW; + return run_diff_files(revs, silent); +} + +static void stuff_change(struct diff_options *opt, + unsigned old_mode, unsigned new_mode, + const unsigned char *old_sha1, + const unsigned char *new_sha1, + const char *old_name, + const char *new_name) +{ + struct diff_filespec *one, *two; + + if (memcmp(null_sha1, old_sha1, 20) && + memcmp(null_sha1, new_sha1, 20) && + !memcmp(old_sha1, new_sha1, 20)) + return; + + if (opt->reverse_diff) { + unsigned tmp; + const + const unsigned char *tmp_u; + const char *tmp_c; + tmp = old_mode; old_mode = new_mode; new_mode = tmp; + tmp_u = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_u; + tmp_c = old_name; old_name = new_name; new_name = tmp_c; + } + one = alloc_filespec(old_name); + two = alloc_filespec(new_name); + fill_filespec(one, old_sha1, old_mode); + fill_filespec(two, new_sha1, new_mode); + + /* NEEDSWORK: shouldn't this part of diffopt??? */ + diff_queue(&diff_queued_diff, one, two); +} + +static int builtin_diff_b_f(struct rev_info *revs, + int argc, const char **argv, + struct blobinfo *blob, + const char *path) +{ + /* Blob vs file in the working tree*/ + struct stat st; + + while (1 < argc) { + const char *arg = argv[1]; + if (!strcmp(arg, "--raw")) + revs->diffopt.output_format = DIFF_FORMAT_RAW; + else + usage(builtin_diff_usage); + argv++; argc--; + } + if (lstat(path, &st)) + die("'%s': %s", path, strerror(errno)); + if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))) + die("'%s': not a regular file or symlink", path); + stuff_change(&revs->diffopt, + canon_mode(st.st_mode), canon_mode(st.st_mode), + blob[0].sha1, null_sha1, + blob[0].name, path); + diffcore_std(&revs->diffopt); + diff_flush(&revs->diffopt); + return 0; +} + +static int builtin_diff_blobs(struct rev_info *revs, + int argc, const char **argv, + struct blobinfo *blob) +{ + /* Blobs */ + unsigned mode = canon_mode(S_IFREG | 0644); + + while (1 < argc) { + const char *arg = argv[1]; + if (!strcmp(arg, "--raw")) + revs->diffopt.output_format = DIFF_FORMAT_RAW; + else + usage(builtin_diff_usage); + argv++; argc--; + } + stuff_change(&revs->diffopt, + mode, mode, + blob[0].sha1, blob[1].sha1, + blob[1].name, blob[1].name); + diffcore_std(&revs->diffopt); + diff_flush(&revs->diffopt); + return 0; +} + +static int builtin_diff_index(struct rev_info *revs, + int argc, const char **argv) +{ + int cached = 0; + while (1 < argc) { + const char *arg = argv[1]; + if (!strcmp(arg, "--cached")) + cached = 1; + else if (!strcmp(arg, "--raw")) + revs->diffopt.output_format = DIFF_FORMAT_RAW; + else + usage(builtin_diff_usage); + argv++; argc--; + } + /* + * Make sure there is one revision (i.e. pending object), + * and there is no revision filtering parameters. + */ + if (!revs->pending_objects || revs->pending_objects->next || + revs->max_count != -1 || revs->min_age != -1 || + revs->max_age != -1) + usage(builtin_diff_usage); + return run_diff_index(revs, cached); +} + +static int builtin_diff_tree(struct rev_info *revs, + int argc, const char **argv, + struct object_list *ent) +{ + /* We saw two trees, ent[0] and ent[1]. + * unless ent[0] is unintesting, they are swapped + */ + const unsigned char *(sha1[2]); + int swap = 1; + while (1 < argc) { + const char *arg = argv[1]; + if (!strcmp(arg, "--raw")) + revs->diffopt.output_format = DIFF_FORMAT_RAW; + else + usage(builtin_diff_usage); + argv++; argc--; + } + if (ent[0].item->flags & UNINTERESTING) + swap = 0; + sha1[swap] = ent[0].item->sha1; + sha1[1-swap] = ent[1].item->sha1; + diff_tree_sha1(sha1[0], sha1[1], "", &revs->diffopt); + log_tree_diff_flush(revs); + return 0; +} + +static void add_head(struct rev_info *revs) +{ + unsigned char sha1[20]; + struct object *obj; + if (get_sha1("HEAD", sha1)) + return; + obj = parse_object(sha1); + if (!obj) + return; + add_object(obj, &revs->pending_objects, NULL, "HEAD"); +} + +int cmd_diff(int argc, const char **argv, char **envp) +{ + struct rev_info rev; + struct object_list *list, ent[2]; + int ents = 0, blobs = 0, paths = 0; + const char *path = NULL; + struct blobinfo blob[2]; + + /* + * We could get N tree-ish in the rev.pending_objects list. + * Also there could be M blobs there, and P pathspecs. + * + * N=0, M=0: + * cache vs files (diff-files) + * N=0, M=2: + * compare two random blobs. P must be zero. + * N=0, M=1, P=1: + * compare a blob with a working tree file. + * + * N=1, M=0: + * tree vs cache (diff-index --cached) + * + * N=2, M=0: + * tree vs tree (diff-tree) + * + * Other cases are errors. + */ + + git_config(git_diff_config); + init_revisions(&rev); + rev.diffopt.output_format = DIFF_FORMAT_PATCH; + + argc = setup_revisions(argc, argv, &rev, NULL); + /* Do we have --cached and not have a pending object, then + * default to HEAD by hand. Eek. + */ + if (!rev.pending_objects) { + int i; + for (i = 1; i < argc; i++) { + const char *arg = argv[i]; + if (!strcmp(arg, "--")) + break; + else if (!strcmp(arg, "--cached")) { + add_head(&rev); + break; + } + } + } + + for (list = rev.pending_objects; list; list = list->next) { + struct object *obj = list->item; + const char *name = list->name; + int flags = (obj->flags & UNINTERESTING); + if (!obj->parsed) + obj = parse_object(obj->sha1); + obj = deref_tag(obj, NULL, 0); + if (!obj) + die("invalid object '%s' given.", name); + if (!strcmp(obj->type, commit_type)) + obj = &((struct commit *)obj)->tree->object; + if (!strcmp(obj->type, tree_type)) { + if (2 <= ents) + die("more than two trees given: '%s'", name); + obj->flags |= flags; + ent[ents].item = obj; + ent[ents].name = name; + ents++; + continue; + } + if (!strcmp(obj->type, blob_type)) { + if (2 <= blobs) + die("more than two blobs given: '%s'", name); + memcpy(blob[blobs].sha1, obj->sha1, 20); + blob[blobs].name = name; + blobs++; + continue; + + } + die("unhandled object '%s' given.", name); + } + if (rev.prune_data) { + const char **pathspec = rev.prune_data; + while (*pathspec) { + if (!path) + path = *pathspec; + paths++; + pathspec++; + } + } + + /* + * Now, do the arguments look reasonable? + */ + if (!ents) { + switch (blobs) { + case 0: + return builtin_diff_files(&rev, argc, argv); + break; + case 1: + if (paths != 1) + usage(builtin_diff_usage); + return builtin_diff_b_f(&rev, argc, argv, blob, path); + break; + case 2: + return builtin_diff_blobs(&rev, argc, argv, blob); + break; + default: + usage(builtin_diff_usage); + } + } + else if (blobs) + usage(builtin_diff_usage); + else if (ents == 1) + return builtin_diff_index(&rev, argc, argv); + else if (ents == 2) + return builtin_diff_tree(&rev, argc, argv, ent); + usage(builtin_diff_usage); +} diff --git a/builtin.h b/builtin.h index 47408a0585..52ffa526f8 100644 --- a/builtin.h +++ b/builtin.h @@ -19,5 +19,6 @@ extern int cmd_version(int argc, const char **argv, char **envp); extern int cmd_whatchanged(int argc, const char **argv, char **envp); extern int cmd_show(int argc, const char **argv, char **envp); extern int cmd_log(int argc, const char **argv, char **envp); +extern int cmd_diff(int argc, const char **argv, char **envp); #endif diff --git a/git.c b/git.c index 01b7e28b8c..ff9b87abbc 100644 --- a/git.c +++ b/git.c @@ -46,6 +46,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "log", cmd_log }, { "whatchanged", cmd_whatchanged }, { "show", cmd_show }, + { "diffn", cmd_diff }, }; int i; -- cgit v1.2.1 From 0fe7c1de16f71312e6adac4b85bddf0d62a47168 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 29 Apr 2006 01:24:49 -0700 Subject: built-in diff: assorted updates. "git diff(n)" without --base, --ours, etc. defaults to --cc, which usually is the same as -p unless you are in the middle of a conflicted merge, just like the shell script version. "git diff(n) blobA blobB path" complains and dies. "git diff(n) tree0 tree1 tree2...treeN" does combined diff that shows a merge of tree1..treeN to result in tree0. Giving "-c" option to any command that defaults to "--cc" turns off dense-combined flag. Signed-off-by: Junio C Hamano --- builtin-diff.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- combine-diff.c | 47 ++++++++++++++++++++++++++++++----------------- diff.h | 2 ++ revision.c | 1 + 4 files changed, 79 insertions(+), 26 deletions(-) diff --git a/builtin-diff.c b/builtin-diff.c index 196821294e..c543105b8e 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -47,13 +47,17 @@ static int builtin_diff_files(struct rev_info *revs, } /* * Make sure there are NO revision (i.e. pending object) parameter, - * rev.max_count is reasonable (0 <= n <= 3), - * there is no other revision filtering parameters. + * specified rev.max_count is reasonable (0 <= n <= 3), and + * there is no other revision filtering parameter. */ if (revs->pending_objects || revs->min_age != -1 || - revs->max_age != -1) + revs->max_age != -1 || + 3 < revs->max_count) usage(builtin_diff_usage); + if (revs->max_count < 0 && + (revs->diffopt.output_format == DIFF_FORMAT_PATCH)) + revs->combine_merges = revs->dense_combined_merges = 1; /* * Backward compatibility wart - "diff-files -s" used to * defeat the common diff option "-s" which asked for @@ -178,9 +182,6 @@ static int builtin_diff_tree(struct rev_info *revs, int argc, const char **argv, struct object_list *ent) { - /* We saw two trees, ent[0] and ent[1]. - * unless ent[0] is unintesting, they are swapped - */ const unsigned char *(sha1[2]); int swap = 1; while (1 < argc) { @@ -191,6 +192,10 @@ static int builtin_diff_tree(struct rev_info *revs, usage(builtin_diff_usage); argv++; argc--; } + + /* We saw two trees, ent[0] and ent[1]. + * unless ent[0] is unintesting, they are swapped + */ if (ent[0].item->flags & UNINTERESTING) swap = 0; sha1[swap] = ent[0].item->sha1; @@ -200,6 +205,33 @@ static int builtin_diff_tree(struct rev_info *revs, return 0; } +static int builtin_diff_combined(struct rev_info *revs, + int argc, const char **argv, + struct object_list *ent, + int ents) +{ + const unsigned char (*parent)[20]; + int i; + + while (1 < argc) { + const char *arg = argv[1]; + if (!strcmp(arg, "--raw")) + revs->diffopt.output_format = DIFF_FORMAT_RAW; + else + usage(builtin_diff_usage); + argv++; argc--; + } + if (!revs->dense_combined_merges && !revs->combine_merges) + revs->dense_combined_merges = revs->combine_merges = 1; + parent = xmalloc(ents * sizeof(*parent)); + /* Again, the revs are all reverse */ + for (i = 0; i < ents; i++) + memcpy(parent + i, ent[ents - 1 - i].item->sha1, 20); + diff_tree_combined(parent[0], parent + 1, ents - 1, + revs->dense_combined_merges, revs); + return 0; +} + static void add_head(struct rev_info *revs) { unsigned char sha1[20]; @@ -215,7 +247,7 @@ static void add_head(struct rev_info *revs) int cmd_diff(int argc, const char **argv, char **envp) { struct rev_info rev; - struct object_list *list, ent[2]; + struct object_list *list, ent[100]; int ents = 0, blobs = 0, paths = 0; const char *path = NULL; struct blobinfo blob[2]; @@ -273,8 +305,9 @@ int cmd_diff(int argc, const char **argv, char **envp) if (!strcmp(obj->type, commit_type)) obj = &((struct commit *)obj)->tree->object; if (!strcmp(obj->type, tree_type)) { - if (2 <= ents) - die("more than two trees given: '%s'", name); + if (ARRAY_SIZE(ent) <= ents) + die("more than %d trees given: '%s'", + ARRAY_SIZE(ent), name); obj->flags |= flags; ent[ents].item = obj; ent[ents].name = name; @@ -316,6 +349,8 @@ int cmd_diff(int argc, const char **argv, char **envp) return builtin_diff_b_f(&rev, argc, argv, blob, path); break; case 2: + if (paths) + usage(builtin_diff_usage); return builtin_diff_blobs(&rev, argc, argv, blob); break; default: @@ -328,5 +363,7 @@ int cmd_diff(int argc, const char **argv, char **envp) return builtin_diff_index(&rev, argc, argv); else if (ents == 2) return builtin_diff_tree(&rev, argc, argv, ent); + else + return builtin_diff_combined(&rev, argc, argv, ent, ents); usage(builtin_diff_usage); } diff --git a/combine-diff.c b/combine-diff.c index ca36f5d5e7..8a8fe3863a 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -831,15 +831,16 @@ void show_combined_diff(struct combine_diff_path *p, } } -void diff_tree_combined_merge(const unsigned char *sha1, - int dense, struct rev_info *rev) +void diff_tree_combined(const unsigned char *sha1, + const unsigned char parent[][20], + int num_parent, + int dense, + struct rev_info *rev) { struct diff_options *opt = &rev->diffopt; - struct commit *commit = lookup_commit(sha1); struct diff_options diffopts; - struct commit_list *parents; struct combine_diff_path *p, *paths = NULL; - int num_parent, i, num_paths; + int i, num_paths; int do_diffstat; do_diffstat = (opt->output_format == DIFF_FORMAT_DIFFSTAT || @@ -849,17 +850,8 @@ void diff_tree_combined_merge(const unsigned char *sha1, diffopts.with_stat = 0; diffopts.recursive = 1; - /* count parents */ - for (parents = commit->parents, num_parent = 0; - parents; - parents = parents->next, num_parent++) - ; /* nothing */ - /* find set of paths that everybody touches */ - for (parents = commit->parents, i = 0; - parents; - parents = parents->next, i++) { - struct commit *parent = parents->item; + for (i = 0; i < num_parent; i++) { /* show stat against the first parent even * when doing combined diff. */ @@ -867,8 +859,7 @@ void diff_tree_combined_merge(const unsigned char *sha1, diffopts.output_format = DIFF_FORMAT_DIFFSTAT; else diffopts.output_format = DIFF_FORMAT_NO_OUTPUT; - diff_tree_sha1(parent->object.sha1, commit->object.sha1, "", - &diffopts); + diff_tree_sha1(parent[i], sha1, "", &diffopts); diffcore_std(&diffopts); paths = intersect_paths(paths, i, num_parent); @@ -907,3 +898,25 @@ void diff_tree_combined_merge(const unsigned char *sha1, free(tmp); } } + +void diff_tree_combined_merge(const unsigned char *sha1, + int dense, struct rev_info *rev) +{ + int num_parent; + const unsigned char (*parent)[20]; + struct commit *commit = lookup_commit(sha1); + struct commit_list *parents; + + /* count parents */ + for (parents = commit->parents, num_parent = 0; + parents; + parents = parents->next, num_parent++) + ; /* nothing */ + + parent = xmalloc(num_parent * sizeof(*parent)); + for (parents = commit->parents, num_parent = 0; + parents; + parents = parents->next, num_parent++) + memcpy(parent + num_parent, parents->item->object.sha1, 20); + diff_tree_combined(sha1, parent, num_parent, dense, rev); +} diff --git a/diff.h b/diff.h index 7150b90385..b3b2c4dd28 100644 --- a/diff.h +++ b/diff.h @@ -75,6 +75,8 @@ struct combine_diff_path { extern void show_combined_diff(struct combine_diff_path *elem, int num_parent, int dense, struct rev_info *); +extern void diff_tree_combined(const unsigned char *sha1, const unsigned char parent[][20], int num_parent, int dense, struct rev_info *rev); + extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *); extern void diff_addremove(struct diff_options *, diff --git a/revision.c b/revision.c index f2a9f25fe1..4381d455e4 100644 --- a/revision.c +++ b/revision.c @@ -664,6 +664,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch } if (!strcmp(arg, "-c")) { revs->diff = 1; + revs->dense_combined_merges = 0; revs->combine_merges = 1; continue; } -- cgit v1.2.1 From 334b506a3487f762493d3db2d3053114f25590e3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 30 Apr 2006 00:26:41 -0700 Subject: builtin-diff.c: die() formatting type fix. Signed-off-by: Junio C Hamano --- builtin-diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-diff.c b/builtin-diff.c index c543105b8e..b6114ce948 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -307,7 +307,7 @@ int cmd_diff(int argc, const char **argv, char **envp) if (!strcmp(obj->type, tree_type)) { if (ARRAY_SIZE(ent) <= ents) die("more than %d trees given: '%s'", - ARRAY_SIZE(ent), name); + (int) ARRAY_SIZE(ent), name); obj->flags |= flags; ent[ents].item = obj; ent[ents].name = name; -- cgit v1.2.1 From 755225de6ce4c7b39137afefb35208d0dbc14d9d Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 29 Apr 2006 21:22:49 -0700 Subject: git builtin "push" This adds a builtin "push" command, which is largely just a C'ification of the "git-push.sh" script. Now, the reason I did it as a built-in is partly because it's yet another step on relying less on shell, but it's actually mostly because I've wanted to be able to push to _multiple_ repositories, and the most obvious and simplest interface for that would seem be to just have a "remotes" file that has multiple URL entries. (For "pull", having multiple entries should either just select the first one, or you could fall back on the others on failure - your choice). And quite frankly, it just became too damn messy to do that in shell. Besides, we actually have a fair amount of infrastructure in C, so it just wasn't that hard to do. Of course, this is almost totally untested. It probably doesn't work for anything but the one trial I threw at it. "Simple" doesn't necessarily mean "obviously correct". Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- Makefile | 2 +- builtin-push.c | 255 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ builtin.h | 2 + git.c | 1 + 4 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 builtin-push.c diff --git a/Makefile b/Makefile index 8ce27a65fb..9919992392 100644 --- a/Makefile +++ b/Makefile @@ -214,7 +214,7 @@ LIB_OBJS = \ $(DIFF_OBJS) BUILTIN_OBJS = \ - builtin-log.o builtin-help.o + builtin-log.o builtin-help.o builtin-push.o GITLIBS = $(LIB_FILE) $(XDIFF_LIB) LIBS = $(GITLIBS) -lz diff --git a/builtin-push.c b/builtin-push.c new file mode 100644 index 0000000000..a0c1caab52 --- /dev/null +++ b/builtin-push.c @@ -0,0 +1,255 @@ +/* + * "git push" + */ +#include "cache.h" +#include "refs.h" +#include "run-command.h" +#include "builtin.h" + +#define MAX_URI (16) + +static const char push_usage[] = "git push [--all] [--tags] [--force] [...]"; + +static int all = 0, tags = 0, force = 0, thin = 1; +static const char *execute = NULL; + +#define BUF_SIZE (2084) +static char buffer[BUF_SIZE]; + +static const char **refspec = NULL; +static int refspec_nr = 0; + +static void add_refspec(const char *ref) +{ + int nr = refspec_nr + 1; + refspec = xrealloc(refspec, nr * sizeof(char *)); + refspec[nr-1] = ref; + refspec_nr = nr; +} + +static int expand_one_ref(const char *ref, const unsigned char *sha1) +{ + /* Ignore the "refs/" at the beginning of the refname */ + ref += 5; + + if (strncmp(ref, "tags/", 5)) + return 0; + + add_refspec(strdup(ref)); + return 0; +} + +static void expand_refspecs(void) +{ + if (all) { + if (refspec_nr) + die("cannot mix '--all' and a refspec"); + + /* + * No need to expand "--all" - we'll just use + * the "--all" flag to send-pack + */ + return; + } + if (!tags) + return; + for_each_ref(expand_one_ref); +} + +static void set_refspecs(const char **refs, int nr) +{ + if (nr) { + size_t bytes = nr * sizeof(char *); + + refspec = xrealloc(refspec, bytes); + memcpy(refspec, refs, bytes); + refspec_nr = nr; + } + expand_refspecs(); +} + +static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) +{ + int n = 0; + FILE *f = fopen(git_path("remotes/%s", repo), "r"); + + if (!f) + return -1; + while (fgets(buffer, BUF_SIZE, f)) { + char *s, *p; + + if (strncmp("URL: ", buffer, 5)) + continue; + s = buffer + 5; + + /* Remove whitespace at the head.. */ + while (isspace(*s)) + s++; + if (!*s) + continue; + + /* ..and at the end */ + p = s + strlen(s); + while (isspace(p[-1])) + *--p = 0; + + uri[n++] = strdup(s); + if (n == MAX_URI) + break; + } + fclose(f); + if (!n) + die("remote '%s' has no URL", repo); + return n; +} + +static int get_branches_uri(const char *repo, const char *uri[MAX_URI]) +{ + const char *slash = strchr(repo, '/'); + int n = slash ? slash - repo : 1000; + FILE *f = fopen(git_path("branches/%.*s", n, repo), "r"); + char *s, *p; + int len; + + if (!f) + return 0; + s = fgets(buffer, BUF_SIZE, f); + fclose(f); + if (!s) + return 0; + while (isspace(*s)) + s++; + if (!*s) + return 0; + p = s + strlen(s); + while (isspace(p[-1])) + *--p = 0; + len = p - s; + if (slash) + len += strlen(slash); + p = xmalloc(len + 1); + strcpy(p, s); + if (slash) + strcat(p, slash); + uri[0] = p; + return 1; +} + +static int get_uri(const char *repo, const char *uri[MAX_URI]) +{ + int n; + + if (*repo != '/') { + n = get_remotes_uri(repo, uri); + if (n > 0) + return n; + + n = get_branches_uri(repo, uri); + if (n > 0) + return n; + } + + uri[0] = repo; + return 1; +} + +static int do_push(const char *repo) +{ + const char *uri[MAX_URI]; + int i, n = get_uri(repo, uri); + int remote; + const char **argv; + int argc; + + n = get_uri(repo, uri); + if (n <= 0) + die("bad repository '%s'", repo); + + argv = xmalloc((refspec_nr + 10) * sizeof(char *)); + argv[0] = "dummy-send-pack"; + argc = 1; + if (all) + argv[argc++] = "--all"; + if (force) + argv[argc++] = "--force"; + if (execute) + argv[argc++] = execute; + if (thin) + argv[argc++] = "--thin"; + remote = argc; + argv[argc++] = "dummy-remote"; + while (refspec_nr--) + argv[argc++] = *refspec++; + argv[argc] = NULL; + + for (i = 0; i < n; i++) { + int error; + const char *dest = uri[i]; + const char *sender = "git-send-pack"; + if (!strncmp(dest, "http://", 7) || + !strncmp(dest, "https://", 8)) + sender = "git-http-push"; + argv[0] = sender; + argv[remote] = dest; + error = run_command_v(argc, argv); + if (!error) + continue; + switch (error) { + case -ERR_RUN_COMMAND_FORK: + die("unable to fork for %s", sender); + case -ERR_RUN_COMMAND_EXEC: + die("unable to exec %s", sender); + case -ERR_RUN_COMMAND_WAITPID: + case -ERR_RUN_COMMAND_WAITPID_WRONG_PID: + case -ERR_RUN_COMMAND_WAITPID_SIGNAL: + case -ERR_RUN_COMMAND_WAITPID_NOEXIT: + die("%s died with strange error", sender); + default: + return -error; + } + } + return 0; +} + +int cmd_push(int argc, const char **argv, char **envp) +{ + int i; + const char *repo = "origin"; // default repository + + for (i = 1; i < argc; i++) { + const char *arg = argv[i]; + + if (arg[0] != '-') { + repo = arg; + i++; + break; + } + if (!strcmp(arg, "--all")) { + all = 1; + continue; + } + if (!strcmp(arg, "--tags")) { + tags = 1; + continue; + } + if (!strcmp(arg, "--force")) { + force = 1; + continue; + } + if (!strcmp(arg, "--thin")) { + thin = 1; + continue; + } + if (!strcmp(arg, "--no-thin")) { + thin = 0; + continue; + } + if (!strncmp(arg, "--exec=", 7)) { + execute = arg; + continue; + } + usage(push_usage); + } + set_refspecs(argv + i, argc - i); + return do_push(repo); +} diff --git a/builtin.h b/builtin.h index 47408a0585..94fa9b5465 100644 --- a/builtin.h +++ b/builtin.h @@ -20,4 +20,6 @@ extern int cmd_whatchanged(int argc, const char **argv, char **envp); extern int cmd_show(int argc, const char **argv, char **envp); extern int cmd_log(int argc, const char **argv, char **envp); +extern int cmd_push(int argc, const char **argv, char **envp); + #endif diff --git a/git.c b/git.c index 01b7e28b8c..fd479e97c1 100644 --- a/git.c +++ b/git.c @@ -46,6 +46,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "log", cmd_log }, { "whatchanged", cmd_whatchanged }, { "show", cmd_show }, + { "push", cmd_push }, }; int i; -- cgit v1.2.1 From 5c477b972583e96b65ef1613c5d0fb1b90af3d0e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 30 Apr 2006 14:05:55 +0200 Subject: builtin-push: resurrect parsing of Push: lines The C'ification of push left these behind. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-push.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/builtin-push.c b/builtin-push.c index a0c1caab52..4e659f0f2b 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -68,6 +68,10 @@ static void set_refspecs(const char **refs, int nr) expand_refspecs(); } +#define MAX_REFSPECS 10 +static int current_refspec = 0; +static char *refspecs_[MAX_REFSPECS]; + static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) { int n = 0; @@ -76,11 +80,17 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) if (!f) return -1; while (fgets(buffer, BUF_SIZE, f)) { + int is_refspec; char *s, *p; - if (strncmp("URL: ", buffer, 5)) + if (!strncmp("URL: ", buffer, 5)) { + is_refspec = 0; + s = buffer + 5; + } else if (!strncmp("Push: ", buffer, 6)) { + is_refspec = 1; + s = buffer + 6; + } else continue; - s = buffer + 5; /* Remove whitespace at the head.. */ while (isspace(*s)) @@ -93,9 +103,10 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) while (isspace(p[-1])) *--p = 0; - uri[n++] = strdup(s); - if (n == MAX_URI) - break; + if (!is_refspec && n < MAX_URI) + uri[n++] = strdup(s); + else if (is_refspec && current_refspec < MAX_REFSPECS) + refspecs_[current_refspec++] = strdup(s); } fclose(f); if (!n) @@ -140,6 +151,8 @@ static int get_uri(const char *repo, const char *uri[MAX_URI]) int n; if (*repo != '/') { + current_refspec = 0; + n = get_remotes_uri(repo, uri); if (n > 0) return n; @@ -165,6 +178,9 @@ static int do_push(const char *repo) if (n <= 0) die("bad repository '%s'", repo); + if (refspec_nr == 0) + set_refspecs((const char**)refspecs_, current_refspec); + argv = xmalloc((refspec_nr + 10) * sizeof(char *)); argv[0] = "dummy-send-pack"; argc = 1; -- cgit v1.2.1 From 7aaf83dafbde7aaa60a1e220e967faaeb28a46f6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 30 Apr 2006 16:03:27 -0700 Subject: Fix builtin-push to honor Push: lines in remotes file. [jc: originally from Johannes Schindelin, but reworked to lift a hard limit of Push: lines] Signed-off-by: Junio C Hamano --- builtin-push.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/builtin-push.c b/builtin-push.c index 4e659f0f2b..9a861b5afe 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -68,14 +68,11 @@ static void set_refspecs(const char **refs, int nr) expand_refspecs(); } -#define MAX_REFSPECS 10 -static int current_refspec = 0; -static char *refspecs_[MAX_REFSPECS]; - static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) { int n = 0; FILE *f = fopen(git_path("remotes/%s", repo), "r"); + int has_explicit_refspec = refspec_nr; if (!f) return -1; @@ -103,10 +100,14 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) while (isspace(p[-1])) *--p = 0; - if (!is_refspec && n < MAX_URI) - uri[n++] = strdup(s); - else if (is_refspec && current_refspec < MAX_REFSPECS) - refspecs_[current_refspec++] = strdup(s); + if (!is_refspec) { + if (n < MAX_URI) + uri[n++] = strdup(s); + else + error("more than %d URL's specified, ignoreing the rest", MAX_URI); + } + else if (is_refspec && !has_explicit_refspec) + add_refspec(strdup(s)); } fclose(f); if (!n) @@ -146,13 +147,17 @@ static int get_branches_uri(const char *repo, const char *uri[MAX_URI]) return 1; } -static int get_uri(const char *repo, const char *uri[MAX_URI]) +/* + * Read remotes and branches file, fill the push target URI + * list. If there is no command line refspecs, read Push: lines + * to set up the *refspec list as well. + * return the number of push target URIs + */ +static int read_config(const char *repo, const char *uri[MAX_URI]) { int n; if (*repo != '/') { - current_refspec = 0; - n = get_remotes_uri(repo, uri); if (n > 0) return n; @@ -169,18 +174,15 @@ static int get_uri(const char *repo, const char *uri[MAX_URI]) static int do_push(const char *repo) { const char *uri[MAX_URI]; - int i, n = get_uri(repo, uri); + int i, n; int remote; const char **argv; int argc; - n = get_uri(repo, uri); + n = read_config(repo, uri); if (n <= 0) die("bad repository '%s'", repo); - if (refspec_nr == 0) - set_refspecs((const char**)refspecs_, current_refspec); - argv = xmalloc((refspec_nr + 10) * sizeof(char *)); argv[0] = "dummy-send-pack"; argc = 1; -- cgit v1.2.1 From f8b28a4078a29cbf93cac6f9edd8d5c203777313 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 1 May 2006 09:50:57 +1000 Subject: gitk: Add a tree-browsing mode You can now select whether you want to see the patch for a commit or the whole tree. If you select the tree, gitk will now display the commit message plus the contents of one file in the bottom-left pane, when you click on the name of the file in the bottom-right pane. Signed-off-by: Paul Mackerras --- gitk | 378 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 358 insertions(+), 20 deletions(-) diff --git a/gitk b/gitk index bd205f876a..f983deee8b 100755 --- a/gitk +++ b/gitk @@ -514,6 +514,13 @@ proc makewindow {} { $ctext tag conf found -back yellow frame .ctop.cdet.right + frame .ctop.cdet.right.mode + radiobutton .ctop.cdet.right.mode.patch -text "Patch" \ + -command reselectline -variable cmitmode -value "patch" + radiobutton .ctop.cdet.right.mode.tree -text "Tree" \ + -command reselectline -variable cmitmode -value "tree" + grid .ctop.cdet.right.mode.patch .ctop.cdet.right.mode.tree -sticky ew + pack .ctop.cdet.right.mode -side top -fill x set cflist .ctop.cdet.right.cfiles set indent [font measure $mainfont "nn"] text $cflist -width $geometry(cflistw) -background white -font $mainfont \ @@ -583,6 +590,7 @@ proc makewindow {} { bind $sha1entry <> clearsha1 bind $cflist <1> {sel_flist %W %x %y; break} bind $cflist {sel_flist %W %x %y; break} + bind $cflist {treeclick %W %x %y} set maincursor [. cget -cursor] set textcursor [$ctext cget -cursor] @@ -647,6 +655,7 @@ proc savestuff {w} { global stuffsaved findmergefiles maxgraphpct global maxwidth global viewname viewfiles viewperm nextviewnum + global cmitmode if {$stuffsaved} return if {![winfo viewable .]} return @@ -658,6 +667,7 @@ proc savestuff {w} { 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 "set geometry(width) [winfo width .ctop]" puts $f "set geometry(height) [winfo height .ctop]" puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]" @@ -820,6 +830,236 @@ f Scroll diff view to next file # Procedures for manipulating the file list window at the # bottom right of the overall window. + +proc treeview {w l openlevs} { + global treecontents treediropen treeheight treeparent treeindex + + set ix 0 + set treeindex() 0 + set lev 0 + set prefix {} + set prefixend -1 + set prefendstack {} + set htstack {} + set ht 0 + set treecontents() {} + $w conf -state normal + foreach f $l { + while {[string range $f 0 $prefixend] ne $prefix} { + if {$lev <= $openlevs} { + $w mark set e:$treeindex($prefix) "end -1c" + $w mark gravity e:$treeindex($prefix) left + } + set treeheight($prefix) $ht + incr ht [lindex $htstack end] + set htstack [lreplace $htstack end end] + set prefixend [lindex $prefendstack end] + set prefendstack [lreplace $prefendstack end end] + set prefix [string range $prefix 0 $prefixend] + incr lev -1 + } + set tail [string range $f [expr {$prefixend+1}] end] + while {[set slash [string first "/" $tail]] >= 0} { + lappend htstack $ht + set ht 0 + lappend prefendstack $prefixend + incr prefixend [expr {$slash + 1}] + set d [string range $tail 0 $slash] + lappend treecontents($prefix) $d + set oldprefix $prefix + append prefix $d + set treecontents($prefix) {} + set treeindex($prefix) [incr ix] + set treeparent($prefix) $oldprefix + set tail [string range $tail [expr {$slash+1}] end] + if {$lev <= $openlevs} { + set ht 1 + set treediropen($prefix) [expr {$lev < $openlevs}] + set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}] + $w mark set d:$ix "end -1c" + $w mark gravity d:$ix left + set str "\n" + for {set i 0} {$i < $lev} {incr i} {append str "\t"} + $w insert end $str + $w image create end -align center -image $bm -padx 1 \ + -name a:$ix + $w insert end $d + $w mark set s:$ix "end -1c" + $w mark gravity s:$ix left + } + incr lev + } + if {$tail ne {}} { + if {$lev <= $openlevs} { + incr ht + set str "\n" + for {set i 0} {$i < $lev} {incr i} {append str "\t"} + $w insert end $str + $w insert end $tail + } + lappend treecontents($prefix) $tail + } + } + while {$htstack ne {}} { + set treeheight($prefix) $ht + incr ht [lindex $htstack end] + set htstack [lreplace $htstack end end] + } + $w conf -state disabled +} + +proc linetoelt {l} { + global treeheight treecontents + + set y 2 + set prefix {} + while {1} { + foreach e $treecontents($prefix) { + if {$y == $l} { + return "$prefix$e" + } + set n 1 + if {[string index $e end] eq "/"} { + set n $treeheight($prefix$e) + if {$y + $n > $l} { + append prefix $e + incr y + break + } + } + incr y $n + } + } +} + +proc treeclosedir {w dir} { + global treediropen treeheight treeparent treeindex + + set ix $treeindex($dir) + $w conf -state normal + $w delete s:$ix e:$ix + set treediropen($dir) 0 + $w image configure a:$ix -image tri-rt + $w conf -state disabled + set n [expr {1 - $treeheight($dir)}] + while {$dir ne {}} { + incr treeheight($dir) $n + set dir $treeparent($dir) + } +} + +proc treeopendir {w dir} { + global treediropen treeheight treeparent treecontents treeindex + + set ix $treeindex($dir) + $w conf -state normal + $w image configure a:$ix -image tri-dn + $w mark set e:$ix s:$ix + $w mark gravity e:$ix right + set lev 0 + set str "\n" + set n [llength $treecontents($dir)] + for {set x $dir} {$x ne {}} {set x $treeparent($x)} { + incr lev + append str "\t" + incr treeheight($x) $n + } + foreach e $treecontents($dir) { + if {[string index $e end] eq "/"} { + set de $dir$e + set iy $treeindex($de) + $w mark set d:$iy e:$ix + $w mark gravity d:$iy left + $w insert e:$ix $str + set treediropen($de) 0 + $w image create e:$ix -align center -image tri-rt -padx 1 \ + -name a:$iy + $w insert e:$ix $e + $w mark set s:$iy e:$ix + $w mark gravity s:$iy left + set treeheight($de) 1 + } else { + $w insert e:$ix $str + $w insert e:$ix $e + } + } + $w mark gravity e:$ix left + $w conf -state disabled + set treediropen($dir) 1 + set top [lindex [split [$w index @0,0] .] 0] + set ht [$w cget -height] + set l [lindex [split [$w index s:$ix] .] 0] + if {$l < $top} { + $w yview $l.0 + } elseif {$l + $n + 1 > $top + $ht} { + set top [expr {$l + $n + 2 - $ht}] + if {$l < $top} { + set top $l + } + $w yview $top.0 + } +} + +proc treeclick {w x y} { + global treediropen cmitmode ctext cflist cflist_top + + if {$cmitmode ne "tree"} return + if {![info exists cflist_top]} return + set l [lindex [split [$w index "@$x,$y"] "."] 0] + $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend" + $cflist tag add highlight $l.0 "$l.0 lineend" + set cflist_top $l + if {$l == 1} { + $ctext yview 1.0 + return + } + set e [linetoelt $l] + if {[string index $e end] ne "/"} { + showfile $e + } elseif {$treediropen($e)} { + treeclosedir $w $e + } else { + treeopendir $w $e + } +} + +proc setfilelist {id} { + global treefilelist cflist + + treeview $cflist $treefilelist($id) 0 +} + +image create bitmap tri-rt -background black -foreground blue -data { + #define tri-rt_width 13 + #define tri-rt_height 13 + static unsigned char tri-rt_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00, + 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00}; +} -maskdata { + #define tri-rt-mask_width 13 + #define tri-rt-mask_height 13 + static unsigned char tri-rt-mask_bits[] = { + 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01, + 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00, + 0x08, 0x00}; +} +image create bitmap tri-dn -background black -foreground blue -data { + #define tri-dn_width 13 + #define tri-dn_height 13 + static unsigned char tri-dn_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03, + 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00}; +} -maskdata { + #define tri-dn-mask_width 13 + #define tri-dn-mask_height 13 + static unsigned char tri-dn-mask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07, + 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00}; +} + proc init_flist {first} { global cflist cflist_top cflist_bot selectedline difffilestart @@ -837,29 +1077,30 @@ proc init_flist {first} { set difffilestart {} } -proc add_flist {f} { +proc add_flist {fl} { global flistmode cflist $cflist conf -state normal if {$flistmode eq "flat"} { - $cflist insert end "\n$f" + foreach f $fl { + $cflist insert end "\n$f" + } } $cflist conf -state disabled } proc sel_flist {w x y} { - global flistmode ctext difffilestart cflist cflist_top + global flistmode ctext difffilestart cflist cflist_top cmitmode + if {$cmitmode eq "tree"} return if {![info exists cflist_top]} return set l [lindex [split [$w index "@$x,$y"] "."] 0] - if {$flistmode eq "flat"} { - if {$l == 1} { - $ctext yview 1.0 - } else { - catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]} - } - highlight_flist $l + if {$l == 1} { + $ctext yview 1.0 + } else { + catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]} } + highlight_flist $l } proc scrolltext {f0 f1} { @@ -2822,6 +3063,7 @@ proc selectline {l isnew} { global currentid sha1entry global commentend idtags linknum global mergemax numcommits pending_select + global cmitmode catch {unset pending_select} $canv delete hover @@ -2893,8 +3135,6 @@ proc selectline {l isnew} { $ctext conf -state normal $ctext delete 0.0 end set linknum 0 - $ctext mark set fmark.0 0.0 - $ctext mark gravity fmark.0 left set info $commitinfo($id) set date [formatdate [lindex $info 2]] $ctext insert end "Author: [lindex $info 1] $date\n" @@ -2943,7 +3183,9 @@ proc selectline {l isnew} { set commentend [$ctext index "end - 1c"] init_flist "Comments" - if {[llength $olds] <= 1} { + if {$cmitmode eq "tree"} { + gettree $id + } elseif {[llength $olds] <= 1} { startdiff $id } else { mergediff $id $l @@ -2997,6 +3239,14 @@ proc unselectline {} { allcanvs delete secsel } +proc reselectline {} { + global selectedline + + if {[info exists selectedline]} { + selectline $selectedline 0 + } +} + proc addtohistory {cmd} { global history historyindex curview @@ -3058,6 +3308,94 @@ proc goforw {} { } } +proc gettree {id} { + global treefilelist treeidlist diffids diffmergeid treepending + + set diffids $id + catch {unset diffmergeid} + if {![info exists treefilelist($id)]} { + if {![info exists treepending]} { + if {[catch {set gtf [open [concat | git-ls-tree -r $id] r]}]} { + return + } + set treepending $id + set treefilelist($id) {} + set treeidlist($id) {} + fconfigure $gtf -blocking 0 + fileevent $gtf readable [list gettreeline $gtf $id] + } + } else { + setfilelist $id + } +} + +proc gettreeline {gtf id} { + global treefilelist treeidlist treepending cmitmode diffids + + while {[gets $gtf line] >= 0} { + if {[lindex $line 1] ne "blob"} continue + set sha1 [lindex $line 2] + set fname [lindex $line 3] + lappend treefilelist($id) $fname + lappend treeidlist($id) $sha1 + } + if {![eof $gtf]} return + close $gtf + unset treepending + if {$cmitmode ne "tree"} { + if {![info exists diffmergeid]} { + gettreediffs $diffids + } + } elseif {$id ne $diffids} { + gettree $diffids + } else { + setfilelist $id + } +} + +proc showfile {f} { + global treefilelist treeidlist diffids + global ctext commentend + + set i [lsearch -exact $treefilelist($diffids) $f] + if {$i < 0} { + puts "oops, $f not in list for id $diffids" + return + } + 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 + } + fconfigure $bf -blocking 0 + fileevent $bf readable [list getblobline $bf $diffids] + $ctext config -state normal + $ctext delete $commentend end + $ctext insert end "\n" + $ctext insert end "$f\n" filesep + $ctext config -state disabled + $ctext yview $commentend +} + +proc getblobline {bf id} { + global diffids cmitmode ctext + + if {$id ne $diffids || $cmitmode ne "tree"} { + catch {close $bf} + return + } + $ctext config -state normal + while {[gets $bf line] >= 0} { + $ctext insert end "$line\n" + } + if {[eof $bf]} { + # delete last newline + $ctext delete "end - 2c" "end - 1c" + close $bf + } + $ctext config -state disabled +} + proc mergediff {id l} { global diffmergeid diffopts mdifffd global diffids @@ -3102,7 +3440,7 @@ proc getmergediffline {mdf id np} { $ctext mark set f:$fname $here $ctext mark gravity f:$fname left lappend difffilestart $here - add_flist $fname + add_flist [list $fname] set l [expr {(78 - [string length $fname]) / 2}] set pad [string range "----------------------------------------" 1 $l] $ctext insert end "$pad $fname $pad\n" filesep @@ -3172,9 +3510,7 @@ proc startdiff {ids} { proc addtocflist {ids} { global treediffs cflist - foreach f $treediffs($ids) { - add_flist $f - } + add_flist $treediffs($ids) getblobdiffs $ids } @@ -3191,6 +3527,7 @@ proc gettreediffs {ids} { proc gettreediffline {gdtf ids} { global treediff treediffs treepending diffids diffmergeid + global cmitmode set n [gets $gdtf line] if {$n < 0} { @@ -3198,7 +3535,9 @@ proc gettreediffline {gdtf ids} { close $gdtf set treediffs($ids) $treediff unset treepending - if {$ids != $diffids} { + if {$cmitmode eq "tree"} { + gettree $diffids + } elseif {$ids != $diffids} { if {![info exists diffmergeid]} { gettreediffs $diffids } @@ -3645,8 +3984,6 @@ proc doseldiff {oldid newid} { $ctext conf -state normal $ctext delete 0.0 end - $ctext mark set fmark.0 0.0 - $ctext mark gravity fmark.0 left init_flist "Top" $ctext insert end "From " $ctext tag conf link -foreground blue -underline 1 @@ -4331,6 +4668,7 @@ set uparrowlen 7 set downarrowlen 7 set mingaplen 30 set flistmode "flat" +set cmitmode "patch" set colors {green red blue magenta darkgrey brown orange} -- cgit v1.2.1 From da7c24dd9c75d014780179f8eb843968919e4c46 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Tue, 2 May 2006 11:15:29 +1000 Subject: gitk: Basic support for highlighting one view within another With this, one view can be used as a highlight for another, so that the commits that are in the highlight view are displayed in bold. This required some fairly major changes to how the list of ids, parents, children, and id to row mapping were stored for each view. We can now be reading in several views at once; for all except the current view, we just update the displayorder and the lists of parents and children for the view. This also creates a little bit of infrastructure for handling the watch cursor. Signed-off-by: Paul Mackerras --- gitk | 564 +++++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 343 insertions(+), 221 deletions(-) diff --git a/gitk b/gitk index f983deee8b..a83a754858 100755 --- a/gitk +++ b/gitk @@ -16,75 +16,82 @@ proc gitdir {} { } } -proc start_rev_list {} { +proc start_rev_list {view} { global startmsecs nextupdate ncmupdate global commfd leftover tclencoding datemode - global revtreeargs curview viewfiles + global revtreeargs viewfiles commitidx set startmsecs [clock clicks -milliseconds] set nextupdate [expr {$startmsecs + 100}] set ncmupdate 1 - initlayout + set commitidx($view) 0 set args $revtreeargs - if {$viewfiles($curview) ne {}} { - set args [concat $args "--" $viewfiles($curview)] + if {$viewfiles($view) ne {}} { + set args [concat $args "--" $viewfiles($view)] } set order "--topo-order" if {$datemode} { set order "--date-order" } if {[catch { - set commfd [open [concat | git-rev-list --header $order \ - --parents --boundary --default HEAD $args] r] + set fd [open [concat | git-rev-list --header $order \ + --parents --boundary --default HEAD $args] r] } err]} { puts stderr "Error executing git-rev-list: $err" exit 1 } - set leftover {} - fconfigure $commfd -blocking 0 -translation lf + set commfd($view) $fd + set leftover($view) {} + fconfigure $fd -blocking 0 -translation lf if {$tclencoding != {}} { - fconfigure $commfd -encoding $tclencoding + fconfigure $fd -encoding $tclencoding } - fileevent $commfd readable [list getcommitlines $commfd] - . config -cursor watch - settextcursor watch + fileevent $fd readable [list getcommitlines $fd $view] + nowbusy $view } proc stop_rev_list {} { - global commfd + global commfd curview - if {![info exists commfd]} return + if {![info exists commfd($curview)]} return + set fd $commfd($curview) catch { - set pid [pid $commfd] + set pid [pid $fd] exec kill $pid } - catch {close $commfd} - unset commfd + catch {close $fd} + unset commfd($curview) } proc getcommits {} { - global phase canv mainfont + global phase canv mainfont curview set phase getcommits - start_rev_list + initlayout + start_rev_list $curview $canv delete all $canv create text 3 3 -anchor nw -text "Reading commits..." \ -font $mainfont -tags textitems } -proc getcommitlines {commfd} { +proc getcommitlines {fd view} { global commitlisted nextupdate - global leftover + global leftover commfd global displayorder commitidx commitrow commitdata - global parentlist childlist children + global parentlist childlist children curview hlview + global vparentlist vchildlist vdisporder vcmitlisted - set stuff [read $commfd] + set stuff [read $fd] if {$stuff == {}} { - if {![eof $commfd]} return + if {![eof $fd]} return + unset commfd($view) # set it blocking so we wait for the process to terminate - fconfigure $commfd -blocking 1 - if {![catch {close $commfd} err]} { - after idle finishcommits + fconfigure $fd -blocking 1 + if {![catch {close $fd} err]} { + notbusy $view + if {$view == $curview} { + after idle finishcommits + } return } if {[string range $err 0 4] == "usage"} { @@ -103,13 +110,13 @@ proc getcommitlines {commfd} { while 1 { set i [string first "\0" $stuff $start] if {$i < 0} { - append leftover [string range $stuff $start end] + append leftover($view) [string range $stuff $start end] break } if {$start == 0} { - set cmit $leftover + set cmit $leftover($view) append cmit [string range $stuff 0 [expr {$i - 1}]] - set leftover {} + set leftover($view) {} } else { set cmit [string range $stuff $start [expr {$i - 1}]] } @@ -145,40 +152,49 @@ proc getcommitlines {commfd} { set i 0 foreach p $olds { if {$i == 0 || [lsearch -exact $olds $p] >= $i} { - lappend children($p) $id + lappend children($view,$p) $id } incr i } } else { set olds {} } - lappend parentlist $olds - if {[info exists children($id)]} { - lappend childlist $children($id) - unset children($id) - } else { - lappend childlist {} + if {![info exists children($view,$id)]} { + set children($view,$id) {} } set commitdata($id) [string range $cmit [expr {$j + 1}] end] - set commitrow($id) $commitidx - incr commitidx - lappend displayorder $id - lappend commitlisted $listed + set commitrow($view,$id) $commitidx($view) + incr commitidx($view) + if {$view == $curview} { + lappend parentlist $olds + lappend childlist $children($view,$id) + lappend displayorder $id + lappend commitlisted $listed + } else { + lappend vparentlist($view) $olds + lappend vchildlist($view) $children($view,$id) + lappend vdisporder($view) $id + lappend vcmitlisted($view) $listed + } set gotsome 1 } if {$gotsome} { - layoutmore + if {$view == $curview} { + layoutmore + } elseif {[info exists hlview] && $view == $hlview} { + highlightmore + } } if {[clock clicks -milliseconds] >= $nextupdate} { - doupdate 1 + doupdate } } -proc doupdate {reading} { +proc doupdate {} { global commfd nextupdate numcommits ncmupdate - if {$reading} { - fileevent $commfd readable {} + foreach v [array names commfd] { + fileevent $commfd($v) readable {} } update set nextupdate [expr {[clock clicks -milliseconds] + 100}] @@ -189,8 +205,9 @@ proc doupdate {reading} { } else { set ncmupdate [expr {$numcommits + 100}] } - if {$reading} { - fileevent $commfd readable [list getcommitlines $commfd] + foreach v [array names commfd] { + set fd $commfd($v) + fileevent $fd readable [list getcommitlines $fd $v] } } @@ -200,13 +217,18 @@ proc readcommit {id} { } proc updatecommits {} { - global viewdata curview revtreeargs phase + global viewdata curview revtreeargs phase displayorder + global children commitrow if {$phase ne {}} { stop_rev_list set phase {} } set n $curview + foreach id $displayorder { + catch {unset children($n,$id)} + catch {unset commitrow($n,$id)} + } set curview -1 catch {unset viewdata($n)} readrefs @@ -363,14 +385,23 @@ proc makewindow {} { .bar add cascade -label "Edit" -menu .bar.edit .bar.edit add command -label "Preferences" -command doprefs .bar.edit configure -font $uifont + menu .bar.view -font $uifont + menu .bar.view.hl -font $uifont -tearoff 0 .bar add cascade -label "View" -menu .bar.view - .bar.view add command -label "New view..." -command newview - .bar.view add command -label "Edit view..." -command editview + .bar.view add command -label "New view..." -command {newview 0} + .bar.view add command -label "Edit view..." -command editview \ + -state disabled .bar.view add command -label "Delete view" -command delview -state disabled + .bar.view add cascade -label "Highlight" -menu .bar.view.hl .bar.view add separator .bar.view add radiobutton -label "All files" -command {showview 0} \ -variable selectedview -value 0 + .bar.view.hl add command -label "New view..." -command {newview 1} + .bar.view.hl add command -label "Remove" -command delhighlight \ + -state disabled + .bar.view.hl add separator + menu .bar.help .bar add cascade -label "Help" -menu .bar.help .bar.help add command -label "About gitk" -command about @@ -1154,9 +1185,10 @@ proc highlight_flist {ll} { # Code to implement multiple views -proc newview {} { - global nextviewnum newviewname newviewperm uifont +proc newview {ishighlight} { + global nextviewnum newviewname newviewperm uifont newishighlight + set newishighlight $ishighlight set top .gitkview if {[winfo exists $top]} { raise $top @@ -1215,19 +1247,23 @@ proc vieweditor {top n title} { focus $top.t } -proc viewmenuitem {n} { - set nmenu [.bar.view index end] - set targetcmd [list showview $n] - for {set i 6} {$i <= $nmenu} {incr i} { - if {[.bar.view entrycget $i -command] eq $targetcmd} { - return $i +proc doviewmenu {m first cmd op args} { + set nmenu [$m index end] + for {set i $first} {$i <= $nmenu} {incr i} { + if {[$m entrycget $i -command] eq $cmd} { + eval $m $op $i $args + break } } - return {} +} + +proc allviewmenus {n op args} { + doviewmenu .bar.view 6 [list showview $n] $op $args + doviewmenu .bar.view.hl 3 [list addhighlight $n] $op $args } proc newviewok {top n} { - global nextviewnum newviewperm newviewname + global nextviewnum newviewperm newviewname newishighlight global viewname viewfiles viewperm selectedview curview set files {} @@ -1243,18 +1279,18 @@ proc newviewok {top n} { set viewname($n) $newviewname($n) set viewperm($n) $newviewperm($n) set viewfiles($n) $files - .bar.view add radiobutton -label $viewname($n) \ - -command [list showview $n] -variable selectedview -value $n - after idle showview $n + addviewmenu $n + if {!$newishighlight} { + after idle showview $n + } else { + after idle addhighlight $n + } } else { # editing an existing view set viewperm($n) $newviewperm($n) if {$newviewname($n) ne $viewname($n)} { set viewname($n) $newviewname($n) - set i [viewmenuitem $n] - if {$i ne {}} { - .bar.view entryconf $i -label $viewname($n) - } + allviewmenus $n entryconf -label $viewname($n) } if {$files ne $viewfiles($n)} { set viewfiles($n) $files @@ -1270,15 +1306,21 @@ proc delview {} { global curview viewdata viewperm if {$curview == 0} return - set i [viewmenuitem $curview] - if {$i ne {}} { - .bar.view delete $i - } + allviewmenus $curview delete set viewdata($curview) {} set viewperm($curview) 0 showview 0 } +proc addviewmenu {n} { + global viewname + + .bar.view add radiobutton -label $viewname($n) \ + -command [list showview $n] -variable selectedview -value $n + .bar.view.hl add radiobutton -label $viewname($n) \ + -command [list addhighlight $n] -variable selectedhlview -value $n +} + proc flatten {var} { global $var @@ -1301,14 +1343,15 @@ proc unflatten {var l} { proc showview {n} { global curview viewdata viewfiles global displayorder parentlist childlist rowidlist rowoffsets - global colormap rowtextx commitrow + global colormap rowtextx commitrow nextcolor canvxmax global numcommits rowrangelist commitlisted idrowranges global selectedline currentid canv canvy0 global matchinglines treediffs global pending_select phase - global commitidx rowlaidout rowoptim linesegends leftover + global commitidx rowlaidout rowoptim linesegends global commfd nextupdate - global selectedview + global selectedview hlview selectedhlview + global vparentlist vchildlist vdisporder vcmitlisted if {$n == $curview} return set selid {} @@ -1329,20 +1372,19 @@ proc showview {n} { normalline stopfindproc if {$curview >= 0} { + set vparentlist($curview) $parentlist + set vchildlist($curview) $childlist + set vdisporder($curview) $displayorder + set vcmitlisted($curview) $commitlisted if {$phase ne {}} { set viewdata($curview) \ - [list $phase $displayorder $parentlist $childlist $rowidlist \ - $rowoffsets $rowrangelist $commitlisted \ - [flatten children] [flatten idrowranges] \ - [flatten idinlist] \ - $commitidx $rowlaidout $rowoptim $numcommits \ - $linesegends $leftover $commfd] - fileevent $commfd readable {} + [list $phase $rowidlist $rowoffsets $rowrangelist \ + [flatten idrowranges] [flatten idinlist] \ + $rowlaidout $rowoptim $numcommits $linesegends] } elseif {![info exists viewdata($curview)] || [lindex $viewdata($curview) 0] ne {}} { set viewdata($curview) \ - [list {} $displayorder $parentlist $childlist $rowidlist \ - $rowoffsets $rowrangelist $commitlisted] + [list {} $rowidlist $rowoffsets $rowrangelist] } } catch {unset matchinglines} @@ -1351,8 +1393,11 @@ proc showview {n} { set curview $n set selectedview $n + set selectedhlview -1 + .bar.view entryconf 1 -state [expr {$n == 0? "disabled": "normal"}] .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}] - .bar.view entryconf 3 -state [expr {$n == 0? "disabled": "normal"}] + catch {unset hlview} + .bar.view.hl entryconf 1 -state disabled if {![info exists viewdata($n)]} { set pending_select $selid @@ -1362,46 +1407,36 @@ proc showview {n} { set v $viewdata($n) set phase [lindex $v 0] - set displayorder [lindex $v 1] - set parentlist [lindex $v 2] - set childlist [lindex $v 3] - set rowidlist [lindex $v 4] - set rowoffsets [lindex $v 5] - set rowrangelist [lindex $v 6] - set commitlisted [lindex $v 7] + set displayorder $vdisporder($n) + set parentlist $vparentlist($n) + set childlist $vchildlist($n) + set commitlisted $vcmitlisted($n) + set rowidlist [lindex $v 1] + set rowoffsets [lindex $v 2] + set rowrangelist [lindex $v 3] if {$phase eq {}} { set numcommits [llength $displayorder] catch {unset idrowranges} - catch {unset children} } else { - unflatten children [lindex $v 8] - unflatten idrowranges [lindex $v 9] - unflatten idinlist [lindex $v 10] - set commitidx [lindex $v 11] - set rowlaidout [lindex $v 12] - set rowoptim [lindex $v 13] - set numcommits [lindex $v 14] - set linesegends [lindex $v 15] - set leftover [lindex $v 16] - set commfd [lindex $v 17] - fileevent $commfd readable [list getcommitlines $commfd] - set nextupdate [expr {[clock clicks -milliseconds] + 100}] + unflatten idrowranges [lindex $v 4] + unflatten idinlist [lindex $v 5] + set rowlaidout [lindex $v 6] + set rowoptim [lindex $v 7] + set numcommits [lindex $v 8] + set linesegends [lindex $v 9] } catch {unset colormap} catch {unset rowtextx} - catch {unset commitrow} + set nextcolor 0 + set canvxmax [$canv cget -width] set curview $n set row 0 - foreach id $displayorder { - set commitrow($id) $row - incr row - } setcanvscroll set yf 0 set row 0 - if {$selid ne {} && [info exists commitrow($selid)]} { - set row $commitrow($selid) + if {$selid ne {} && [info exists commitrow($n,$selid)]} { + set row $commitrow($n,$selid) # try to get the selected row in the same position on the screen set ymax [lindex [$canv cget -scrollregion] 3] set ytop [expr {[yc $row] - $yscreen}] @@ -1413,21 +1448,98 @@ proc showview {n} { allcanvs yview moveto $yf drawvisible selectline $row 0 - if {$phase eq {}} { - global maincursor textcursor - . config -cursor $maincursor - settextcursor $textcursor - } else { - . config -cursor watch - settextcursor watch + if {$phase ne {}} { if {$phase eq "getcommits"} { global mainfont $canv create text 3 3 -anchor nw -text "Reading commits..." \ -font $mainfont -tags textitems } + if {[info exists commfd($n)]} { + layoutmore + } else { + finishcommits + } } } +proc addhighlight {n} { + global hlview curview viewdata highlighted highlightedrows + global selectedhlview + + if {[info exists hlview]} { + delhighlight + } + set hlview $n + set selectedhlview $n + .bar.view.hl entryconf 1 -state normal + set highlighted($n) 0 + set highlightedrows {} + if {$n != $curview && ![info exists viewdata($n)]} { + set viewdata($n) [list getcommits {{}} {{}} {} {} {} 0 0 0 {}] + set vparentlist($n) {} + set vchildlist($n) {} + set vdisporder($n) {} + set vcmitlisted($n) {} + start_rev_list $n + } else { + highlightmore + } +} + +proc delhighlight {} { + global hlview highlightedrows canv linehtag mainfont + global selectedhlview selectedline + + if {![info exists hlview]} return + unset hlview + set selectedhlview {} + .bar.view.hl entryconf 1 -state disabled + foreach l $highlightedrows { + $canv itemconf $linehtag($l) -font $mainfont + if {$l == $selectedline} { + $canv delete secsel + set t [eval $canv create rect [$canv bbox $linehtag($l)] \ + -outline {{}} -tags secsel \ + -fill [$canv cget -selectbackground]] + $canv lower $t + } + } +} + +proc highlightmore {} { + global hlview highlighted commitidx highlightedrows linehtag mainfont + global displayorder vdisporder curview canv commitrow selectedline + + set font [concat $mainfont bold] + set max $commitidx($hlview) + if {$hlview == $curview} { + set disp $displayorder + } else { + set disp $vdisporder($hlview) + } + for {set i $highlighted($hlview)} {$i < $max} {incr i} { + set id [lindex $disp $i] + if {[info exists commitrow($curview,$id)]} { + set row $commitrow($curview,$id) + if {[info exists linehtag($row)]} { + $canv itemconf $linehtag($row) -font $font + lappend highlightedrows $row + if {$row == $selectedline} { + $canv delete secsel + set t [eval $canv create rect \ + [$canv bbox $linehtag($row)] \ + -outline {{}} -tags secsel \ + -fill [$canv cget -selectbackground]] + $canv lower $t + } + } + } + } + set highlighted($hlview) $max +} + +# Graph layout functions + proc shortids {ids} { set res {} foreach id $ids { @@ -1463,19 +1575,19 @@ proc ntimes {n o} { } proc usedinrange {id l1 l2} { - global children commitrow childlist + global children commitrow childlist curview - if {[info exists commitrow($id)]} { - set r $commitrow($id) + if {[info exists commitrow($curview,$id)]} { + set r $commitrow($curview,$id) if {$l1 <= $r && $r <= $l2} { return [expr {$r - $l1 + 1}] } set kids [lindex $childlist $r] } else { - set kids $children($id) + set kids $children($curview,$id) } foreach c $kids { - set r $commitrow($c) + set r $commitrow($curview,$c) if {$l1 <= $r && $r <= $l2} { return [expr {$r - $l1 + 1}] } @@ -1546,20 +1658,18 @@ proc initlayout {} { global rowidlist rowoffsets displayorder commitlisted global rowlaidout rowoptim global idinlist rowchk rowrangelist idrowranges - global commitidx numcommits canvxmax canv + global numcommits canvxmax canv global nextcolor global parentlist childlist children - global colormap rowtextx commitrow + global colormap rowtextx global linesegends - set commitidx 0 set numcommits 0 set displayorder {} set commitlisted {} set parentlist {} set childlist {} set rowrangelist {} - catch {unset children} set nextcolor 0 set rowidlist {{}} set rowoffsets {{}} @@ -1570,7 +1680,6 @@ proc initlayout {} { set canvxmax [$canv cget -width] catch {unset colormap} catch {unset rowtextx} - catch {unset commitrow} catch {unset idrowranges} set linesegends {} } @@ -1605,10 +1714,10 @@ proc visiblerows {} { proc layoutmore {} { global rowlaidout rowoptim commitidx numcommits optim_delay - global uparrowlen + global uparrowlen curview set row $rowlaidout - set rowlaidout [layoutrows $row $commitidx 0] + set rowlaidout [layoutrows $row $commitidx($curview) 0] set orow [expr {$rowlaidout - $uparrowlen - 1}] if {$orow > $rowoptim} { optimize_rows $rowoptim 0 $orow @@ -1622,7 +1731,7 @@ proc layoutmore {} { proc showstuff {canshow} { global numcommits commitrow pending_select selectedline - global linesegends idrowranges idrangedrawn + global linesegends idrowranges idrangedrawn curview if {$numcommits == 0} { global phase @@ -1657,9 +1766,9 @@ proc showstuff {canshow} { incr row } if {[info exists pending_select] && - [info exists commitrow($pending_select)] && - $commitrow($pending_select) < $numcommits} { - selectline $commitrow($pending_select) 1 + [info exists commitrow($curview,$pending_select)] && + $commitrow($curview,$pending_select) < $numcommits} { + selectline $commitrow($curview,$pending_select) 1 } if {![info exists selectedline] && ![info exists pending_select]} { selectline 0 1 @@ -1671,7 +1780,7 @@ proc layoutrows {row endrow last} { global uparrowlen downarrowlen maxwidth mingaplen global childlist parentlist global idrowranges linesegends - global commitidx + global commitidx curview global idinlist rowchk rowrangelist set idlist [lindex $rowidlist $row] @@ -1691,7 +1800,8 @@ proc layoutrows {row endrow last} { set nev [expr {[llength $idlist] + [llength $newolds] + [llength $oldolds] - $maxwidth + 1}] if {$nev > 0} { - if {!$last && $row + $uparrowlen + $mingaplen >= $commitidx} break + if {!$last && + $row + $uparrowlen + $mingaplen >= $commitidx($curview)} break for {set x [llength $idlist]} {[incr x -1] >= 0} {} { set i [lindex $idlist $x] if {![info exists rowchk($i)] || $row >= $rowchk($i)} { @@ -1780,30 +1890,28 @@ proc layoutrows {row endrow last} { proc addextraid {id row} { global displayorder commitrow commitinfo global commitidx commitlisted - global parentlist childlist children + global parentlist childlist children curview - incr commitidx + incr commitidx($curview) lappend displayorder $id lappend commitlisted 0 lappend parentlist {} - set commitrow($id) $row + set commitrow($curview,$id) $row readcommit $id if {![info exists commitinfo($id)]} { set commitinfo($id) {"No commit information available"} } - if {[info exists children($id)]} { - lappend childlist $children($id) - unset children($id) - } else { - lappend childlist {} + if {![info exists children($curview,$id)]} { + set children($curview,$id) {} } + lappend childlist $children($curview,$id) } proc layouttail {} { - global rowidlist rowoffsets idinlist commitidx + global rowidlist rowoffsets idinlist commitidx curview global idrowranges rowrangelist - set row $commitidx + set row $commitidx($curview) set idlist [lindex $rowidlist $row] while {$idlist ne {}} { set col [expr {[llength $idlist] - 1}] @@ -1978,12 +2086,13 @@ proc linewidth {id} { } proc rowranges {id} { - global phase idrowranges commitrow rowlaidout rowrangelist + global phase idrowranges commitrow rowlaidout rowrangelist curview set ranges {} if {$phase eq {} || - ([info exists commitrow($id)] && $commitrow($id) < $rowlaidout)} { - set ranges [lindex $rowrangelist $commitrow($id)] + ([info exists commitrow($curview,$id)] + && $commitrow($curview,$id) < $rowlaidout)} { + set ranges [lindex $rowrangelist $commitrow($curview,$id)] } elseif {[info exists idrowranges($id)]} { set ranges $idrowranges($id) } @@ -1994,11 +2103,12 @@ proc drawlineseg {id i} { global rowoffsets rowidlist global displayorder global canv colormap linespc - global numcommits commitrow + global numcommits commitrow curview set ranges [rowranges $id] set downarrow 1 - if {[info exists commitrow($id)] && $commitrow($id) < $numcommits} { + if {[info exists commitrow($curview,$id)] + && $commitrow($curview,$id) < $numcommits} { set downarrow [expr {$i < [llength $ranges] / 2 - 1}] } else { set downarrow 1 @@ -2122,7 +2232,7 @@ proc drawparentlinks {id row col olds} { proc drawlines {id} { global colormap canv global idrangedrawn - global childlist iddrawn commitrow rowidlist + global children iddrawn commitrow rowidlist curview $canv delete lines.$id set nr [expr {[llength [rowranges $id]] / 2}] @@ -2131,9 +2241,9 @@ proc drawlines {id} { drawlineseg $id $i } } - foreach child [lindex $childlist $commitrow($id)] { + foreach child $children($curview,$id) { if {[info exists iddrawn($child)]} { - set row $commitrow($child) + set row $commitrow($curview,$child) set col [lsearch -exact [lindex $rowidlist $row] $child] if {$col >= 0} { drawparentlinks $child $row $col [list $id] @@ -2147,7 +2257,8 @@ proc drawcmittext {id row col rmx} { global commitlisted commitinfo rowidlist global rowtextx idpos idtags idheads idotherrefs global linehtag linentag linedtag - global mainfont namefont canvxmax + global mainfont canvxmax + global hlview commitrow highlightedrows set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}] set x [xc $row $col] @@ -2172,11 +2283,16 @@ proc drawcmittext {id row col rmx} { set name [lindex $commitinfo($id) 1] set date [lindex $commitinfo($id) 2] set date [formatdate $date] + set font $mainfont + if {[info exists hlview] && [info exists commitrow($hlview,$id)]} { + lappend font bold + lappend highlightedrows $row + } set linehtag($row) [$canv create text $xt $y -anchor w \ - -text $headline -font $mainfont ] + -text $headline -font $font] $canv bind $linehtag($row) "rowmenu %X %Y $id" set linentag($row) [$canv2 create text 3 $y -anchor w \ - -text $name -font $namefont] + -text $name -font $mainfont] set linedtag($row) [$canv3 create text 3 $y -anchor w \ -text $date -font $mainfont] set xr [expr {$xt + [font measure $mainfont $headline]}] @@ -2307,21 +2423,19 @@ proc findcrossings {id} { proc assigncolor {id} { global colormap colors nextcolor - global commitrow parentlist children childlist + global commitrow parentlist children children curview if {[info exists colormap($id)]} return set ncolors [llength $colors] - if {[info exists commitrow($id)]} { - set kids [lindex $childlist $commitrow($id)] - } elseif {[info exists children($id)]} { - set kids $children($id) + if {[info exists children($curview,$id)]} { + set kids $children($curview,$id) } else { set kids {} } if {[llength $kids] == 1} { set child [lindex $kids 0] if {[info exists colormap($child)] - && [llength [lindex $parentlist $commitrow($child)]] == 1} { + && [llength [lindex $parentlist $commitrow($curview,$child)]] == 1} { set colormap($id) $colormap($child) return } @@ -2349,7 +2463,7 @@ proc assigncolor {id} { && [lsearch -exact $badcolors $colormap($child)] < 0} { lappend badcolors $colormap($child) } - foreach p [lindex $parentlist $commitrow($child)] { + foreach p [lindex $parentlist $commitrow($curview,$child)] { if {[info exists colormap($p)] && [lsearch -exact $badcolors $colormap($p)] < 0} { lappend badcolors $colormap($p) @@ -2382,7 +2496,7 @@ proc bindline {t id} { proc drawtags {id x xt y1} { global idtags idheads idotherrefs global linespc lthickness - global canv mainfont commitrow rowtextx + global canv mainfont commitrow rowtextx curview set marks {} set ntags 0 @@ -2425,7 +2539,7 @@ proc drawtags {id x xt y1} { $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \ -width 1 -outline black -fill yellow -tags tag.$id] $canv bind $t <1> [list showtag $tag 1] - set rowtextx($commitrow($id)) [expr {$xr + $linespc}] + set rowtextx($commitrow($curview,$id)) [expr {$xr + $linespc}] } else { # draw a head or other ref if {[incr nheads -1] >= 0} { @@ -2467,21 +2581,17 @@ proc xcoord {i level ln} { } proc finishcommits {} { - global commitidx phase + global commitidx phase curview global canv mainfont ctext maincursor textcursor global findinprogress pending_select - if {$commitidx > 0} { + if {$commitidx($curview) > 0} { drawrest } else { $canv delete all $canv create text 3 3 -anchor nw -text "No commits selected" \ -font $mainfont -tags textitems } - if {![info exists findinprogress]} { - . config -cursor $maincursor - settextcursor $textcursor - } set phase {} catch {unset pending_select} } @@ -2497,18 +2607,38 @@ proc settextcursor {c} { set curtextcursor $c } +proc nowbusy {what} { + global isbusy + + if {[array names isbusy] eq {}} { + . config -cursor watch + settextcursor watch + } + set isbusy($what) 1 +} + +proc notbusy {what} { + global isbusy maincursor textcursor + + catch {unset isbusy($what)} + if {[array names isbusy] eq {}} { + . config -cursor $maincursor + settextcursor $textcursor + } +} + proc drawrest {} { global numcommits global startmsecs global canvy0 numcommits linespc - global rowlaidout commitidx + global rowlaidout commitidx curview global pending_select set row $rowlaidout - layoutrows $rowlaidout $commitidx 1 + layoutrows $rowlaidout $commitidx($curview) 1 layouttail - optimize_rows $row 0 $commitidx - showstuff $commitidx + optimize_rows $row 0 $commitidx($curview) + showstuff $commitidx($curview) if {[info exists pending_select]} { selectline 0 1 } @@ -2540,7 +2670,7 @@ proc findmatches {f} { proc dofind {} { global findtype findloc findstring markedmatches commitinfo global numcommits displayorder linehtag linentag linedtag - global mainfont namefont canv canv2 canv3 selectedline + global mainfont canv canv2 canv3 selectedline global matchinglines foundstring foundstrlen matchstring global commitdata @@ -2601,7 +2731,7 @@ proc dofind {} { markmatches $canv $l $f $linehtag($l) $matches $mainfont } elseif {$ty == "Author"} { drawcmitrow $l - markmatches $canv2 $l $f $linentag($l) $matches $namefont + markmatches $canv2 $l $f $linentag($l) $matches $mainfont } elseif {$ty == "Date"} { drawcmitrow $l markmatches $canv3 $l $f $linedtag($l) $matches $mainfont @@ -2699,13 +2829,8 @@ proc stopfindproc {{done 0}} { catch {close $findprocfile} unset findprocpid } - if {[info exists findinprogress]} { - unset findinprogress - if {$phase eq {}} { - . config -cursor $maincursor - settextcursor $textcursor - } - } + catch {unset findinprogress} + notbusy find } proc findpatches {} { @@ -2745,14 +2870,13 @@ proc findpatches {} { fconfigure $f -blocking 0 fileevent $f readable readfindproc set finddidsel 0 - . config -cursor watch - settextcursor watch + nowbusy find set findinprogress 1 } proc readfindproc {} { global findprocfile finddidsel - global commitrow matchinglines findinsertpos + global commitrow matchinglines findinsertpos curview set n [gets $findprocfile line] if {$n < 0} { @@ -2769,11 +2893,11 @@ proc readfindproc {} { stopfindproc return } - if {![info exists commitrow($id)]} { + if {![info exists commitrow($curview,$id)]} { puts stderr "spurious id: $id" return } - set l $commitrow($id) + set l $commitrow($curview,$id) insertmatch $l $id } @@ -2847,8 +2971,7 @@ proc findfiles {} { set finddidsel 0 set findinsertpos end set id [lindex $displayorder $l] - . config -cursor watch - settextcursor watch + nowbusy find set findinprogress 1 findcont update @@ -3018,7 +3141,7 @@ proc commit_descriptor {p} { # append some text to the ctext widget, and make any SHA1 ID # that we know about be a clickable link. proc appendwithlinks {text} { - global ctext commitrow linknum + global ctext commitrow linknum curview set start [$ctext index "end - 1c"] $ctext insert end $text @@ -3028,11 +3151,12 @@ proc appendwithlinks {text} { set s [lindex $l 0] set e [lindex $l 1] set linkid [string range $text $s $e] - if {![info exists commitrow($linkid)]} continue + if {![info exists commitrow($curview,$linkid)]} continue incr e $ctext tag add link "$start + $s c" "$start + $e c" $ctext tag add link$linknum "$start + $s c" "$start + $e c" - $ctext tag bind link$linknum <1> [list selectline $commitrow($linkid) 1] + $ctext tag bind link$linknum <1> \ + [list selectline $commitrow($curview,$linkid) 1] incr linknum } $ctext tag conf link -foreground blue -underline 1 @@ -3686,11 +3810,10 @@ proc redisplay {} { } proc incrfont {inc} { - global mainfont namefont textfont ctext canv phase + global mainfont textfont ctext canv phase global stopped entries unmarkmatches set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]] - set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]] set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]] setcoords $ctext conf -font $textfont @@ -3729,7 +3852,7 @@ proc sha1change {n1 n2 op} { proc gotocommit {} { global sha1string currentid commitrow tagids headids - global displayorder numcommits + global displayorder numcommits curview if {$sha1string == {} || ([info exists currentid] && $sha1string == $currentid)} return @@ -3755,8 +3878,8 @@ proc gotocommit {} { } } } - if {[info exists commitrow($id)]} { - selectline $commitrow($id) 1 + if {[info exists commitrow($curview,$id)]} { + selectline $commitrow($curview,$id) 1 return } if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} { @@ -3864,7 +3987,7 @@ proc arrowjump {id n y} { } proc lineclick {x y id isnew} { - global ctext commitinfo childlist commitrow canv thickerline + global ctext commitinfo children canv thickerline curview if {![info exists commitinfo($id)] && ![getcommit $id]} return unmarkmatches @@ -3903,7 +4026,7 @@ proc lineclick {x y id isnew} { $ctext insert end "\tAuthor:\t[lindex $info 1]\n" set date [formatdate [lindex $info 2]] $ctext insert end "\tDate:\t$date\n" - set kids [lindex $childlist $commitrow($id)] + set kids $children($curview,$id) if {$kids ne {}} { $ctext insert end "\nChildren:" set i 0 @@ -3934,9 +4057,9 @@ proc normalline {} { } proc selbyid {id} { - global commitrow - if {[info exists commitrow($id)]} { - selectline $commitrow($id) 1 + global commitrow curview + if {[info exists commitrow($curview,$id)]} { + selectline $commitrow($curview,$id) 1 } } @@ -3949,9 +4072,10 @@ proc mstime {} { } proc rowmenu {x y id} { - global rowctxmenu commitrow selectedline rowmenuid + global rowctxmenu commitrow selectedline rowmenuid curview - if {![info exists selectedline] || $commitrow($id) eq $selectedline} { + if {![info exists selectedline] + || $commitrow($curview,$id) eq $selectedline} { set state disabled } else { set state normal @@ -4151,14 +4275,15 @@ proc domktag {} { } proc redrawtags {id} { - global canv linehtag commitrow idpos selectedline + global canv linehtag commitrow idpos selectedline curview - if {![info exists commitrow($id)]} return - drawcmitrow $commitrow($id) + if {![info exists commitrow($curview,$id)]} return + drawcmitrow $commitrow($curview,$id) $canv delete tag.$id set xt [eval drawtags $id $idpos($id)] - $canv coords $linehtag($commitrow($id)) $xt [lindex $idpos($id) 2] - if {[info exists selectedline] && $selectedline == $commitrow($id)} { + $canv coords $linehtag($commitrow($curview,$id)) $xt [lindex $idpos($id) 2] + if {[info exists selectedline] + && $selectedline == $commitrow($curview,$id)} { selectline $selectedline 0 } } @@ -4674,8 +4799,6 @@ set colors {green red blue magenta darkgrey brown orange} catch {source ~/.gitk} -set namefont $mainfont - font create optionfont -family sans-serif -size -12 set revtreeargs {} @@ -4704,6 +4827,7 @@ set optim_delay 16 set nextviewnum 1 set curview 0 set selectedview 0 +set selectedhlview {} set viewfiles(0) {} set viewperm(0) 0 @@ -4733,10 +4857,9 @@ if {$cmdline_files ne {}} { set viewname(1) "Command line" set viewfiles(1) $cmdline_files set viewperm(1) 0 - .bar.view add radiobutton -label $viewname(1) -command {showview 1} \ - -variable selectedview -value 1 + addviewmenu 1 + .bar.view entryconf 1 -state normal .bar.view entryconf 2 -state normal - .bar.view entryconf 3 -state normal } if {[info exists permviews]} { @@ -4746,8 +4869,7 @@ if {[info exists permviews]} { set viewname($n) [lindex $v 0] set viewfiles($n) [lindex $v 1] set viewperm($n) 1 - .bar.view add radiobutton -label $viewname($n) \ - -command [list showview $n] -variable selectedview -value $n + addviewmenu $n } } getcommits -- cgit v1.2.1 From 468eb79ed453017151c1230057986a7a79264395 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 1 May 2006 23:05:39 -0700 Subject: builtin-count-objects: make it official. Remove the shell-script version, make the hardlink from the git binary, and update the documentation to describe a new option. Signed-off-by: Junio C Hamano --- Documentation/git-count-objects.txt | 12 +++++++++++- Makefile | 5 +++-- git-count-objects.sh | 31 ------------------------------- 3 files changed, 14 insertions(+), 34 deletions(-) delete mode 100755 git-count-objects.sh diff --git a/Documentation/git-count-objects.txt b/Documentation/git-count-objects.txt index 47216f488b..198ce77a8a 100644 --- a/Documentation/git-count-objects.txt +++ b/Documentation/git-count-objects.txt @@ -7,13 +7,23 @@ git-count-objects - Reports on unpacked objects SYNOPSIS -------- -'git-count-objects' +'git-count-objects' [-v] DESCRIPTION ----------- This counts the number of unpacked object files and disk space consumed by them, to help you decide when it is a good time to repack. + +OPTIONS +------- +-v:: + In addition to the number of loose objects and disk + space consumed, it reports the number of in-pack + objects, and number of objects that can be removed by + running `git-prune-packed`. + + Author ------ Written by Junio C Hamano diff --git a/Makefile b/Makefile index 14193aa1e2..f1592fb6ef 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__ SCRIPT_SH = \ git-add.sh git-bisect.sh git-branch.sh git-checkout.sh \ git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \ - git-count-objects.sh git-diff.sh git-fetch.sh \ + git-diff.sh git-fetch.sh \ git-format-patch.sh git-ls-remote.sh \ git-merge-one-file.sh git-parse-remote.sh \ git-prune.sh git-pull.sh git-push.sh git-rebase.sh \ @@ -167,7 +167,8 @@ PROGRAMS = \ git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \ git-describe$X git-merge-tree$X git-blame$X git-imap-send$X -BUILT_INS = git-log$X +BUILT_INS = git-log$X \ + git-count-objects$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) diff --git a/git-count-objects.sh b/git-count-objects.sh deleted file mode 100755 index 40c58efe08..0000000000 --- a/git-count-objects.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2005 Junio C Hamano -# - -GIT_DIR=`git-rev-parse --git-dir` || exit $? - -dc /dev/null || { - # This is not a real DC at all -- it just knows how - # this script feeds DC and does the computation itself. - dc () { - while read a b - do - case $a,$b in - 0,) acc=0 ;; - *,+) acc=$(($acc + $a)) ;; - p,) echo "$acc" ;; - esac - done - } -} - -echo $(find "$GIT_DIR/objects"/?? -type f -print 2>/dev/null | wc -l) objects, \ -$({ - echo 0 - # "no-such" is to help Darwin folks by not using xargs -r. - find "$GIT_DIR/objects"/?? -type f -print 2>/dev/null | - xargs du -k "$GIT_DIR/objects/no-such" 2>/dev/null | - sed -e 's/[ ].*/ +/' - echo p -} | dc) kilobytes -- cgit v1.2.1 From 8ab99476ec2298a43e94949e0bb7aa5125793a28 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 1 May 2006 22:58:18 -0700 Subject: builtin-diff: call it "git-diff", really. Call it "git diff" not "git diffn", remove the shell script version, and hardlink the git binary to it. Signed-off-by: Junio C Hamano --- Makefile | 5 +++-- git-diff.sh | 74 ------------------------------------------------------------- git.c | 2 +- 3 files changed, 4 insertions(+), 77 deletions(-) delete mode 100755 git-diff.sh diff --git a/Makefile b/Makefile index 277c1ac079..47b165e301 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__ SCRIPT_SH = \ git-add.sh git-bisect.sh git-branch.sh git-checkout.sh \ git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \ - git-count-objects.sh git-diff.sh git-fetch.sh \ + git-count-objects.sh git-fetch.sh \ git-format-patch.sh git-ls-remote.sh \ git-merge-one-file.sh git-parse-remote.sh \ git-prune.sh git-pull.sh git-push.sh git-rebase.sh \ @@ -167,7 +167,8 @@ PROGRAMS = \ git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \ git-describe$X git-merge-tree$X git-blame$X git-imap-send$X -BUILT_INS = git-log$X +BUILT_INS = git-log$X \ + git-diff$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) diff --git a/git-diff.sh b/git-diff.sh deleted file mode 100755 index 0fe6770749..0000000000 --- a/git-diff.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2005 Linus Torvalds -# Copyright (c) 2005 Junio C Hamano - -USAGE='[ --diff-options ] {0,2} [...]' -SUBDIRECTORY_OK='Yes' -. git-sh-setup - -rev=$(git-rev-parse --revs-only --no-flags --sq "$@") || exit -flags=$(git-rev-parse --no-revs --flags --sq "$@") -files=$(git-rev-parse --no-revs --no-flags --sq "$@") - -# I often say 'git diff --cached -p' and get scolded by git-diff-files, but -# obviously I mean 'git diff --cached -p HEAD' in that case. -case "$rev" in -'') - case " $flags " in - *" '--cached' "*) - rev='HEAD ' - ;; - esac -esac - -# If we have -[123] --ours --theirs --base, don't do --cc by default. -case " $flags " in -*" '-"[123]"' "* | *" '--ours' "* | *" '--base' "* | *" '--theirs' "*) - cc_or_p=-p ;; -*) - cc_or_p=--cc ;; -esac - -# If we do not have --name-status, --name-only, -r, -c or --stat, -# default to --cc. -case " $flags " in -*" '--name-status' "* | *" '--name-only' "* | *" '-r' "* | *" '-c' "* | \ -*" '--stat' "*) - ;; -*) - flags="$flags'$cc_or_p' " ;; -esac - -# If we do not have -B, -C, -r, nor -p, default to -M. -case " $flags " in -*" '-"[BCMrp]* | *" '--find-copies-harder' "*) - ;; # something like -M50. -*) - flags="$flags'-M' " ;; -esac - -case "$rev" in -?*' '?*' '?*) - usage - ;; -?*' '^?*) - begin=$(expr "$rev" : '.*^.\([0-9a-f]*\).*') && - end=$(expr "$rev" : '.\([0-9a-f]*\). .*') || exit - cmd="git-diff-tree $flags $begin $end -- $files" - ;; -?*' '?*) - cmd="git-diff-tree $flags $rev -- $files" - ;; -?*' ') - cmd="git-diff-index $flags $rev -- $files" - ;; -'') - cmd="git-diff-files $flags -- $files" - ;; -*) - usage - ;; -esac - -eval "$cmd" diff --git a/git.c b/git.c index ff9b87abbc..e6a960a965 100644 --- a/git.c +++ b/git.c @@ -46,7 +46,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "log", cmd_log }, { "whatchanged", cmd_whatchanged }, { "show", cmd_show }, - { "diffn", cmd_diff }, + { "diff", cmd_diff }, }; int i; -- cgit v1.2.1 From 7b763f7c6536f40090b06c79896a147ba97b0b03 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 1 May 2006 23:14:58 -0700 Subject: builtin-log/whatchanged/show: make them official. Remove the shell script version, and hardlink the git binary to them. Signed-off-by: Junio C Hamano --- Makefile | 9 +++------ git-whatchanged.sh | 28 ---------------------------- 2 files changed, 3 insertions(+), 34 deletions(-) delete mode 100755 git-whatchanged.sh diff --git a/Makefile b/Makefile index 8ce27a65fb..5d19820a09 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,7 @@ SCRIPT_SH = \ git-prune.sh git-pull.sh git-push.sh git-rebase.sh \ git-repack.sh git-request-pull.sh git-reset.sh \ git-resolve.sh git-revert.sh git-rm.sh git-sh-setup.sh \ - git-tag.sh git-verify-tag.sh git-whatchanged.sh \ + git-tag.sh git-verify-tag.sh \ git-applymbox.sh git-applypatch.sh git-am.sh \ git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \ git-merge-resolve.sh git-merge-ours.sh git-grep.sh \ @@ -139,7 +139,7 @@ SCRIPT_PYTHON = \ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \ $(patsubst %.perl,%,$(SCRIPT_PERL)) \ $(patsubst %.py,%,$(SCRIPT_PYTHON)) \ - git-cherry-pick git-show git-status + git-cherry-pick git-status # The ones that do not have to link with lcrypto, lz nor xdiff. SIMPLE_PROGRAMS = \ @@ -167,7 +167,7 @@ PROGRAMS = \ git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \ git-describe$X git-merge-tree$X git-blame$X git-imap-send$X -BUILT_INS = git-log$X +BUILT_INS = git-log$X git-whatchanged$X git-show$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) @@ -505,9 +505,6 @@ $(patsubst %.py,%,$(SCRIPT_PYTHON)) : % : %.py git-cherry-pick: git-revert cp $< $@ -git-show: git-whatchanged - cp $< $@ - git-status: git-commit cp $< $@ diff --git a/git-whatchanged.sh b/git-whatchanged.sh deleted file mode 100755 index 1fb9feb348..0000000000 --- a/git-whatchanged.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -USAGE='[-p] [--max-count=] [..] [--pretty=] [-m] [git-diff-tree options] [git-rev-list options]' -SUBDIRECTORY_OK='Yes' -. git-sh-setup - -diff_tree_flags=$(git-rev-parse --sq --no-revs --flags "$@") || exit -case "$0" in -*whatchanged) - count= - test -z "$diff_tree_flags" && - diff_tree_flags=$(git-repo-config --get whatchanged.difftree) - diff_tree_default_flags='-c -M --abbrev' ;; -*show) - count=-n1 - test -z "$diff_tree_flags" && - diff_tree_flags=$(git-repo-config --get show.difftree) - diff_tree_default_flags='--cc --always' ;; -esac -test -z "$diff_tree_flags" && - diff_tree_flags="$diff_tree_default_flags" - -rev_list_args=$(git-rev-parse --sq --default HEAD --revs-only "$@") && -diff_tree_args=$(git-rev-parse --sq --no-revs --no-flags "$@") && - -eval "git-rev-list $count $rev_list_args" | -eval "git-diff-tree --stdin --pretty -r $diff_tree_flags $diff_tree_args" | -LESS="$LESS -S" ${PAGER:-less} -- cgit v1.2.1 From c24fe420d3e2af6e5faabc6ab7f68c18f939582d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 1 May 2006 17:12:26 -0700 Subject: show-branch: omit uninteresting merges. Signed-off-by: Junio C Hamano --- show-branch.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/show-branch.c b/show-branch.c index 24efb65e62..268c57b180 100644 --- a/show-branch.c +++ b/show-branch.c @@ -5,7 +5,7 @@ #include "refs.h" static const char show_branch_usage[] = -"git-show-branch [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [...]"; +"git-show-branch [--dense] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [...]"; static int default_num = 0; static int default_alloc = 0; @@ -527,6 +527,27 @@ static int git_show_branch_config(const char *var, const char *value) return git_default_config(var, value); } +static int omit_in_dense(struct commit *commit, struct commit **rev, int n) +{ + /* If the commit is tip of the named branches, do not + * omit it. + * Otherwise, if it is a merge that is reachable from only one + * tip, it is not that interesting. + */ + int i, flag, count; + for (i = 0; i < n; i++) + if (rev[i] == commit) + return 0; + flag = commit->object.flags; + for (i = count = 0; i < n; i++) { + if (flag & (1u << (i + REV_SHIFT))) + count++; + } + if (count == 1) + return 1; + return 0; +} + int main(int ac, char **av) { struct commit *rev[MAX_REVS], *commit; @@ -548,6 +569,7 @@ int main(int ac, char **av) int with_current_branch = 0; int head_at = -1; int topics = 0; + int dense = 1; setup_git_directory(); git_config(git_show_branch_config); @@ -590,6 +612,8 @@ int main(int ac, char **av) lifo = 1; else if (!strcmp(arg, "--topics")) topics = 1; + else if (!strcmp(arg, "--sparse")) + dense = 0; else if (!strcmp(arg, "--date-order")) lifo = 0; else @@ -732,12 +756,15 @@ int main(int ac, char **av) shown_merge_point |= is_merge_point; if (1 < num_rev) { - int is_merge = !!(commit->parents && commit->parents->next); + int is_merge = !!(commit->parents && + commit->parents->next); if (topics && !is_merge_point && (this_flag & (1u << REV_SHIFT))) continue; - + if (dense && is_merge && + omit_in_dense(commit, rev, num_rev)) + continue; for (i = 0; i < num_rev; i++) { int mark; if (!(this_flag & (1u << (i + REV_SHIFT)))) -- cgit v1.2.1 From 54eb2d3ff91bf7a914b6e1de9cf8f748d6a9ecb4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 1 May 2006 23:40:37 -0700 Subject: builtin-push: make it official. Remove the shell script version, and hardlink the git binary to it. Signed-off-by: Junio C Hamano --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9919992392..9cb40a8163 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,7 @@ SCRIPT_SH = \ git-count-objects.sh git-diff.sh git-fetch.sh \ git-format-patch.sh git-ls-remote.sh \ git-merge-one-file.sh git-parse-remote.sh \ - git-prune.sh git-pull.sh git-push.sh git-rebase.sh \ + git-prune.sh git-pull.sh git-rebase.sh \ git-repack.sh git-request-pull.sh git-reset.sh \ git-resolve.sh git-revert.sh git-rm.sh git-sh-setup.sh \ git-tag.sh git-verify-tag.sh git-whatchanged.sh \ @@ -167,7 +167,8 @@ PROGRAMS = \ git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \ git-describe$X git-merge-tree$X git-blame$X git-imap-send$X -BUILT_INS = git-log$X +BUILT_INS = git-log$X \ + git-push$X # what 'all' will build and 'install' will install, in gitexecdir ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) -- cgit v1.2.1 From 97d4df0b29d262df291985aed486e226b43132d0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 30 Apr 2006 15:23:48 +0200 Subject: builtin-push: also ask config for remote information Now you can store your remote information in the config file like this: [remote.upstream] url = me@company.com:the-project push = master:iceballs [jc: fixed up to adjust a different fix for Push: lines earlier.] Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-push.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/builtin-push.c b/builtin-push.c index 9a861b5afe..06d06ff310 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -115,6 +115,41 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) return n; } +static const char **config_uri; +static const char *config_repo; +static int config_repo_len; +static int config_current_uri; +static int config_get_refspecs; + +static int get_remote_config(const char* key, const char* value) +{ + if (!strncmp(key, "remote.", 7) && + !strncmp(key + 7, config_repo, config_repo_len)) { + if (!strcmp(key + 7 + config_repo_len, ".url")) { + if (config_current_uri < MAX_URI) + config_uri[config_current_uri++] = strdup(value); + else + error("more than %d URL's specified, ignoring the rest", MAX_URI); + } + else if (config_get_refspecs && + !strcmp(key + 7 + config_repo_len, ".push")) + add_refspec(strdup(value)); + } + return 0; +} + +static int get_config_remotes_uri(const char *repo, const char *uri[MAX_URI]) +{ + config_repo_len = strlen(repo); + config_repo = repo; + config_current_uri = 0; + config_uri = uri; + config_get_refspecs = !refspec_nr; + + git_config(get_remote_config); + return config_current_uri; +} + static int get_branches_uri(const char *repo, const char *uri[MAX_URI]) { const char *slash = strchr(repo, '/'); @@ -162,6 +197,10 @@ static int read_config(const char *repo, const char *uri[MAX_URI]) if (n > 0) return n; + n = get_config_remotes_uri(repo, uri); + if (n > 0) + return n; + n = get_branches_uri(repo, uri); if (n > 0) return n; -- cgit v1.2.1 From 5a223a0d434c874984a0251eca4520ef95718a6d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 30 Apr 2006 15:24:03 +0200 Subject: fetch, pull: ask config for remote information Now you can say [remote.junio] url = git://git.kernel.org/pub/scm/git/git.git pull = next:next in your .git/config. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/git-parse-remote.sh b/git-parse-remote.sh index c9b899e3d7..8ce57c80fb 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -4,13 +4,43 @@ # this would fail in that case and would issue an error message. GIT_DIR=$(git-rev-parse --git-dir 2>/dev/null) || :; +if [ -d "$GIT_DIR"/remotes -a "$GIT_REWRITE_REMOTES" = true ]; then + echo "Rewriting $GIT_DIR/remotes" >&2 + error=0 + # rewrite into config + { + cd "$GIT_DIR"/remotes + ls | while read f; do + name=$(echo -n "$f" | tr -c "A-Za-z0-9" ".") + sed -n \ + -e "s/^URL: /remote.$name.url . /p" \ + -e "s/^Pull: /remote.$name.pull ^$ /p" \ + -e "s/^Push: /remote.$name.push ^$ /p" \ + < "$f" + done + echo done + } | while read key regex value; do + case $key in + done) + if [ $error = 0 ]; then + mv "$GIT_DIR"/remotes "$GIT_DIR"/remotes.old + fi ;; + *) + git-repo-config $key "$value" $regex || error=1 ;; + esac + done +fi + get_data_source () { case "$1" in */*) # Not so fast. This could be the partial URL shorthand... token=$(expr "z$1" : 'z\([^/]*\)/') remainder=$(expr "z$1" : 'z[^/]*/\(.*\)') - if test -f "$GIT_DIR/branches/$token" + if test "$(git-repo-config --get "remote.$token.url")" + then + echo config-partial + elif test -f "$GIT_DIR/branches/$token" then echo branches-partial else @@ -18,7 +48,10 @@ get_data_source () { fi ;; *) - if test -f "$GIT_DIR/remotes/$1" + if test "$(git-repo-config --get "remote.$1.url")" + then + echo config + elif test -f "$GIT_DIR/remotes/$1" then echo remotes elif test -f "$GIT_DIR/branches/$1" @@ -35,6 +68,15 @@ get_remote_url () { case "$data_source" in '') echo "$1" ;; + config-partial) + token=$(expr "z$1" : '\([^/]*\)/') + remainder=$(expr "z$1" : '[^/]*/\(.*\)') + url=$(git-repo-config --get "remote.$token.url") + echo "$url/$remainder" + ;; + config) + git-repo-config --get "remote.$1.url" + ;; remotes) sed -ne '/^URL: */{ s///p @@ -56,8 +98,10 @@ get_remote_url () { get_remote_default_refs_for_push () { data_source=$(get_data_source "$1") case "$data_source" in - '' | branches | branches-partial) + '' | config-partial | branches | branches-partial) ;; # no default push mapping, just send matching refs. + config) + git-repo-config --get-all "remote.$1.push" ;; remotes) sed -ne '/^Push: */{ s///p @@ -111,8 +155,11 @@ canon_refs_list_for_fetch () { get_remote_default_refs_for_fetch () { data_source=$(get_data_source "$1") case "$data_source" in - '' | branches-partial) + '' | config-partial | branches-partial) echo "HEAD:" ;; + config) + canon_refs_list_for_fetch \ + $(git-repo-config --get-all "remote.$1.pull") ;; branches) remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1") case "$remote_branch" in '') remote_branch=master ;; esac -- cgit v1.2.1 From 89b11d3ba5132e44cc04826c297a34e31788d0ab Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Tue, 2 May 2006 19:55:31 +1000 Subject: gitk: Fix file list display when files are renamed The conversion of the file list to use a text widget assumed incorrectly that the list of files from git-diff-tree -r would correspond 1-1 with the diff sections in the output of git-diff-tree -r -p -C, which is not true when renames are detected. This fixes it by keeping the elements in the difffilestart list in the order they appear in the file list window. Since this means that the elements of difffilestart are no longer necessarily in ascending order, it's somewhat hard to do the dynamic highlighting in the file list as the diff window is scrolled, so I have taken that out for now. Signed-off-by: Paul Mackerras --- gitk | 91 ++++++++++++++++++++++---------------------------------------------- 1 file changed, 29 insertions(+), 62 deletions(-) diff --git a/gitk b/gitk index a83a754858..28f8233dbc 100755 --- a/gitk +++ b/gitk @@ -512,7 +512,7 @@ proc makewindow {} { set ctext .ctop.cdet.left.ctext text $ctext -bg white -state disabled -font $textfont \ -width $geometry(ctextw) -height $geometry(ctexth) \ - -yscrollcommand scrolltext -wrap none + -yscrollcommand {.ctop.cdet.left.sb set} -wrap none scrollbar .ctop.cdet.left.sb -command "$ctext yview" pack .ctop.cdet.left.sb -side right -fill y pack $ctext -side left -fill both -expand 1 @@ -562,7 +562,8 @@ proc makewindow {} { scrollbar .ctop.cdet.right.sb -command "$cflist yview" pack .ctop.cdet.right.sb -side right -fill y pack $cflist -side left -fill both -expand 1 - $cflist tag configure highlight -background yellow + $cflist tag configure highlight \ + -background [$cflist cget -selectbackground] .ctop.cdet add .ctop.cdet.right bind .ctop.cdet {resizecdetpanes %W %w} @@ -1092,14 +1093,13 @@ image create bitmap tri-dn -background black -foreground blue -data { } proc init_flist {first} { - global cflist cflist_top cflist_bot selectedline difffilestart + global cflist cflist_top selectedline difffilestart $cflist conf -state normal $cflist delete 0.0 end if {$first ne {}} { $cflist insert end $first set cflist_top 1 - set cflist_bot 1 $cflist tag add highlight 1.0 "1.0 lineend" } else { catch {unset cflist_top} @@ -1126,61 +1126,14 @@ proc sel_flist {w x y} { if {$cmitmode eq "tree"} return if {![info exists cflist_top]} return set l [lindex [split [$w index "@$x,$y"] "."] 0] + $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend" + $cflist tag add highlight $l.0 "$l.0 lineend" + set cflist_top $l if {$l == 1} { $ctext yview 1.0 } else { catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]} } - highlight_flist $l -} - -proc scrolltext {f0 f1} { - global cflist_top - - .ctop.cdet.left.sb set $f0 $f1 - if {[info exists cflist_top]} { - highlight_flist $cflist_top - } -} - -# Given an index $tl in the $ctext window, this works out which line -# of the $cflist window displays the filename whose patch is shown -# at the given point in the $ctext window. $ll is a hint about which -# line it might be, and is used as the starting point of the search. -proc ctext_index {tl ll} { - global ctext difffilestart - - while {$ll >= 2 && [$ctext compare $tl < \ - [lindex $difffilestart [expr {$ll - 2}]]]} { - incr ll -1 - } - set nfiles [llength $difffilestart] - while {$ll - 1 < $nfiles && [$ctext compare $tl >= \ - [lindex $difffilestart [expr {$ll - 1}]]]} { - incr ll - } - return $ll -} - -proc highlight_flist {ll} { - global ctext cflist cflist_top cflist_bot difffilestart - - if {![info exists difffilestart] || [llength $difffilestart] == 0} return - set ll [ctext_index [$ctext index @0,1] $ll] - set lb $cflist_bot - if {$lb < $ll} { - set lb $ll - } - set y [expr {[winfo height $ctext] - 2}] - set lb [ctext_index [$ctext index @0,$y] $lb] - if {$ll != $cflist_top || $lb != $cflist_bot} { - $cflist tag remove highlight $cflist_top.0 "$cflist_bot.0 lineend" - for {set l $ll} {$l <= $lb} {incr l} { - $cflist tag add highlight $l.0 "$l.0 lineend" - } - set cflist_top $ll - set cflist_bot $lb - } } # Code to implement multiple views @@ -3561,8 +3514,6 @@ proc getmergediffline {mdf id np} { # start of a new file $ctext insert end "\n" set here [$ctext index "end - 1c"] - $ctext mark set f:$fname $here - $ctext mark gravity f:$fname left lappend difffilestart $here add_flist [list $fname] set l [expr {(78 - [string length $fname]) / 2}] @@ -3693,6 +3644,19 @@ proc getblobdiffs {ids} { set nextupdate [expr {[clock clicks -milliseconds] + 100}] } +proc setinlist {var i val} { + global $var + + while {[llength [set $var]] < $i} { + lappend $var {} + } + if {[llength [set $var]] == $i} { + lappend $var $val + } else { + lset $var $i $val + } +} + proc getblobdiffline {bdf ids} { global diffids blobdifffd ctext curdifftag curtagstart global diffnexthead diffnextnote difffilestart @@ -3719,12 +3683,15 @@ proc getblobdiffline {bdf ids} { set here [$ctext index "end - 1c"] set curtagstart $here set header $newname - lappend difffilestart $here - $ctext mark set f:$fname $here - $ctext mark gravity f:$fname left - if {$newname != $fname} { - $ctext mark set f:$newfname $here - $ctext mark gravity f:$newfname left + set i [lsearch -exact $treediffs($ids) $fname] + if {$i >= 0} { + setinlist difffilestart $i $here + } + if {$newname ne $fname} { + set i [lsearch -exact $treediffs($ids) $newname] + if {$i >= 0} { + setinlist difffilestart $i $here + } } set curdifftag "f:$fname" $ctext tag delete $curdifftag -- cgit v1.2.1 From c9889e40858fa8b9265b58519e7281c07f3632c6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 2 May 2006 14:16:46 -0700 Subject: Revert "fetch, pull: ask config for remote information" This reverts 5a223a0d434c874984a0251eca4520ef95718a6d commit. I asked Johannes to roll an updated version, so let's wait for it. --- git-parse-remote.sh | 55 ++++------------------------------------------------- 1 file changed, 4 insertions(+), 51 deletions(-) diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 8ce57c80fb..c9b899e3d7 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -4,43 +4,13 @@ # this would fail in that case and would issue an error message. GIT_DIR=$(git-rev-parse --git-dir 2>/dev/null) || :; -if [ -d "$GIT_DIR"/remotes -a "$GIT_REWRITE_REMOTES" = true ]; then - echo "Rewriting $GIT_DIR/remotes" >&2 - error=0 - # rewrite into config - { - cd "$GIT_DIR"/remotes - ls | while read f; do - name=$(echo -n "$f" | tr -c "A-Za-z0-9" ".") - sed -n \ - -e "s/^URL: /remote.$name.url . /p" \ - -e "s/^Pull: /remote.$name.pull ^$ /p" \ - -e "s/^Push: /remote.$name.push ^$ /p" \ - < "$f" - done - echo done - } | while read key regex value; do - case $key in - done) - if [ $error = 0 ]; then - mv "$GIT_DIR"/remotes "$GIT_DIR"/remotes.old - fi ;; - *) - git-repo-config $key "$value" $regex || error=1 ;; - esac - done -fi - get_data_source () { case "$1" in */*) # Not so fast. This could be the partial URL shorthand... token=$(expr "z$1" : 'z\([^/]*\)/') remainder=$(expr "z$1" : 'z[^/]*/\(.*\)') - if test "$(git-repo-config --get "remote.$token.url")" - then - echo config-partial - elif test -f "$GIT_DIR/branches/$token" + if test -f "$GIT_DIR/branches/$token" then echo branches-partial else @@ -48,10 +18,7 @@ get_data_source () { fi ;; *) - if test "$(git-repo-config --get "remote.$1.url")" - then - echo config - elif test -f "$GIT_DIR/remotes/$1" + if test -f "$GIT_DIR/remotes/$1" then echo remotes elif test -f "$GIT_DIR/branches/$1" @@ -68,15 +35,6 @@ get_remote_url () { case "$data_source" in '') echo "$1" ;; - config-partial) - token=$(expr "z$1" : '\([^/]*\)/') - remainder=$(expr "z$1" : '[^/]*/\(.*\)') - url=$(git-repo-config --get "remote.$token.url") - echo "$url/$remainder" - ;; - config) - git-repo-config --get "remote.$1.url" - ;; remotes) sed -ne '/^URL: */{ s///p @@ -98,10 +56,8 @@ get_remote_url () { get_remote_default_refs_for_push () { data_source=$(get_data_source "$1") case "$data_source" in - '' | config-partial | branches | branches-partial) + '' | branches | branches-partial) ;; # no default push mapping, just send matching refs. - config) - git-repo-config --get-all "remote.$1.push" ;; remotes) sed -ne '/^Push: */{ s///p @@ -155,11 +111,8 @@ canon_refs_list_for_fetch () { get_remote_default_refs_for_fetch () { data_source=$(get_data_source "$1") case "$data_source" in - '' | config-partial | branches-partial) + '' | branches-partial) echo "HEAD:" ;; - config) - canon_refs_list_for_fetch \ - $(git-repo-config --get-all "remote.$1.pull") ;; branches) remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1") case "$remote_branch" in '') remote_branch=master ;; esac -- cgit v1.2.1 From 098dd8a34b43ea1317527ca1a3354aae9f3704b5 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Wed, 3 May 2006 09:32:53 +1000 Subject: gitk: Allow view to specify arbitrary arguments to git-rev-list The list of arguments to git-rev-list, including arguments that select the range of commits, is now a part of the view specification. If any arguments are given to gitk, they become part of the "Command line" view, and the non-file arguments become the default for any new views created. Getting an error from git-rev-list is no longer fatal; instead the error window pops up, and when you press OK, the main window just shows "No commits selected". The git-rev-list arguments are entered in an entry widget in the view editor window using shell quoting conventions, not Tcl quoting conventions. Signed-off-by: Paul Mackerras --- gitk | 247 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 196 insertions(+), 51 deletions(-) diff --git a/gitk b/gitk index 28f8233dbc..4aa57c01ce 100755 --- a/gitk +++ b/gitk @@ -19,13 +19,13 @@ proc gitdir {} { proc start_rev_list {view} { global startmsecs nextupdate ncmupdate global commfd leftover tclencoding datemode - global revtreeargs viewfiles commitidx + global viewargs viewfiles commitidx set startmsecs [clock clicks -milliseconds] set nextupdate [expr {$startmsecs + 100}] set ncmupdate 1 set commitidx($view) 0 - set args $revtreeargs + set args $viewargs($view) if {$viewfiles($view) ne {}} { set args [concat $args "--" $viewfiles($view)] } @@ -69,9 +69,7 @@ proc getcommits {} { set phase getcommits initlayout start_rev_list $curview - $canv delete all - $canv create text 3 3 -anchor nw -text "Reading commits..." \ - -font $mainfont -tags textitems + show_status "Reading commits..." } proc getcommitlines {fd view} { @@ -84,26 +82,33 @@ proc getcommitlines {fd view} { set stuff [read $fd] if {$stuff == {}} { if {![eof $fd]} return + global viewname unset commfd($view) + notbusy $view # set it blocking so we wait for the process to terminate fconfigure $fd -blocking 1 - if {![catch {close $fd} err]} { - notbusy $view - if {$view == $curview} { - after idle finishcommits + if {[catch {close $fd} err]} { + set fv {} + if {$view != $curview} { + set fv " for the \"$viewname($view)\" view" } - return + if {[string range $err 0 4] == "usage"} { + set err "Gitk: error reading commits$fv:\ + bad arguments to git-rev-list." + if {$viewname($view) eq "Command line"} { + append err \ + " (Note: arguments to gitk are passed to git-rev-list\ + to allow selection of commits to be displayed.)" + } + } else { + set err "Error reading commits$fv: $err" + } + error_popup $err } - if {[string range $err 0 4] == "usage"} { - set err \ - "Gitk: error reading commits: bad arguments to git-rev-list.\ - (Note: arguments to gitk are passed to git-rev-list\ - to allow selection of commits to be displayed.)" - } else { - set err "Error reading commits: $err" + if {$view == $curview} { + after idle finishcommits } - error_popup $err - exit 1 + return } set start 0 set gotsome 0 @@ -217,7 +222,7 @@ proc readcommit {id} { } proc updatecommits {} { - global viewdata curview revtreeargs phase displayorder + global viewdata curview phase displayorder global children commitrow if {$phase ne {}} { @@ -352,10 +357,7 @@ proc readrefs {} { close $refd } -proc error_popup msg { - set w .error - toplevel $w - wm transient $w . +proc show_error {w msg} { message $w.m -text $msg -justify center -aspect 400 pack $w.m -side top -fill x -padx 20 -pady 20 button $w.ok -text OK -command "destroy $w" @@ -365,6 +367,13 @@ proc error_popup msg { tkwait window $w } +proc error_popup msg { + set w .error + toplevel $w + wm transient $w . + show_error $w $msg +} + proc makewindow {} { global canv canv2 canv3 linespc charspc ctext cflist global textfont mainfont uifont @@ -686,7 +695,7 @@ proc savestuff {w} { global canv canv2 canv3 ctext cflist mainfont textfont uifont global stuffsaved findmergefiles maxgraphpct global maxwidth - global viewname viewfiles viewperm nextviewnum + global viewname viewfiles viewargs viewperm nextviewnum global cmitmode if {$stuffsaved} return @@ -715,7 +724,7 @@ proc savestuff {w} { puts -nonewline $f "set permviews {" for {set v 0} {$v < $nextviewnum} {incr v} { if {$viewperm($v)} { - puts $f "{[list $viewname($v) $viewfiles($v)]}" + puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v)]}" } } puts $f "}" @@ -1136,10 +1145,105 @@ proc sel_flist {w x y} { } } +# Functions for adding and removing shell-type quoting + +proc shellquote {str} { + if {![string match "*\['\"\\ \t]*" $str]} { + return $str + } + if {![string match "*\['\"\\]*" $str]} { + return "\"$str\"" + } + if {![string match "*'*" $str]} { + return "'$str'" + } + return "\"[string map {\" \\\" \\ \\\\} $str]\"" +} + +proc shellarglist {l} { + set str {} + foreach a $l { + if {$str ne {}} { + append str " " + } + append str [shellquote $a] + } + return $str +} + +proc shelldequote {str} { + set ret {} + set used -1 + while {1} { + incr used + if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} { + append ret [string range $str $used end] + set used [string length $str] + break + } + set first [lindex $first 0] + set ch [string index $str $first] + if {$first > $used} { + append ret [string range $str $used [expr {$first - 1}]] + set used $first + } + if {$ch eq " " || $ch eq "\t"} break + incr used + if {$ch eq "'"} { + set first [string first "'" $str $used] + if {$first < 0} { + error "unmatched single-quote" + } + append ret [string range $str $used [expr {$first - 1}]] + set used $first + continue + } + if {$ch eq "\\"} { + if {$used >= [string length $str]} { + error "trailing backslash" + } + append ret [string index $str $used] + continue + } + # here ch == "\"" + while {1} { + if {![regexp -start $used -indices "\[\"\\\\]" $str first]} { + error "unmatched double-quote" + } + set first [lindex $first 0] + set ch [string index $str $first] + if {$first > $used} { + append ret [string range $str $used [expr {$first - 1}]] + set used $first + } + if {$ch eq "\""} break + incr used + append ret [string index $str $used] + incr used + } + } + return [list $used $ret] +} + +proc shellsplit {str} { + set l {} + while {1} { + set str [string trimleft $str] + if {$str eq {}} break + set dq [shelldequote $str] + set n [lindex $dq 0] + set word [lindex $dq 1] + set str [string range $str $n end] + lappend l $word + } + return $l +} + # Code to implement multiple views proc newview {ishighlight} { global nextviewnum newviewname newviewperm uifont newishighlight + global newviewargs revtreeargs set newishighlight $ishighlight set top .gitkview @@ -1149,12 +1253,14 @@ proc newview {ishighlight} { } set newviewname($nextviewnum) "View $nextviewnum" set newviewperm($nextviewnum) 0 + set newviewargs($nextviewnum) [shellarglist $revtreeargs] vieweditor $top $nextviewnum "Gitk view definition" } proc editview {} { global curview global viewname viewperm newviewname newviewperm + global viewargs newviewargs set top .gitkvedit-$curview if {[winfo exists $top]} { @@ -1163,6 +1269,7 @@ proc editview {} { } set newviewname($curview) $viewname($curview) set newviewperm($curview) $viewperm($curview) + set newviewargs($curview) [shellarglist $viewargs($curview)] vieweditor $top $curview "Gitk: edit view $viewname($curview)" } @@ -1177,7 +1284,13 @@ proc vieweditor {top n title} { grid $top.nl $top.name -sticky w -pady 5 checkbutton $top.perm -text "Remember this view" -variable newviewperm($n) grid $top.perm - -pady 5 -sticky w - message $top.l -aspect 500 -font $uifont \ + message $top.al -aspect 1000 -font $uifont \ + -text "Commits to include (arguments to git-rev-list):" + grid $top.al - -sticky w -pady 5 + entry $top.args -width 50 -textvariable newviewargs($n) \ + -background white + grid $top.args - -sticky ew -padx 5 + message $top.l -aspect 1000 -font $uifont \ -text "Enter files and directories to include, one per line:" grid $top.l - -sticky w text $top.t -width 40 -height 10 -background white @@ -1189,7 +1302,7 @@ proc vieweditor {top n title} { $top.t delete {end - 1c} end $top.t mark set insert 0.0 } - grid $top.t - -sticky w -padx 5 + grid $top.t - -sticky ew -padx 5 frame $top.buts button $top.buts.ok -text "OK" -command [list newviewok $top $n] button $top.buts.can -text "Cancel" -command [list destroy $top] @@ -1211,14 +1324,23 @@ proc doviewmenu {m first cmd op args} { } proc allviewmenus {n op args} { - doviewmenu .bar.view 6 [list showview $n] $op $args + doviewmenu .bar.view 7 [list showview $n] $op $args doviewmenu .bar.view.hl 3 [list addhighlight $n] $op $args } proc newviewok {top n} { global nextviewnum newviewperm newviewname newishighlight global viewname viewfiles viewperm selectedview curview + global viewargs newviewargs + if {[catch { + set newargs [shellsplit $newviewargs($n)] + } err]} { + error_popup "Error in commit selection arguments: $err" + wm raise $top + focus $top + return + } set files {} foreach f [split [$top.t get 0.0 end] "\n"] { set ft [string trim $f] @@ -1232,6 +1354,7 @@ proc newviewok {top n} { set viewname($n) $newviewname($n) set viewperm($n) $newviewperm($n) set viewfiles($n) $files + set viewargs($n) $newargs addviewmenu $n if {!$newishighlight} { after idle showview $n @@ -1245,8 +1368,9 @@ proc newviewok {top n} { set viewname($n) $newviewname($n) allviewmenus $n entryconf -label $viewname($n) } - if {$files ne $viewfiles($n)} { + if {$files ne $viewfiles($n) || $newargs ne $viewargs($n)} { set viewfiles($n) $files + set viewargs($n) $newargs if {$curview == $n} { after idle updatecommits } @@ -1347,8 +1471,8 @@ proc showview {n} { set curview $n set selectedview $n set selectedhlview -1 - .bar.view entryconf 1 -state [expr {$n == 0? "disabled": "normal"}] .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}] + .bar.view entryconf 3 -state [expr {$n == 0? "disabled": "normal"}] catch {unset hlview} .bar.view.hl entryconf 1 -state disabled @@ -1403,15 +1527,15 @@ proc showview {n} { selectline $row 0 if {$phase ne {}} { if {$phase eq "getcommits"} { - global mainfont - $canv create text 3 3 -anchor nw -text "Reading commits..." \ - -font $mainfont -tags textitems + show_status "Reading commits..." } if {[info exists commfd($n)]} { layoutmore } else { finishcommits } + } elseif {$numcommits == 0} { + show_status "No commits selected" } } @@ -2533,6 +2657,13 @@ proc xcoord {i level ln} { return $x } +proc show_status {msg} { + global canv mainfont + + clear_display + $canv create text 3 3 -anchor nw -text $msg -font $mainfont -tags textitems +} + proc finishcommits {} { global commitidx phase curview global canv mainfont ctext maincursor textcursor @@ -2541,9 +2672,7 @@ proc finishcommits {} { if {$commitidx($curview) > 0} { drawrest } else { - $canv delete all - $canv create text 3 3 -anchor nw -text "No commits selected" \ - -font $mainfont -tags textitems + show_status "No commits selected" } set phase {} catch {unset pending_select} @@ -4782,10 +4911,33 @@ foreach arg $argv { # check that we can find a .git directory somewhere... set gitdir [gitdir] if {![file isdirectory $gitdir]} { - error_popup "Cannot find the git directory \"$gitdir\"." + show_error . "Cannot find the git directory \"$gitdir\"." exit 1 } +set cmdline_files {} +set i [lsearch -exact $revtreeargs "--"] +if {$i >= 0} { + set cmdline_files [lrange $revtreeargs [expr {$i + 1}] end] + set revtreeargs [lrange $revtreeargs 0 [expr {$i - 1}]] +} elseif {$revtreeargs ne {}} { + if {[catch { + set f [eval exec git-rev-parse --no-revs --no-flags $revtreeargs] + set cmdline_files [split $f "\n"] + set n [llength $cmdline_files] + set revtreeargs [lrange $revtreeargs 0 end-$n] + } err]} { + # unfortunately we get both stdout and stderr in $err, + # so look for "fatal:". + set i [string first "fatal:" $err] + if {$i > 0} { + set err [string range [expr {$i + 6}] end] + } + show_error . "Bad arguments to gitk:\n$err" + exit 1 + } +} + set history {} set historyindex 0 @@ -4797,7 +4949,9 @@ set selectedview 0 set selectedhlview {} set viewfiles(0) {} set viewperm(0) 0 +set viewargs(0) {} +set cmdlineok 0 set stopped 0 set stuffsaved 0 set patchnum 0 @@ -4805,28 +4959,18 @@ setcoords makewindow readrefs -set cmdline_files {} -catch { - set fileargs [eval exec git-rev-parse --no-revs --no-flags $revtreeargs] - set cmdline_files [split $fileargs "\n"] - set n [llength $cmdline_files] - set revtreeargs [lrange $revtreeargs 0 end-$n] -} -if {[lindex $revtreeargs end] eq "--"} { - set revtreeargs [lrange $revtreeargs 0 end-1] -} - -if {$cmdline_files ne {}} { +if {$cmdline_files ne {} || $revtreeargs ne {}} { # create a view for the files/dirs specified on the command line set curview 1 set selectedview 1 set nextviewnum 2 set viewname(1) "Command line" set viewfiles(1) $cmdline_files + set viewargs(1) $revtreeargs set viewperm(1) 0 addviewmenu 1 - .bar.view entryconf 1 -state normal .bar.view entryconf 2 -state normal + .bar.view entryconf 3 -state normal } if {[info exists permviews]} { @@ -4835,6 +4979,7 @@ if {[info exists permviews]} { incr nextviewnum set viewname($n) [lindex $v 0] set viewfiles($n) [lindex $v 1] + set viewargs($n) [lindex $v 2] set viewperm($n) 1 addviewmenu $n } -- cgit v1.2.1 From 2fa9a0fb31cbf01e8318a02c3e222d7fd3fd0a83 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 2 May 2006 14:22:48 +0200 Subject: repo-config: support --get-regexp With --get-regexp, output all key/value pairs where the key matches a regexp. Example: git-repo-config --get-regexp remote.*.url will output something like remote.junio.url git://git.kernel.org/pub/scm/git/git.git remote.gitk.url git://git.kernel.org/pub/scm/gitk/gitk.git Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-repo-config.txt | 5 ++++- repo-config.c | 40 ++++++++++++++++++++++++++++++++------- t/t1300-repo-config.sh | 23 ++++++++++++++++++++++ 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt index 566cfa1836..ddcf52364c 100644 --- a/Documentation/git-repo-config.txt +++ b/Documentation/git-repo-config.txt @@ -49,7 +49,7 @@ OPTIONS --replace-all:: Default behaviour is to replace at most one line. This replaces - all lines matching the key (and optionally the value_regex) + all lines matching the key (and optionally the value_regex). --get:: Get the value for a given key (optionally filtered by a regex @@ -59,6 +59,9 @@ OPTIONS Like get, but does not fail if the number of values for the key is not exactly one. +--get-regexp:: + Like --get-all, but interprets the name as a regular expression. + --unset:: Remove the line matching the key from .git/config. diff --git a/repo-config.c b/repo-config.c index e35063034f..722153c946 100644 --- a/repo-config.c +++ b/repo-config.c @@ -6,7 +6,10 @@ static const char git_config_set_usage[] = static char* key = NULL; static char* value = NULL; +static regex_t* key_regexp = NULL; static regex_t* regexp = NULL; +static int show_keys = 0; +static int use_key_regexp = 0; static int do_all = 0; static int do_not_match = 0; static int seen = 0; @@ -26,16 +29,18 @@ static int show_config(const char* key_, const char* value_) if (value_ == NULL) value_ = ""; - if (!strcmp(key_, key) && + if ((use_key_regexp || !strcmp(key_, key)) && + (!use_key_regexp || + !regexec(key_regexp, key_, 0, NULL, 0)) && (regexp == NULL || (do_not_match ^ !regexec(regexp, value_, 0, NULL, 0)))) { - if (do_all) { - printf("%s\n", value_); - return 0; - } + if (show_keys) + printf("%s ", key_); if (seen > 0) { - fprintf(stderr, "More than one value: %s\n", value); + if (!do_all) + fprintf(stderr, "More than one value: %s\n", + value); free(value); } @@ -50,6 +55,8 @@ static int show_config(const char* key_, const char* value_) value = strdup(value_); } seen++; + if (do_all) + printf("%s\n", value); } return 0; } @@ -63,6 +70,14 @@ static int get_value(const char* key_, const char* regex_) key[i] = tolower(key_[i]); key[i] = 0; + if (use_key_regexp) { + key_regexp = (regex_t*)malloc(sizeof(regex_t)); + if (regcomp(key_regexp, key, REG_EXTENDED)) { + fprintf(stderr, "Invalid key pattern: %s\n", regex_); + return -1; + } + } + if (regex_) { if (regex_[0] == '!') { do_not_match = 1; @@ -78,7 +93,8 @@ static int get_value(const char* key_, const char* regex_) git_config(show_config); if (value) { - printf("%s\n", value); + if (!do_all) + printf("%s\n", value); free(value); } free(key); @@ -123,6 +139,11 @@ int main(int argc, const char **argv) else if (!strcmp(argv[1], "--get-all")) { do_all = 1; return get_value(argv[2], NULL); + } else if (!strcmp(argv[1], "--get-regexp")) { + show_keys = 1; + use_key_regexp = 1; + do_all = 1; + return get_value(argv[2], NULL); } else return git_config_set(argv[1], argv[2]); @@ -136,6 +157,11 @@ int main(int argc, const char **argv) else if (!strcmp(argv[1], "--get-all")) { do_all = 1; return get_value(argv[2], argv[3]); + } else if (!strcmp(argv[1], "--get-regexp")) { + show_keys = 1; + use_key_regexp = 1; + do_all = 1; + return get_value(argv[2], argv[3]); } else if (!strcmp(argv[1], "--replace-all")) return git_config_set_multivar(argv[2], argv[3], NULL, 1); diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index ab4dd5c4ce..1bf728fb06 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -247,6 +247,24 @@ EOF test_expect_success 'hierarchical section value' 'cmp .git/config expect' +cat > expect << EOF +beta.noindent=sillyValue +nextsection.nonewline=wow2 for me +123456.a123=987 +1.2.3.alpha=beta +EOF + +test_expect_success 'working --list' \ + 'git-repo-config --list > output && cmp output expect' + +cat > expect << EOF +beta.noindent sillyValue +nextsection.nonewline wow2 for me +EOF + +test_expect_success '--get-regexp' \ + 'git-repo-config --get-regexp in > output && cmp output expect' + cat > .git/config << EOF [novalue] variable @@ -255,5 +273,10 @@ EOF test_expect_success 'get variable with no value' \ 'git-repo-config --get novalue.variable ^$' +git-repo-config > output 2>&1 + +test_expect_success 'no arguments, but no crash' \ + "test $? = 129 && grep usage output" + test_done -- cgit v1.2.1 From 9f0bb90d161edf8c43f5261d12bf83f14eb02ff4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 2 May 2006 00:40:24 -0700 Subject: core.prefersymlinkrefs: use symlinks for .git/HEAD When inspecting a project whose build infrastructure used to assume that .git/HEAD is a symlink ref, core.prefersymlinkrefs in the config file of such a project would help to bisect its history. Signed-off-by: Junio C Hamano --- Documentation/config.txt | 8 +++++--- Makefile | 8 ++++++-- cache.h | 2 +- config.c | 4 ++-- environment.c | 2 +- refs.c | 4 ++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index b27b0d5c06..d1a4bec0d4 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -64,9 +64,11 @@ core.ignoreStat:: slow, such as Microsoft Windows. See gitlink:git-update-index[1]. False by default. -core.onlyUseSymrefs:: - Always use the "symref" format instead of symbolic links for HEAD - and other symbolic reference files. True by default. +core.preferSymlinkRefs:: + Instead of the default "symref" format for HEAD + and other symbolic reference files, use symbolic links. + This is sometimes needed to work with old scripts that + expect HEAD to be a symbolic link. core.repositoryFormatVersion:: Internal variable identifying the repository format and layout diff --git a/Makefile b/Makefile index 8ce27a65fb..cb6bb72399 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,8 @@ all: # # Define NO_SETENV if you don't have setenv in the C library. # -# Define USE_SYMLINK_HEAD if you want .git/HEAD to be a symbolic link. -# Don't enable it on Windows. +# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link. +# Enable it on Windows. By default, symrefs are still used. # # Define PPC_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for PowerPC. @@ -263,6 +263,7 @@ ifeq ($(uname_O),Cygwin) NO_D_TYPE_IN_DIRENT = YesPlease NO_D_INO_IN_DIRENT = YesPlease NO_STRCASESTR = YesPlease + NO_SYMLINK_HEAD = YesPlease NEEDS_LIBICONV = YesPlease # There are conflicting reports about this. # On some boxes NO_MMAP is needed, and not so elsewhere. @@ -386,6 +387,9 @@ endif ifdef NO_D_INO_IN_DIRENT ALL_CFLAGS += -DNO_D_INO_IN_DIRENT endif +ifdef NO_SYMLINK_HEAD + ALL_CFLAGS += -DNO_SYMLINK_HEAD +endif ifdef NO_STRCASESTR COMPAT_CFLAGS += -DNO_STRCASESTR COMPAT_OBJS += compat/strcasestr.o diff --git a/cache.h b/cache.h index a4f253ec25..9d0ddcff01 100644 --- a/cache.h +++ b/cache.h @@ -169,7 +169,7 @@ extern void rollback_index_file(struct cache_file *); /* Environment bits from configuration mechanism */ extern int trust_executable_bit; extern int assume_unchanged; -extern int only_use_symrefs; +extern int prefer_symlink_refs; extern int warn_ambiguous_refs; extern int diff_rename_limit_default; extern int shared_repository; diff --git a/config.c b/config.c index 253c48a613..47734140dd 100644 --- a/config.c +++ b/config.c @@ -227,8 +227,8 @@ int git_default_config(const char *var, const char *value) return 0; } - if (!strcmp(var, "core.symrefsonly")) { - only_use_symrefs = git_config_bool(var, value); + if (!strcmp(var, "core.prefersymlinkrefs")) { + prefer_symlink_refs = git_config_bool(var, value); return 0; } diff --git a/environment.c b/environment.c index 6df647862c..444c99ed6e 100644 --- a/environment.c +++ b/environment.c @@ -13,7 +13,7 @@ char git_default_email[MAX_GITNAME]; char git_default_name[MAX_GITNAME]; int trust_executable_bit = 1; int assume_unchanged = 0; -int only_use_symrefs = 0; +int prefer_symlink_refs = 0; int warn_ambiguous_refs = 1; int repository_format_version = 0; char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8"; diff --git a/refs.c b/refs.c index 03398ccc53..275b914b2b 100644 --- a/refs.c +++ b/refs.c @@ -76,8 +76,8 @@ int create_symref(const char *git_HEAD, const char *refs_heads_master) char ref[1000]; int fd, len, written; -#ifdef USE_SYMLINK_HEAD - if (!only_use_symrefs) { +#ifndef NO_SYMLINK_HEAD + if (prefer_symlink_refs) { unlink(git_HEAD); if (!symlink(refs_heads_master, git_HEAD)) return 0; -- cgit v1.2.1 From e098c6f82a28efe1488c7eb1bed4e92f76dd2afd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 2 May 2006 21:06:56 -0700 Subject: repo-config: readability fixups. Signed-off-by: Junio C Hamano --- repo-config.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/repo-config.c b/repo-config.c index 722153c946..7e06d1a041 100644 --- a/repo-config.c +++ b/repo-config.c @@ -2,10 +2,9 @@ #include static const char git_config_set_usage[] = -"git-repo-config [ --bool | --int ] [--get | --get-all | --replace-all | --unset | --unset-all] name [value [value_regex]] | --list"; +"git-repo-config [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --unset | --unset-all] name [value [value_regex]] | --list"; static char* key = NULL; -static char* value = NULL; static regex_t* key_regexp = NULL; static regex_t* regexp = NULL; static int show_keys = 0; @@ -26,6 +25,9 @@ static int show_all_config(const char *key_, const char *value_) static int show_config(const char* key_, const char* value_) { + char value[256]; + const char *vptr = value; + if (value_ == NULL) value_ = ""; @@ -35,28 +37,25 @@ static int show_config(const char* key_, const char* value_) (regexp == NULL || (do_not_match ^ !regexec(regexp, value_, 0, NULL, 0)))) { + int dup_error = 0; if (show_keys) printf("%s ", key_); - if (seen > 0) { - if (!do_all) - fprintf(stderr, "More than one value: %s\n", - value); - free(value); - } - - if (type == T_INT) { - value = malloc(256); + if (seen && !do_all) + dup_error = 1; + if (type == T_INT) sprintf(value, "%d", git_config_int(key_, value_)); - } else if (type == T_BOOL) { - value = malloc(256); + else if (type == T_BOOL) sprintf(value, "%s", git_config_bool(key_, value_) ? "true" : "false"); - } else { - value = strdup(value_); - } + else + vptr = value_; seen++; - if (do_all) - printf("%s\n", value); + if (dup_error) { + error("More than one value for the key %s: %s", + key_, vptr); + } + else + printf("%s\n", vptr); } return 0; } @@ -73,7 +72,7 @@ static int get_value(const char* key_, const char* regex_) if (use_key_regexp) { key_regexp = (regex_t*)malloc(sizeof(regex_t)); if (regcomp(key_regexp, key, REG_EXTENDED)) { - fprintf(stderr, "Invalid key pattern: %s\n", regex_); + fprintf(stderr, "Invalid key pattern: %s\n", key_); return -1; } } @@ -92,11 +91,6 @@ static int get_value(const char* key_, const char* regex_) } git_config(show_config); - if (value) { - if (!do_all) - printf("%s\n", value); - free(value); - } free(key); if (regexp) { regfree(regexp); @@ -104,9 +98,9 @@ static int get_value(const char* key_, const char* regex_) } if (do_all) - return 0; + return !seen; - return seen == 1 ? 0 : 1; + return (seen == 1) ? 0 : 1; } int main(int argc, const char **argv) -- cgit v1.2.1 From 80fe7d2b54b1aebde6c067694cdbf3ba40ad0c39 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 2 May 2006 23:03:15 -0700 Subject: builtin-count-objects: open packs when running -v Otherwise we would report absolutely no objects in a fully packed repository. Signed-off-by: Junio C Hamano --- builtin-count.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin-count.c b/builtin-count.c index 0256369d5b..5ee72df247 100644 --- a/builtin-count.c +++ b/builtin-count.c @@ -105,6 +105,8 @@ int cmd_count_objects(int ac, const char **av, char **ep) } if (verbose) { struct packed_git *p; + if (!packed_git) + prepare_packed_git(); for (p = packed_git; p; p = p->next) { if (!p->pack_local) continue; -- cgit v1.2.1 From de5f2bf3612a43af074a98fd1fcdef6a403daf3f Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 3 May 2006 12:51:40 +0200 Subject: fix various typos in documentation Signed-off-by: Matthias Kestenholz Signed-off-by: Junio C Hamano --- Documentation/git-diff-tree.txt | 2 +- Documentation/git-update-index.txt | 4 ++-- revision.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt index 2169169850..906830d4bf 100644 --- a/Documentation/git-diff-tree.txt +++ b/Documentation/git-diff-tree.txt @@ -92,7 +92,7 @@ separated with a single space are given. Furthermore, it lists only files which were modified from all parents. --cc:: +--cc:: This flag changes the way a merge commit patch is displayed, in a similar way to the '-c' option. It implies the '-c' and '-p' options and further compresses the patch output diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index d4137fc87e..e01b42f445 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -10,8 +10,8 @@ SYNOPSIS -------- [verse] 'git-update-index' - [--add] [--remove | --force-remove] [--replace] - [--refresh [-q] [--unmerged] [--ignore-missing]] + [--add] [--remove | --force-remove] [--replace] + [--refresh] [-q] [--unmerged] [--ignore-missing] [--cacheinfo ]\* [--chmod=(+|-)x] [--assume-unchanged | --no-assume-unchanged] diff --git a/revision.c b/revision.c index 03dd238939..5f2f0be382 100644 --- a/revision.c +++ b/revision.c @@ -537,7 +537,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch revs->max_count = atoi(arg + 12); continue; } - /* accept -, like traditilnal "head" */ + /* accept -, like traditional "head" */ if ((*arg == '-') && isdigit(arg[1])) { revs->max_count = atoi(arg + 1); continue; -- cgit v1.2.1 From 060729dd7e4e7d366f09d2e13d796f05ec1734a9 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 3 May 2006 12:53:19 +0200 Subject: add documentation for update-index --unresolve Signed-off-by: Matthias Kestenholz Signed-off-by: Junio C Hamano --- Documentation/git-update-index.txt | 6 +++++- update-index.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index d4137fc87e..4bdb2b0ffa 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -15,7 +15,7 @@ SYNOPSIS [--cacheinfo ]\* [--chmod=(+|-)x] [--assume-unchanged | --no-assume-unchanged] - [--really-refresh] + [--really-refresh] [--unresolve] [--info-only] [--index-info] [-z] [--stdin] [--verbose] @@ -80,6 +80,10 @@ OPTIONS filesystem that has very slow lstat(2) system call (e.g. cifs). +--unresolve:: + Restores the 'unmerged' or 'needs updating' state of a + file during a merge if it was cleared by accident. + --info-only:: Do not create objects in the object database for all arguments that follow this flag; just insert diff --git a/update-index.c b/update-index.c index facec8d915..9fa3d2bb96 100644 --- a/update-index.c +++ b/update-index.c @@ -473,7 +473,7 @@ static void read_index_info(int line_termination) } static const char update_index_usage[] = -"git-update-index [-q] [--add] [--replace] [--remove] [--unmerged] [--refresh] [--cacheinfo] [--chmod=(+|-)x] [--info-only] [--force-remove] [--stdin] [--index-info] [--ignore-missing] [-z] [--verbose] [--] ..."; +"git-update-index [-q] [--add] [--replace] [--remove] [--unmerged] [--refresh] [--really-refresh] [--cacheinfo] [--chmod=(+|-)x] [--assume-unchanged] [--info-only] [--force-remove] [--stdin] [--index-info] [--unresolve] [--ignore-missing] [-z] [--verbose] [--] ..."; static unsigned char head_sha1[20]; static unsigned char merge_head_sha1[20]; -- cgit v1.2.1 From c8c893c62b0d9997e7dfe7bd5f636ddbf29ef619 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 3 May 2006 07:59:00 -0700 Subject: Fix "git-log --parents" breakage post v1.3.0 Post 1.3.0 "git log" forgets to list parent commits on the first line when --parents is given. git-cvsserver relied on it. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/log-tree.c b/log-tree.c index 9634c4677f..b90ba6762a 100644 --- a/log-tree.c +++ b/log-tree.c @@ -3,6 +3,15 @@ #include "commit.h" #include "log-tree.h" +static void show_parents(struct commit *commit, int abbrev) +{ + struct commit_list *p; + for (p = commit->parents; p ; p = p->next) { + struct commit *parent = p->item; + printf(" %s", diff_unique_abbrev(parent->object.sha1, abbrev)); + } +} + void show_log(struct rev_info *opt, struct log_info *log, const char *sep) { static char this_header[16384]; @@ -14,7 +23,10 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) opt->loginfo = NULL; if (!opt->verbose_header) { - puts(sha1_to_hex(commit->object.sha1)); + fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); + if (opt->parents) + show_parents(commit, abbrev_commit); + putchar('\n'); return; } @@ -40,7 +52,9 @@ void show_log(struct rev_info *opt, struct log_info *log, const char *sep) printf("%s%s", opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", diff_unique_abbrev(commit->object.sha1, abbrev_commit)); - if (parent) + if (opt->parents) + show_parents(commit, abbrev_commit); + if (parent) printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); -- cgit v1.2.1 From 8f5ff31f8e74ac2f72c3c415beb2639bc36f7cb7 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 3 May 2006 14:41:03 +0200 Subject: repo-config: deconvolute logics It was rightly noticed that the logic is quite convoluted. Fix that. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- repo-config.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/repo-config.c b/repo-config.c index 7e06d1a041..63eda1bb78 100644 --- a/repo-config.c +++ b/repo-config.c @@ -27,36 +27,38 @@ static int show_config(const char* key_, const char* value_) { char value[256]; const char *vptr = value; + int dup_error = 0; if (value_ == NULL) value_ = ""; - if ((use_key_regexp || !strcmp(key_, key)) && - (!use_key_regexp || - !regexec(key_regexp, key_, 0, NULL, 0)) && - (regexp == NULL || + if (!use_key_regexp && strcmp(key_, key)) + return 0; + if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0)) + return 0; + if (regexp != NULL && (do_not_match ^ - !regexec(regexp, value_, 0, NULL, 0)))) { - int dup_error = 0; - if (show_keys) - printf("%s ", key_); - if (seen && !do_all) - dup_error = 1; - if (type == T_INT) - sprintf(value, "%d", git_config_int(key_, value_)); - else if (type == T_BOOL) - sprintf(value, "%s", git_config_bool(key_, value_) - ? "true" : "false"); - else - vptr = value_; - seen++; - if (dup_error) { - error("More than one value for the key %s: %s", - key_, vptr); - } - else - printf("%s\n", vptr); + regexec(regexp, value_, 0, NULL, 0))) + return 0; + + if (show_keys) + printf("%s ", key_); + if (seen && !do_all) + dup_error = 1; + if (type == T_INT) + sprintf(value, "%d", git_config_int(key_, value_)); + else if (type == T_BOOL) + vptr = git_config_bool(key_, value_) ? "true" : "false"; + else + vptr = value_; + seen++; + if (dup_error) { + error("More than one value for the key %s: %s", + key_, vptr); } + else + printf("%s\n", vptr); + return 0; } -- cgit v1.2.1 From 095acb8a2ac86c003d89886c5df7706c44912196 Mon Sep 17 00:00:00 2001 From: Martin Langhoff Date: Thu, 4 May 2006 10:53:37 +1200 Subject: cvsserver: use git-rev-list instead of git-log Signed-off-by: Martin Langhoff Signed-off-by: Junio C Hamano --- git-cvsserver.perl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/git-cvsserver.perl b/git-cvsserver.perl index 11d153c4cd..ffd9c66f94 100755 --- a/git-cvsserver.perl +++ b/git-cvsserver.perl @@ -2076,14 +2076,15 @@ sub update # TODO: log processing is memory bound # if we can parse into a 2nd file that is in reverse order # we can probably do something really efficient - my @git_log_params = ('--parents', '--topo-order'); + my @git_log_params = ('--pretty', '--parents', '--topo-order'); if (defined $lastcommit) { push @git_log_params, "$lastcommit..$self->{module}"; } else { push @git_log_params, $self->{module}; } - open(GITLOG, '-|', 'git-log', @git_log_params) or die "Cannot call git-log: $!"; + # git-rev-list is the backend / plumbing version of git-log + open(GITLOG, '-|', 'git-rev-list', @git_log_params) or die "Cannot call git-rev-list: $!"; my @commits; -- cgit v1.2.1 From 899707dac0c4a29b5b05a88a0017639508d48e7f Mon Sep 17 00:00:00 2001 From: Fredrik Kuivinen Date: Wed, 3 May 2006 23:28:46 +0200 Subject: blame: Fix path pruning This makes git-blame useable again, it has been totally broken for some time on larger repositories. Signed-off-by: Fredrik Kuivinen Signed-off-by: Junio C Hamano --- blame.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/blame.c b/blame.c index 07d2d27251..99ceea81df 100644 --- a/blame.c +++ b/blame.c @@ -515,9 +515,9 @@ static int compare_tree_path(struct rev_info* revs, paths[1] = NULL; diff_tree_setup_paths(get_pathspec(revs->prefix, paths), - &revs->diffopt); + &revs->pruning); ret = rev_compare_tree(revs, c1->tree, c2->tree); - diff_tree_release_paths(&revs->diffopt); + diff_tree_release_paths(&revs->pruning); return ret; } @@ -531,9 +531,9 @@ static int same_tree_as_empty_path(struct rev_info *revs, struct tree* t1, paths[1] = NULL; diff_tree_setup_paths(get_pathspec(revs->prefix, paths), - &revs->diffopt); + &revs->pruning); ret = rev_same_tree_as_empty(revs, t1); - diff_tree_release_paths(&revs->diffopt); + diff_tree_release_paths(&revs->pruning); return ret; } @@ -834,7 +834,7 @@ int main(int argc, const char **argv) args[0] = filename; args[1] = NULL; - diff_tree_setup_paths(args, &rev.diffopt); + diff_tree_setup_paths(args, &rev.pruning); prepare_revision_walk(&rev); process_commits(&rev, filename, &initial); -- cgit v1.2.1 From dcb3450fd8785d76dd3d25aa49be66190aa5e7f3 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 3 May 2006 17:21:08 -0700 Subject: sha1_to_hex() usage cleanup Somebody on the #git channel complained that the sha1_to_hex() thing uses a static buffer which caused an error message to show the same hex output twice instead of showing two different ones. That's pretty easily rectified by making it uses a simple LRU of a few buffers, which also allows some other users (that were aware of the buffer re-use) to be written in a more straightforward manner. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- diff.c | 6 ++---- merge-tree.c | 6 ++---- sha1_file.c | 5 +++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/diff.c b/diff.c index 6762fcee5a..c845c87113 100644 --- a/diff.c +++ b/diff.c @@ -1018,14 +1018,12 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o) } if (memcmp(one->sha1, two->sha1, 20)) { - char one_sha1[41]; int abbrev = o->full_index ? 40 : DEFAULT_ABBREV; - memcpy(one_sha1, sha1_to_hex(one->sha1), 41); len += snprintf(msg + len, sizeof(msg) - len, "index %.*s..%.*s", - abbrev, one_sha1, abbrev, - sha1_to_hex(two->sha1)); + abbrev, sha1_to_hex(one->sha1), + abbrev, sha1_to_hex(two->sha1)); if (one->mode == two->mode) len += snprintf(msg + len, sizeof(msg) - len, " %06o", one->mode); diff --git a/merge-tree.c b/merge-tree.c index 50528d5e43..cc7b5bd891 100644 --- a/merge-tree.c +++ b/merge-tree.c @@ -24,16 +24,14 @@ static const char *sha1_to_hex_zero(const unsigned char *sha1) static void resolve(const char *base, struct name_entry *branch1, struct name_entry *result) { - char branch1_sha1[50]; - /* If it's already branch1, don't bother showing it */ if (!branch1) return; - memcpy(branch1_sha1, sha1_to_hex_zero(branch1->sha1), 41); printf("0 %06o->%06o %s->%s %s%s\n", branch1->mode, result->mode, - branch1_sha1, sha1_to_hex_zero(result->sha1), + sha1_to_hex_zero(branch1->sha1), + sha1_to_hex_zero(result->sha1), base, result->path); } diff --git a/sha1_file.c b/sha1_file.c index f2d33afb27..5464828259 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -108,9 +108,10 @@ int safe_create_leading_directories(char *path) char * sha1_to_hex(const unsigned char *sha1) { - static char buffer[50]; + static int bufno; + static char hexbuffer[4][50]; static const char hex[] = "0123456789abcdef"; - char *buf = buffer; + char *buffer = hexbuffer[3 & ++bufno], *buf = buffer; int i; for (i = 0; i < 20; i++) { -- cgit v1.2.1 From aa9b1573a5ca93395e8e41651bfc7245f10e0240 Mon Sep 17 00:00:00 2001 From: Jon Loeliger Date: Wed, 3 May 2006 23:15:46 -0500 Subject: Alphabetize the glossary. Signed-off-by: Jon Loeliger Signed-off-by: Junio C Hamano --- Documentation/glossary.txt | 339 +++++++++++++++++++++++---------------------- 1 file changed, 170 insertions(+), 169 deletions(-) diff --git a/Documentation/glossary.txt b/Documentation/glossary.txt index 02a9d9c18a..aa1648effb 100644 --- a/Documentation/glossary.txt +++ b/Documentation/glossary.txt @@ -1,79 +1,37 @@ -object:: - The unit of storage in git. It is uniquely identified by - the SHA1 of its contents. Consequently, an object can not - be changed. - -object name:: - The unique identifier of an object. The hash of the object's contents - using the Secure Hash Algorithm 1 and usually represented by the 40 - character hexadecimal encoding of the hash of the object (possibly - followed by a white space). - -SHA1:: - Synonym for object name. - -object identifier:: - Synonym for object name. - -hash:: - In git's context, synonym to object name. - -object database:: - Stores a set of "objects", and an individual object is identified - by its object name. The objects usually live in `$GIT_DIR/objects/`. +alternate object database:: + Via the alternates mechanism, a repository can inherit part of its + object database from another object database, which is called + "alternate". blob object:: Untyped object, e.g. the contents of a file. -tree object:: - An object containing a list of file names and modes along with refs - to the associated blob and/or tree objects. A tree is equivalent - to a directory. - -tree:: - Either a working tree, or a tree object together with the - dependent blob and tree objects (i.e. a stored representation - of a working tree). - -DAG:: - Directed acyclic graph. The commit objects form a directed acyclic - graph, because they have parents (directed), and the graph of commit - objects is acyclic (there is no chain which begins and ends with the - same object). - -index:: - A collection of files with stat information, whose contents are - stored as objects. The index is a stored version of your working - tree. Truth be told, it can also contain a second, and even a third - version of a working tree, which are used when merging. - -index entry:: - The information regarding a particular file, stored in the index. - An index entry can be unmerged, if a merge was started, but not - yet finished (i.e. if the index contains multiple versions of - that file). - -unmerged index: - An index which contains unmerged index entries. +branch:: + A non-cyclical graph of revisions, i.e. the complete history of + a particular revision, which is called the branch head. The + branch heads are stored in `$GIT_DIR/refs/heads/`. cache:: Obsolete for: index. -working tree:: - The set of files and directories currently being worked on, - i.e. you can work in your working tree without using git at all. - -directory:: - The list you get with "ls" :-) +chain:: + A list of objects, where each object in the list contains a + reference to its successor (for example, the successor of a commit + could be one of its parents). -revision:: - A particular state of files and directories which was stored in - the object database. It is referenced by a commit object. +changeset:: + BitKeeper/cvsps speak for "commit". Since git does not store + changes, but states, it really does not make sense to use + the term "changesets" with git. checkout:: The action of updating the working tree to a revision which was stored in the object database. +clean:: + A working tree is clean, if it corresponds to the revision + referenced by the current head. Also see "dirty". + commit:: As a verb: The action of storing the current state of the index in the object database. The result is a revision. @@ -85,73 +43,72 @@ commit object:: tree object which corresponds to the top directory of the stored revision. -parent:: - A commit object contains a (possibly empty) list of the logical - predecessor(s) in the line of development, i.e. its parents. +core git:: + Fundamental data structures and utilities of git. Exposes only + limited source code management tools. -changeset:: - BitKeeper/cvsps speak for "commit". Since git does not store - changes, but states, it really does not make sense to use - the term "changesets" with git. +DAG:: + Directed acyclic graph. The commit objects form a directed acyclic + graph, because they have parents (directed), and the graph of commit + objects is acyclic (there is no chain which begins and ends with the + same object). -clean:: - A working tree is clean, if it corresponds to the revision - referenced by the current head. +dircache:: + You are *waaaaay* behind. dirty:: A working tree is said to be dirty if it contains modifications which have not been committed to the current branch. -head:: - The top of a branch. It contains a ref to the corresponding - commit object. +directory:: + The list you get with "ls" :-) -branch:: - A non-cyclical graph of revisions, i.e. the complete history of - a particular revision, which is called the branch head. The - branch heads are stored in `$GIT_DIR/refs/heads/`. +ent:: + Favorite synonym to "tree-ish" by some total geeks. See + `http://en.wikipedia.org/wiki/Ent_(Middle-earth)` for an in-depth + explanation. -master:: - The default branch. Whenever you create a git repository, a branch - named "master" is created, and becomes the active branch. In most - cases, this contains the local development. +fetch:: + Fetching a branch means to get the branch's head ref from a + remote repository, to find out which objects are missing from + the local object database, and to get them, too. -origin:: - The default upstream branch. Most projects have one upstream - project which they track, and by default 'origin' is used for - that purpose. New updates from upstream will be fetched into - this branch; you should never commit to it yourself. +file system:: + Linus Torvalds originally designed git to be a user space file + system, i.e. the infrastructure to hold files and directories. + That ensured the efficiency and speed of git. -ref:: - A 40-byte hex representation of a SHA1 pointing to a particular - object. These may be stored in `$GIT_DIR/refs/`. +git archive:: + Synonym for repository (for arch people). + +hash:: + In git's context, synonym to object name. + +head:: + The top of a branch. It contains a ref to the corresponding + commit object. head ref:: A ref pointing to a head. Often, this is abbreviated to "head". Head refs are stored in `$GIT_DIR/refs/heads/`. -tree-ish:: - A ref pointing to either a commit object, a tree object, or a - tag object pointing to a tag or commit or tree object. +index:: + A collection of files with stat information, whose contents are + stored as objects. The index is a stored version of your working + tree. Truth be told, it can also contain a second, and even a third + version of a working tree, which are used when merging. -ent:: - Favorite synonym to "tree-ish" by some total geeks. See - `http://en.wikipedia.org/wiki/Ent_(Middle-earth)` for an in-depth - explanation. +index entry:: + The information regarding a particular file, stored in the index. + An index entry can be unmerged, if a merge was started, but not + yet finished (i.e. if the index contains multiple versions of + that file). -tag object:: - An object containing a ref pointing to another object, which can - contain a message just like a commit object. It can also - contain a (PGP) signature, in which case it is called a "signed - tag object". +master:: + The default branch. Whenever you create a git repository, a branch + named "master" is created, and becomes the active branch. In most + cases, this contains the local development. -tag:: - A ref pointing to a tag or commit object. In contrast to a head, - a tag is not changed by a commit. Tags (not tag objects) are - stored in `$GIT_DIR/refs/tags/`. A git tag has nothing to do with - a Lisp tag (which is called object type in git's context). - A tag is most typically used to mark a particular point in the - commit ancestry chain. merge:: To merge branches means to try to accumulate the changes since a @@ -159,55 +116,57 @@ merge:: merge uses heuristics to accomplish that. Evidently, an automatic merge can fail. -octopus:: - To merge more than two branches. Also denotes an intelligent - predator. +object:: + The unit of storage in git. It is uniquely identified by + the SHA1 of its contents. Consequently, an object can not + be changed. -resolve:: - The action of fixing up manually what a failed automatic merge - left behind. +object database:: + Stores a set of "objects", and an individual object is identified + by its object name. The objects usually live in `$GIT_DIR/objects/`. -rewind:: - To throw away part of the development, i.e. to assign the head to - an earlier revision. +object identifier:: + Synonym for object name. -rebase:: - To clean a branch by starting from the head of the main line of - development ("master"), and reapply the (possibly cherry-picked) - changes from that branch. +object name:: + The unique identifier of an object. The hash of the object's contents + using the Secure Hash Algorithm 1 and usually represented by the 40 + character hexadecimal encoding of the hash of the object (possibly + followed by a white space). -repository:: - A collection of refs together with an object database containing - all objects, which are reachable from the refs, possibly accompanied - by meta data from one or more porcelains. A repository can - share an object database with other repositories. +object type: + One of the identifiers "commit","tree","tag" and "blob" describing + the type of an object. -git archive:: - Synonym for repository (for arch people). +octopus:: + To merge more than two branches. Also denotes an intelligent + predator. -file system:: - Linus Torvalds originally designed git to be a user space file - system, i.e. the infrastructure to hold files and directories. - That ensured the efficiency and speed of git. +origin:: + The default upstream branch. Most projects have one upstream + project which they track, and by default 'origin' is used for + that purpose. New updates from upstream will be fetched into + this branch; you should never commit to it yourself. -alternate object database:: - Via the alternates mechanism, a repository can inherit part of its - object database from another object database, which is called - "alternate". +pack:: + A set of objects which have been compressed into one file (to save + space or to transmit them efficiently). -reachable:: - An object is reachable from a ref/commit/tree/tag, if there is a - chain leading from the latter to the former. +pack index:: + The list of identifiers, and other information, of the objects in a + pack, to assist in efficiently accessing the contents of a pack. -chain:: - A list of objects, where each object in the list contains a - reference to its successor (for example, the successor of a commit - could be one of its parents). +parent:: + A commit object contains a (possibly empty) list of the logical + predecessor(s) in the line of development, i.e. its parents. -fetch:: - Fetching a branch means to get the branch's head ref from a - remote repository, to find out which objects are missing from - the local object database, and to get them, too. +plumbing:: + Cute name for core git. + +porcelain:: + Cute name for programs and program suites depending on core git, + presenting a high level access to core git. Porcelains expose + more of a SCM interface than the plumbing. pull:: Pulling a branch means to fetch it and merge it. @@ -221,33 +180,75 @@ push:: the remote head ref. If the remote head is not an ancestor to the local head, the push fails. -pack:: - A set of objects which have been compressed into one file (to save - space or to transmit them efficiently). +reachable:: + An object is reachable from a ref/commit/tree/tag, if there is a + chain leading from the latter to the former. -pack index:: - The list of identifiers, and other information, of the objects in a - pack, to assist in efficiently accessing the contents of a pack. +rebase:: + To clean a branch by starting from the head of the main line of + development ("master"), and reapply the (possibly cherry-picked) + changes from that branch. -core git:: - Fundamental data structures and utilities of git. Exposes only - limited source code management tools. +ref:: + A 40-byte hex representation of a SHA1 pointing to a particular + object. These may be stored in `$GIT_DIR/refs/`. -plumbing:: - Cute name for core git. +repository:: + A collection of refs together with an object database containing + all objects, which are reachable from the refs, possibly accompanied + by meta data from one or more porcelains. A repository can + share an object database with other repositories. -porcelain:: - Cute name for programs and program suites depending on core git, - presenting a high level access to core git. Porcelains expose - more of a SCM interface than the plumbing. +resolve:: + The action of fixing up manually what a failed automatic merge + left behind. -object type: - One of the identifiers "commit","tree","tag" and "blob" describing - the type of an object. +revision:: + A particular state of files and directories which was stored in + the object database. It is referenced by a commit object. + +rewind:: + To throw away part of the development, i.e. to assign the head to + an earlier revision. SCM:: Source code management (tool). -dircache:: - You are *waaaaay* behind. +SHA1:: + Synonym for object name. + +tree object:: + An object containing a list of file names and modes along with refs + to the associated blob and/or tree objects. A tree is equivalent + to a directory. + +tree:: + Either a working tree, or a tree object together with the + dependent blob and tree objects (i.e. a stored representation + of a working tree). + +tree-ish:: + A ref pointing to either a commit object, a tree object, or a + tag object pointing to a tag or commit or tree object. + +tag object:: + An object containing a ref pointing to another object, which can + contain a message just like a commit object. It can also + contain a (PGP) signature, in which case it is called a "signed + tag object". + +tag:: + A ref pointing to a tag or commit object. In contrast to a head, + a tag is not changed by a commit. Tags (not tag objects) are + stored in `$GIT_DIR/refs/tags/`. A git tag has nothing to do with + a Lisp tag (which is called object type in git's context). + A tag is most typically used to mark a particular point in the + commit ancestry chain. + +unmerged index: + An index which contains unmerged index entries. + +working tree:: + The set of files and directories currently being worked on, + i.e. you can work in your working tree without using git at all. -- cgit v1.2.1 From 9290cd58c374a73cca989879678dc1ee929cdf2e Mon Sep 17 00:00:00 2001 From: Jon Loeliger Date: Wed, 3 May 2006 23:18:59 -0500 Subject: Added definitions for a few words: fast forward pickaxe refspec tracking branch Wild hack allows "link:git-" prefix to reference commands too. Signed-off-by: Jon Loeliger Signed-off-by: Junio C Hamano --- Documentation/glossary.txt | 33 +++++++++++++++++++++++++++++++++ Documentation/sort_glossary.pl | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Documentation/glossary.txt b/Documentation/glossary.txt index aa1648effb..e216eb489c 100644 --- a/Documentation/glossary.txt +++ b/Documentation/glossary.txt @@ -68,6 +68,14 @@ ent:: `http://en.wikipedia.org/wiki/Ent_(Middle-earth)` for an in-depth explanation. +fast forward:: + A fast-forward is a special type of merge where you have + a revision and you are "merging" another branch's changes + that happen to be a descendant of what you have. + In such these cases, you do not make a new merge commit but + instead just update to his revision. This will happen + frequently on a tracking branch of a remote repository. + fetch:: Fetching a branch means to get the branch's head ref from a remote repository, to find out which objects are missing from @@ -160,6 +168,12 @@ parent:: A commit object contains a (possibly empty) list of the logical predecessor(s) in the line of development, i.e. its parents. +pickaxe:: The term pickaxe refers to an option to the diffcore routines + that help select changes that add or delete a given text string. + With the --pickaxe-all option, it can be used to view the + full changeset that introduced or removed, say, a particular + line of text. See gitlink:git-diff[1]. + plumbing:: Cute name for core git. @@ -193,6 +207,18 @@ ref:: A 40-byte hex representation of a SHA1 pointing to a particular object. These may be stored in `$GIT_DIR/refs/`. +refspec:: + A refspec is used by fetch and push to describe the mapping + between remote ref and local ref. They are combined with + a colon in the format :, preceded by an optional + plus sign, +. For example: + `git fetch $URL refs/heads/master:refs/heads/origin` + means "grab the master branch head from the $URL and store + it as my origin branch head". + And `git push $URL refs/heads/master:refs/heads/to-upstream` + means "publish my master branch head as to-upstream master head + at $URL". See also gitlink:git-push[1] + repository:: A collection of refs together with an object database containing all objects, which are reachable from the refs, possibly accompanied @@ -217,6 +243,13 @@ SCM:: SHA1:: Synonym for object name. +tracking branch:: + A regular git branch that is used to follow changes from + another repository. A tracking branch should not contain + direct modifications or made commits made locally. + A tracking branch can usually be identified as the + right-hand-side ref in a Pull: refspec. + tree object:: An object containing a list of file names and modes along with refs to the associated blob and/or tree objects. A tree is equivalent diff --git a/Documentation/sort_glossary.pl b/Documentation/sort_glossary.pl index e57dc78e0e..e0bc552a64 100644 --- a/Documentation/sort_glossary.pl +++ b/Documentation/sort_glossary.pl @@ -48,7 +48,7 @@ This list is sorted alphabetically: '; @keys=sort {uc($a) cmp uc($b)} keys %terms; -$pattern='(\b'.join('\b|\b',reverse @keys).'\b)'; +$pattern='(\b(?>";/eg; print '[[ref_'.no_spaces($key).']]'.$key."::\n" -- cgit v1.2.1 From 7abd7117ec57b8c3c2a469db62c7811fdac5c655 Mon Sep 17 00:00:00 2001 From: Jon Loeliger Date: Wed, 3 May 2006 23:19:54 -0500 Subject: Add a few more words to the glossary. Clean up a few entries and fix typos. bare repository cherry-picking hook topic branch [jc: removing questionable "symbolic ref -- see 'ref'" for now.] Signed-off-by: Jon Loeliger Signed-off-by: Junio C Hamano --- Documentation/glossary.txt | 63 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/Documentation/glossary.txt b/Documentation/glossary.txt index e216eb489c..39c90ad7a6 100644 --- a/Documentation/glossary.txt +++ b/Documentation/glossary.txt @@ -3,6 +3,17 @@ alternate object database:: object database from another object database, which is called "alternate". +bare repository:: + A bare repository is normally an appropriately named + directory with a `.git` suffix that does not have a + locally checked-out copy of any of the files under revision + control. That is, all of the `git` administrative and + control files that would normally be present in the + hidden `.git` sub-directory are directly present in + the `repository.git` directory instead, and no other files + are present and checked out. Usually publishers of public + repositories make bare repositories available. + blob object:: Untyped object, e.g. the contents of a file. @@ -28,6 +39,15 @@ checkout:: The action of updating the working tree to a revision which was stored in the object database. +cherry-picking:: + In SCM jargon, "cherry pick" means to choose a subset of + changes out of a series of changes (typically commits) + and record them as a new series of changes on top of + different codebase. In GIT, this is performed by + "git cherry-pick" command to extract the change + introduced by an existing commit and to record it based + on the tip of the current branch as a new commit. + clean:: A working tree is clean, if it corresponds to the revision referenced by the current head. Also see "dirty". @@ -100,6 +120,16 @@ head ref:: A ref pointing to a head. Often, this is abbreviated to "head". Head refs are stored in `$GIT_DIR/refs/heads/`. +hook:: + During the normal execution of several git commands, + call-outs are made to optional scripts that allow + a developer to add functionality or checking. + Typically, the hooks allow for a command to be pre-verified + and potentially aborted, and allow for a post-notification + after the operation is done. + The hook scripts are found in the `$GIT_DIR/hooks/` directory, + and are enabled by simply making them executable. + index:: A collection of files with stat information, whose contents are stored as objects. The index is a stored version of your working @@ -113,10 +143,10 @@ index entry:: that file). master:: - The default branch. Whenever you create a git repository, a branch - named "master" is created, and becomes the active branch. In most - cases, this contains the local development. - + The default development branch. Whenever you create a git + repository, a branch named "master" is created, and becomes + the active branch. In most cases, this contains the local + development, though that is purely conventional and not required. merge:: To merge branches means to try to accumulate the changes since a @@ -151,10 +181,11 @@ octopus:: predator. origin:: - The default upstream branch. Most projects have one upstream - project which they track, and by default 'origin' is used for - that purpose. New updates from upstream will be fetched into - this branch; you should never commit to it yourself. + The default upstream tracking branch. Most projects have at + least one upstream project which they track. By default + 'origin' is used for that purpose. New upstream updates + will be fetched into this branch; you should never commit + to it yourself. pack:: A set of objects which have been compressed into one file (to save @@ -168,7 +199,8 @@ parent:: A commit object contains a (possibly empty) list of the logical predecessor(s) in the line of development, i.e. its parents. -pickaxe:: The term pickaxe refers to an option to the diffcore routines +pickaxe:: + The term pickaxe refers to an option to the diffcore routines that help select changes that add or delete a given text string. With the --pickaxe-all option, it can be used to view the full changeset that introduced or removed, say, a particular @@ -204,8 +236,8 @@ rebase:: changes from that branch. ref:: - A 40-byte hex representation of a SHA1 pointing to a particular - object. These may be stored in `$GIT_DIR/refs/`. + A 40-byte hex representation of a SHA1 or a name that denotes + a particular object. These may be stored in `$GIT_DIR/refs/`. refspec:: A refspec is used by fetch and push to describe the mapping @@ -243,10 +275,17 @@ SCM:: SHA1:: Synonym for object name. +topic branch:: + A regular git branch that is used by a developer to + identify a conceptual line of development. Since branches + are very easy and inexpensive, it is often desirable to + have several small branches that each contain very well + defined concepts or small incremental yet related changes. + tracking branch:: A regular git branch that is used to follow changes from another repository. A tracking branch should not contain - direct modifications or made commits made locally. + direct modifications or have local commits made to it. A tracking branch can usually be identified as the right-hand-side ref in a Pull: refspec. -- cgit v1.2.1 From 5edbcd8d778d81254d2c8a4229c76c6fa7880407 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 4 May 2006 23:18:14 +0200 Subject: builtin-push: --all and --tags _are_ explicit refspecs ... so do not get refspecs from remotes/* or the config if one of them was specified. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-push.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin-push.c b/builtin-push.c index 06d06ff310..e530022824 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -72,7 +72,7 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI]) { int n = 0; FILE *f = fopen(git_path("remotes/%s", repo), "r"); - int has_explicit_refspec = refspec_nr; + int has_explicit_refspec = refspec_nr || all || tags; if (!f) return -1; @@ -144,7 +144,7 @@ static int get_config_remotes_uri(const char *repo, const char *uri[MAX_URI]) config_repo = repo; config_current_uri = 0; config_uri = uri; - config_get_refspecs = !refspec_nr; + config_get_refspecs = !(refspec_nr || all || tags); git_config(get_remote_config); return config_current_uri; -- cgit v1.2.1 From fb335158d5a93349e16bc0985e75e93bb9fcd5eb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 4 May 2006 17:38:41 -0700 Subject: Makefile: do not link rev-list any specially. We used to depend on bignum from openssl for rev-list to compute merge-order, but there is no reason to use different build recipe from other programs anymore. Just build it with git-%$X rule like everybody else. Noticed by Alexey Dobriyan. Signed-off-by: Junio C Hamano --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index a3f7e92d01..45484fcd82 100644 --- a/Makefile +++ b/Makefile @@ -564,10 +564,6 @@ git-http-push$X: revision.o http.o http-push.o $(LIB_FILE) $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) -git-rev-list$X: rev-list.o $(LIB_FILE) - $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ - $(LIBS) $(OPENSSL_LIBSSL) - init-db.o: init-db.c $(CC) -c $(ALL_CFLAGS) \ -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' $*.c -- cgit v1.2.1 From ac4c758adcf52b913b82d481626b0f8648e95475 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 May 2006 02:35:58 -0700 Subject: delta: stricter constness Signed-off-by: Junio C Hamano --- delta.h | 6 +++--- diff-delta.c | 4 ++-- patch-delta.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/delta.h b/delta.h index 9464f3e9b0..09b2e1eed5 100644 --- a/delta.h +++ b/delta.h @@ -2,11 +2,11 @@ #define DELTA_H /* handling of delta buffers */ -extern void *diff_delta(void *from_buf, unsigned long from_size, - void *to_buf, unsigned long to_size, +extern void *diff_delta(const void *from_buf, unsigned long from_size, + const void *to_buf, unsigned long to_size, unsigned long *delta_size, unsigned long max_size); extern void *patch_delta(void *src_buf, unsigned long src_size, - void *delta_buf, unsigned long delta_size, + const void *delta_buf, unsigned long delta_size, unsigned long *dst_size); /* the smallest possible delta size is 4 bytes */ diff --git a/diff-delta.c b/diff-delta.c index 1188b31cd0..5bc22047f8 100644 --- a/diff-delta.c +++ b/diff-delta.c @@ -131,8 +131,8 @@ static struct index ** delta_index(const unsigned char *buf, /* the maximum size for any opcode */ #define MAX_OP_SIZE COPYOP_SIZE(0xffffffff, 0xffffffff) -void *diff_delta(void *from_buf, unsigned long from_size, - void *to_buf, unsigned long to_size, +void *diff_delta(const void *from_buf, unsigned long from_size, + const void *to_buf, unsigned long to_size, unsigned long *delta_size, unsigned long max_size) { diff --git a/patch-delta.c b/patch-delta.c index d95f0d9721..affd4f673d 100644 --- a/patch-delta.c +++ b/patch-delta.c @@ -14,7 +14,7 @@ #include "delta.h" void *patch_delta(void *src_buf, unsigned long src_size, - void *delta_buf, unsigned long delta_size, + const void *delta_buf, unsigned long delta_size, unsigned long *dst_size) { const unsigned char *data, *top; -- cgit v1.2.1 From 81c5a0e6e5135384a7316b9689a5b0baaf1a2752 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 5 May 2006 12:35:39 -0700 Subject: git-svn: documentation updates * Clarify that 'init' requires an argument * Remove instances of 'SVN_URL' in the manpage, it's not an environment variable. * Refer to 'Additional Fetch Arguments' when documenting 'fetch' * document --authors-file / -A option Thanks to Pavel Roskin and Seth Falcon for bringing these issues to my attention. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- contrib/git-svn/git-svn.perl | 6 ++++-- contrib/git-svn/git-svn.txt | 45 +++++++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl index 7c44450d72..e003501be6 100755 --- a/contrib/git-svn/git-svn.perl +++ b/contrib/git-svn/git-svn.perl @@ -42,7 +42,8 @@ my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext, my %cmd = ( fetch => [ \&fetch, "Download new revisions from SVN", { 'revision|r=s' => \$_revision, %fc_opts } ], - init => [ \&init, "Initialize and fetch (import)", { } ], + init => [ \&init, "Initialize a repo for tracking" . + " (requires URL argument)", { } ], commit => [ \&commit, "Commit git revisions to SVN", { 'stdin|' => \$_stdin, 'edit|e' => \$_edit, @@ -220,7 +221,8 @@ when you have upgraded your tools and habits to use refs/remotes/$GIT_SVN } sub init { - $SVN_URL = shift or croak "SVN repository location required\n"; + $SVN_URL = shift or die "SVN repository location required " . + "as a command-line argument\n"; unless (-d $GIT_DIR) { sys('git-init-db'); } diff --git a/contrib/git-svn/git-svn.txt b/contrib/git-svn/git-svn.txt index e18fcaf4fb..f7d3de48f0 100644 --- a/contrib/git-svn/git-svn.txt +++ b/contrib/git-svn/git-svn.txt @@ -36,17 +36,22 @@ COMMANDS -------- init:: Creates an empty git repository with additional metadata - directories for git-svn. The SVN_URL must be specified - at this point. + directories for git-svn. The Subversion URL must be specified + as a command-line argument. fetch:: - Fetch unfetched revisions from the SVN_URL we are tracking. - refs/heads/remotes/git-svn will be updated to the latest revision. + Fetch unfetched revisions from the Subversion URL we are + tracking. refs/remotes/git-svn will be updated to the + latest revision. - Note: You should never attempt to modify the remotes/git-svn branch - outside of git-svn. Instead, create a branch from remotes/git-svn - and work on that branch. Use the 'commit' command (see below) - to write git commits back to remotes/git-svn. + Note: You should never attempt to modify the remotes/git-svn + branch outside of git-svn. Instead, create a branch from + remotes/git-svn and work on that branch. Use the 'commit' + command (see below) to write git commits back to + remotes/git-svn. + + See 'Additional Fetch Arguments' if you are interested in + manually joining branches on commit. commit:: Commit specified commit or tree objects to SVN. This relies on @@ -62,9 +67,9 @@ rebuild:: tracked with git-svn. Unfortunately, git-clone does not clone git-svn metadata and the svn working tree that git-svn uses for its operations. This rebuilds the metadata so git-svn can - resume fetch operations. SVN_URL may be optionally specified if - the directory/repository you're tracking has moved or changed - protocols. + resume fetch operations. A Subversion URL may be optionally + specified at the command-line if the directory/repository you're + tracking has moved or changed protocols. show-ignore:: Recursively finds and lists the svn:ignore property on @@ -123,6 +128,24 @@ OPTIONS repo-config key: svn.l repo-config key: svn.findcopiesharder +-A:: +--authors-file=:: + + Syntax is compatible with the files used by git-svnimport and + git-cvsimport: + +------------------------------------------------------------------------ +loginname = Joe User +------------------------------------------------------------------------ + + If this option is specified and git-svn encounters an SVN + committer name that does not exist in the authors-file, git-svn + will abort operation. The user will then have to add the + appropriate entry. Re-running the previous git-svn command + after the authors-file is modified should continue operation. + + repo-config key: svn.authors-file + ADVANCED OPTIONS ---------------- -b:: -- cgit v1.2.1 From 88521450fc4cca1f96d9179ee4f2cbe51da3359c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 5 May 2006 12:35:40 -0700 Subject: git-svn 1.0.0 Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- contrib/git-svn/git-svn.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl index e003501be6..de13a96b8a 100755 --- a/contrib/git-svn/git-svn.perl +++ b/contrib/git-svn/git-svn.perl @@ -8,7 +8,7 @@ use vars qw/ $AUTHOR $VERSION $GIT_SVN_INDEX $GIT_SVN $GIT_DIR $REV_DIR/; $AUTHOR = 'Eric Wong '; -$VERSION = '0.11.0'; +$VERSION = '1.0.0'; use Cwd qw/abs_path/; $GIT_DIR = abs_path($ENV{GIT_DIR} || '.git'); -- cgit v1.2.1 From 2b5f3ed3166ea7d93f4138bb2b6c849851ba86ac Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 15:05:10 -0400 Subject: Several trivial documentation touch ups. Move incorrect asciidoc level 2 titles back to level 1. Show output of git-name-rev in man page example. Reword sentences that begin with a period (.) in asciidoc numbered lists to work around conversion to man page bug. Mention that git-repack now calls git-prune-packed when the -d option is passed to it. [imap] section headers in the config file example need to be contained in a literal block. imap.pass is the proper config file variable to use, not imap.password. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- Documentation/git-clone.txt | 2 +- Documentation/git-imap-send.txt | 4 +++- Documentation/git-name-rev.txt | 1 + Documentation/git-repack.txt | 1 + Documentation/git-repo-config.txt | 6 +++--- Documentation/git-reset.txt | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index 131e445747..b333f51045 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -101,7 +101,7 @@ OPTIONS is not allowed. Examples -~~~~~~~~ +-------- Clone from upstream:: + diff --git a/Documentation/git-imap-send.txt b/Documentation/git-imap-send.txt index cfc0d88d02..eca9e9ccef 100644 --- a/Documentation/git-imap-send.txt +++ b/Documentation/git-imap-send.txt @@ -29,6 +29,7 @@ CONFIGURATION git-imap-send requires the following values in the repository configuration file (shown with examples): +.......................... [imap] Folder = "INBOX.Drafts" @@ -38,8 +39,9 @@ configuration file (shown with examples): [imap] Host = imap.server.com User = bob - Password = pwd + Pass = pwd Port = 143 +.......................... BUGS diff --git a/Documentation/git-name-rev.txt b/Documentation/git-name-rev.txt index 68707083be..ffaa00468f 100644 --- a/Documentation/git-name-rev.txt +++ b/Documentation/git-name-rev.txt @@ -41,6 +41,7 @@ Enter git-name-rev: ------------ % git name-rev 33db5f4d9027a10e477ccf054b2c1ab94f74c85a +33db5f4d9027a10e477ccf054b2c1ab94f74c85a tags/v0.99^0~940 ------------ Now you are wiser, because you know that it happened 940 revisions before v0.99. diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt index d2f9a44382..951622774a 100644 --- a/Documentation/git-repack.txt +++ b/Documentation/git-repack.txt @@ -38,6 +38,7 @@ OPTIONS -d:: After packing, if the newly created packs make some existing packs redundant, remove the redundant packs. + Also runs gitlink:git-prune-packed[1]. -l:: Pass the `--local` option to `git pack-objects`, see diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt index ddcf52364c..fd44f629f5 100644 --- a/Documentation/git-repo-config.txt +++ b/Documentation/git-repo-config.txt @@ -34,10 +34,10 @@ convert the value to the canonical form (simple decimal number for int, a "true" or "false" string for bool). If no type specifier is passed, no checks or transformations are performed on the value. -This command will fail if +This command will fail if: -. .git/config is invalid, -. .git/config can not be written to, +. The .git/config file is invalid, +. Can not write to .git/config, . no section was provided, . the section or key is invalid, . you try to unset an option which does not exist, or diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index ebcfe5edb7..b27399dd41 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -43,7 +43,7 @@ OPTIONS Commit to make the current HEAD. Examples -~~~~~~~~ +-------- Undo a commit and redo:: + -- cgit v1.2.1 From e994004f93a481414b9065ac24edd0807d1c311e Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 15:05:24 -0400 Subject: Fix up docs where "--" isn't displayed correctly. A bare "--" doesn't show up in man or html pages correctly as two individual dashes unless backslashed as \-- in the asciidoc source. Note, no backslash is needed inside a literal block. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- Documentation/git-add.txt | 2 +- Documentation/git-checkout-index.txt | 2 +- Documentation/git-commit.txt | 2 +- Documentation/git-log.txt | 2 +- Documentation/git-ls-files.txt | 2 +- Documentation/git-merge-index.txt | 4 ++-- Documentation/git-prune.txt | 2 +- Documentation/git-rm.txt | 2 +- Documentation/git-update-index.txt | 2 +- Documentation/git-verify-pack.txt | 2 +- Documentation/git-whatchanged.txt | 2 +- Documentation/gitk.txt | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index ae24547c8a..5e3112943d 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -26,7 +26,7 @@ OPTIONS -v:: Be verbose. ---:: +\--:: This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for command-line options). diff --git a/Documentation/git-checkout-index.txt b/Documentation/git-checkout-index.txt index 09bd6a5535..765c173e15 100644 --- a/Documentation/git-checkout-index.txt +++ b/Documentation/git-checkout-index.txt @@ -63,7 +63,7 @@ OPTIONS Only meaningful with `--stdin`; paths are separated with NUL character instead of LF. ---:: +\--:: Do not interpret any more arguments as options. The order of the flags used to matter, but not anymore. diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index 0a7365b9a8..38df59ce23 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -106,7 +106,7 @@ but can be used to amend a merge commit. index and the latest commit does not match on the specified paths to avoid confusion. ---:: +\--:: Do not interpret any more arguments as options. ...:: diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index af378ffcf9..c9ffff734c 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -51,7 +51,7 @@ git log v2.6.12.. include/scsi drivers/scsi:: Show all commits since version 'v2.6.12' that changed any file in the include/scsi or drivers/scsi subdirectories -git log --since="2 weeks ago" -- gitk:: +git log --since="2 weeks ago" \-- gitk:: Show the changes during the last two weeks to the file 'gitk'. The "--" is necessary to avoid confusion with the *branch* named diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt index 796d049be6..a29c633c8d 100644 --- a/Documentation/git-ls-files.txt +++ b/Documentation/git-ls-files.txt @@ -106,7 +106,7 @@ OPTIONS lines, show only handful hexdigits prefix. Non default number of digits can be specified with --abbrev=. ---:: +\--:: Do not interpret any more arguments as options. :: diff --git a/Documentation/git-merge-index.txt b/Documentation/git-merge-index.txt index fbc986aa84..332e023d0f 100644 --- a/Documentation/git-merge-index.txt +++ b/Documentation/git-merge-index.txt @@ -8,7 +8,7 @@ git-merge-index - Runs a merge for files needing merging SYNOPSIS -------- -'git-merge-index' [-o] [-q] (-a | -- | \*) +'git-merge-index' [-o] [-q] (-a | \-- | \*) DESCRIPTION ----------- @@ -19,7 +19,7 @@ files are passed as arguments 5, 6 and 7. OPTIONS ------- ---:: +\--:: Do not interpret any more arguments as options. -a:: diff --git a/Documentation/git-prune.txt b/Documentation/git-prune.txt index f694fcbde8..a11e303094 100644 --- a/Documentation/git-prune.txt +++ b/Documentation/git-prune.txt @@ -28,7 +28,7 @@ OPTIONS Do not remove anything; just report what it would remove. ---:: +\--:: Do not interpret any more arguments as options. ...:: diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt index c9c3088424..66fc478f57 100644 --- a/Documentation/git-rm.txt +++ b/Documentation/git-rm.txt @@ -32,7 +32,7 @@ OPTIONS -v:: Be verbose. ---:: +\--:: This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for command-line options). diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index 23f2b6f1a5..57177c7fb6 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -113,7 +113,7 @@ OPTIONS Only meaningful with `--stdin`; paths are separated with NUL character instead of LF. ---:: +\--:: Do not interpret any more arguments as options. :: diff --git a/Documentation/git-verify-pack.txt b/Documentation/git-verify-pack.txt index 4962d6975f..7a6132b016 100644 --- a/Documentation/git-verify-pack.txt +++ b/Documentation/git-verify-pack.txt @@ -25,7 +25,7 @@ OPTIONS -v:: After verifying the pack, show list of objects contained in the pack. ---:: +\--:: Do not interpret any more arguments as options. OUTPUT FORMAT diff --git a/Documentation/git-whatchanged.txt b/Documentation/git-whatchanged.txt index 641cb7ea97..e8f21d02f7 100644 --- a/Documentation/git-whatchanged.txt +++ b/Documentation/git-whatchanged.txt @@ -58,7 +58,7 @@ git-whatchanged -p v2.6.12.. include/scsi drivers/scsi:: Show as patches the commits since version 'v2.6.12' that changed any file in the include/scsi or drivers/scsi subdirectories -git-whatchanged --since="2 weeks ago" -- gitk:: +git-whatchanged --since="2 weeks ago" \-- gitk:: Show the changes during the last two weeks to the file 'gitk'. The "--" is necessary to avoid confusion with the *branch* named diff --git a/Documentation/gitk.txt b/Documentation/gitk.txt index eb126d7a4b..cb482bf98e 100644 --- a/Documentation/gitk.txt +++ b/Documentation/gitk.txt @@ -31,7 +31,7 @@ gitk v2.6.12.. include/scsi drivers/scsi:: Show as the changes since version 'v2.6.12' that changed any file in the include/scsi or drivers/scsi subdirectories -gitk --since="2 weeks ago" -- gitk:: +gitk --since="2 weeks ago" \-- gitk:: Show the changes during the last two weeks to the file 'gitk'. The "--" is necessary to avoid confusion with the *branch* named -- cgit v1.2.1 From ae0b219c8e32aa8f34401252d845916b136a467b Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 15:05:36 -0400 Subject: Update git-unpack-objects documentation. Document that git-unpack-objects will not produce any results when used on a pack that exists in a repository; move it first. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- Documentation/git-unpack-objects.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Documentation/git-unpack-objects.txt b/Documentation/git-unpack-objects.txt index 18280628a1..c20b38b08a 100644 --- a/Documentation/git-unpack-objects.txt +++ b/Documentation/git-unpack-objects.txt @@ -13,9 +13,16 @@ SYNOPSIS DESCRIPTION ----------- -Reads a packed archive (.pack) from the standard input, and -expands the objects contained in the pack into "one-file -one-object" format in $GIT_OBJECT_DIRECTORY. +Read a packed archive (.pack) from the standard input, expanding +the objects contained within and writing them into the repository in +"loose" (one object per file) format. + +Objects that already exist in the repository will *not* be unpacked +from the pack-file. Therefore, nothing will be unpacked if you use +this command on a pack-file that exists within the target repository. + +Please see the `git-repack` documentation for options to generate +new packs and replace existing ones. OPTIONS ------- -- cgit v1.2.1 From 81ae43cdc4ec4bfba1638aa9786e08322d10b72c Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 15:06:07 -0400 Subject: Clarify git-cherry documentation. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- Documentation/git-cherry.txt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt index 9a5e37186f..893baaa6f6 100644 --- a/Documentation/git-cherry.txt +++ b/Documentation/git-cherry.txt @@ -11,11 +11,20 @@ SYNOPSIS DESCRIPTION ----------- -Each commit between the fork-point and is examined, and compared against -the change each commit between the fork-point and introduces. -Commits already included in upstream are prefixed with '-' (meaning "drop from -my local pull"), while commits missing from upstream are prefixed with '+' -(meaning "add to the updated upstream"). +The changeset (or "diff") of each commit between the fork-point and +is compared against each commit between the fork-point and . + +Every commit with a changeset that doesn't exist in the other branch +has its id (sha1) reported, prefixed by a symbol. Those existing only +in the branch are prefixed with a minus (-) sign, and those +that only exist in the branch are prefixed with a plus (+) symbol. + +Because git-cherry compares the changeset rather than the commit id +(sha1), you can use git-cherry to find out if a commit you made locally +has been applied under a different commit id. For example, +this will happen if you're feeding patches via email rather +than pushing or pulling commits directly. + OPTIONS ------- -- cgit v1.2.1 From 93ddef3e2dd5f7f3238fad9d52e974d03c7844f2 Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 5 May 2006 09:49:15 -0400 Subject: Fix for config file section parsing. Currently, if the target key has a section that matches the initial substring of another section we mistakenly believe we've found the correct section. To avoid this problem, ensure that the section lengths are identical before comparison. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- config.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 4e1f0c2286..a3e14d76e5 100644 --- a/config.c +++ b/config.c @@ -335,8 +335,9 @@ static int store_aux(const char* key, const char* value) store.offset[store.seen] = ftell(config_file); store.state = KEY_SEEN; store.seen++; - } else if(!strncmp(key, store.key, store.baselen)) - store.state = SECTION_SEEN; + } else if (strrchr(key, '.') - key == store.baselen && + !strncmp(key, store.key, store.baselen)) + store.state = SECTION_SEEN; } return 0; } -- cgit v1.2.1 From 7ebdba614223f867d3f19963647406df1d0e5ce0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 2 May 2006 16:58:37 +0200 Subject: repo-config: trim white-space before comment Earlier, calling git-repo-config core.hello on a .git/config like this: [core] hello = world ; a comment would yield "world " (i.e. with a trailing space). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano (cherry picked from c1aee1fd8d94da9b3c5d2dc1d4264f7e73a58f80 commit) --- config.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config.c b/config.c index a3e14d76e5..2cdf5fcab4 100644 --- a/config.c +++ b/config.c @@ -60,6 +60,12 @@ static char *parse_value(void) space = 1; continue; } + if (!quote) { + if (c == ';' || c == '#') { + comment = 1; + continue; + } + } if (space) { if (len) value[len++] = ' '; @@ -93,12 +99,6 @@ static char *parse_value(void) quote = 1-quote; continue; } - if (!quote) { - if (c == ';' || c == '#') { - comment = 1; - continue; - } - } value[len++] = c; } } -- cgit v1.2.1 From e388c7382563b7497397c78bc078d0679dc891a8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 2 May 2006 00:40:24 -0700 Subject: core.prefersymlinkrefs: use symlinks for .git/HEAD When inspecting a project whose build infrastructure used to assume that .git/HEAD is a symlink ref, core.prefersymlinkrefs in the config file of such a project would help to bisect its history. Signed-off-by: Junio C Hamano (cherry picked from 9f0bb90d161edf8c43f5261d12bf83f14eb02ff4 commit) --- Documentation/config.txt | 8 +++++--- Makefile | 8 ++++++-- cache.h | 2 +- config.c | 4 ++-- environment.c | 2 +- refs.c | 4 ++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index b27b0d5c06..d1a4bec0d4 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -64,9 +64,11 @@ core.ignoreStat:: slow, such as Microsoft Windows. See gitlink:git-update-index[1]. False by default. -core.onlyUseSymrefs:: - Always use the "symref" format instead of symbolic links for HEAD - and other symbolic reference files. True by default. +core.preferSymlinkRefs:: + Instead of the default "symref" format for HEAD + and other symbolic reference files, use symbolic links. + This is sometimes needed to work with old scripts that + expect HEAD to be a symbolic link. core.repositoryFormatVersion:: Internal variable identifying the repository format and layout diff --git a/Makefile b/Makefile index 8aed3af016..3972d10886 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,8 @@ all: # # Define NO_SETENV if you don't have setenv in the C library. # -# Define USE_SYMLINK_HEAD if you want .git/HEAD to be a symbolic link. -# Don't enable it on Windows. +# Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link. +# Enable it on Windows. By default, symrefs are still used. # # Define PPC_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for PowerPC. @@ -260,6 +260,7 @@ ifeq ($(uname_O),Cygwin) NO_D_TYPE_IN_DIRENT = YesPlease NO_D_INO_IN_DIRENT = YesPlease NO_STRCASESTR = YesPlease + NO_SYMLINK_HEAD = YesPlease NEEDS_LIBICONV = YesPlease # There are conflicting reports about this. # On some boxes NO_MMAP is needed, and not so elsewhere. @@ -383,6 +384,9 @@ endif ifdef NO_D_INO_IN_DIRENT ALL_CFLAGS += -DNO_D_INO_IN_DIRENT endif +ifdef NO_SYMLINK_HEAD + ALL_CFLAGS += -DNO_SYMLINK_HEAD +endif ifdef NO_STRCASESTR COMPAT_CFLAGS += -DNO_STRCASESTR COMPAT_OBJS += compat/strcasestr.o diff --git a/cache.h b/cache.h index 4d8fabc6d8..ae69fdea95 100644 --- a/cache.h +++ b/cache.h @@ -168,7 +168,7 @@ extern void rollback_index_file(struct cache_file *); /* Environment bits from configuration mechanism */ extern int trust_executable_bit; extern int assume_unchanged; -extern int only_use_symrefs; +extern int prefer_symlink_refs; extern int warn_ambiguous_refs; extern int diff_rename_limit_default; extern int shared_repository; diff --git a/config.c b/config.c index 2cdf5fcab4..87fb22041e 100644 --- a/config.c +++ b/config.c @@ -227,8 +227,8 @@ int git_default_config(const char *var, const char *value) return 0; } - if (!strcmp(var, "core.symrefsonly")) { - only_use_symrefs = git_config_bool(var, value); + if (!strcmp(var, "core.prefersymlinkrefs")) { + prefer_symlink_refs = git_config_bool(var, value); return 0; } diff --git a/environment.c b/environment.c index 6df647862c..444c99ed6e 100644 --- a/environment.c +++ b/environment.c @@ -13,7 +13,7 @@ char git_default_email[MAX_GITNAME]; char git_default_name[MAX_GITNAME]; int trust_executable_bit = 1; int assume_unchanged = 0; -int only_use_symrefs = 0; +int prefer_symlink_refs = 0; int warn_ambiguous_refs = 1; int repository_format_version = 0; char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8"; diff --git a/refs.c b/refs.c index 03398ccc53..275b914b2b 100644 --- a/refs.c +++ b/refs.c @@ -76,8 +76,8 @@ int create_symref(const char *git_HEAD, const char *refs_heads_master) char ref[1000]; int fd, len, written; -#ifdef USE_SYMLINK_HEAD - if (!only_use_symrefs) { +#ifndef NO_SYMLINK_HEAD + if (prefer_symlink_refs) { unlink(git_HEAD); if (!symlink(refs_heads_master, git_HEAD)) return 0; -- cgit v1.2.1 From 86118bcb463e3f34b3df21d550335a40586dfb66 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 May 2006 03:20:44 -0700 Subject: pack-object: squelch eye-candy on non-tty One of my post-update scripts runs a git-fetch into a separate repository and sends the results back to me (2>&1); I end up getting this in the mail: Generating pack... Done counting 180 objects. Result has 131 objects. Deltifying 131 objects. 0% (0/131) done^M 1% (2/131) done^M... This defaults not to do the progress report when not on a tty. You could give --progress to force the progress report, but let's not bother even documenting it nor mentioning it in the usage string. Signed-off-by: Junio C Hamano --- pack-objects.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pack-objects.c b/pack-objects.c index 6604338131..53caed42dd 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -1239,6 +1239,7 @@ int main(int argc, char **argv) setup_git_directory(); + progress = isatty(2); for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -1269,6 +1270,10 @@ int main(int argc, char **argv) usage(pack_usage); continue; } + if (!strcmp("--progress", arg)) { + progress = 1; + continue; + } if (!strcmp("-q", arg)) { progress = 0; continue; -- cgit v1.2.1 From 09895c1fa02f77acb2bde3d7e9da675eeb1271cf Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 May 2006 17:50:06 -0700 Subject: update-index --unresolve: work from a subdirectory. It completely forgot to take the prefix into account, so you had to feed the full path even when you start from a subdirectory, which was nonsensical. Signed-off-by: Junio C Hamano --- update-index.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/update-index.c b/update-index.c index 9fa3d2bb96..1870ac7966 100644 --- a/update-index.c +++ b/update-index.c @@ -576,7 +576,8 @@ static void read_head_pointers(void) } } -static int do_unresolve(int ac, const char **av) +static int do_unresolve(int ac, const char **av, + const char *prefix, int prefix_length) { int i; int err = 0; @@ -588,7 +589,10 @@ static int do_unresolve(int ac, const char **av) for (i = 1; i < ac; i++) { const char *arg = av[i]; - err |= unresolve_one(arg); + const char *p = prefix_path(prefix, prefix_length, arg); + err |= unresolve_one(p); + if (p != arg) + free((char*)p); } return err; } @@ -704,7 +708,8 @@ int main(int argc, const char **argv) break; } if (!strcmp(path, "--unresolve")) { - has_errors = do_unresolve(argc - i, argv + i); + has_errors = do_unresolve(argc - i, argv + i, + prefix, prefix_length); if (has_errors) active_cache_changed = 0; goto finish; -- cgit v1.2.1 From dc46da2286cf0d42e1e5ebbd272c201dbc3a626a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 May 2006 22:38:06 -0700 Subject: checkout-index: plug memory leak from prefix_path() prefix_path() sometimes allocates new memory and returns it, and other times returns the incoming path argument intact. The callers need to be a bit careful not to leak memory. Signed-off-by: Junio C Hamano --- checkout-index.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/checkout-index.c b/checkout-index.c index dd6a2d86fe..0b9cabc61c 100644 --- a/checkout-index.c +++ b/checkout-index.c @@ -269,12 +269,16 @@ int main(int argc, char **argv) /* Check out named files first */ for ( ; i < argc; i++) { const char *arg = argv[i]; + const char *p; if (all) die("git-checkout-index: don't mix '--all' and explicit filenames"); if (read_from_stdin) die("git-checkout-index: don't mix '--stdin' and explicit filenames"); - checkout_file(prefix_path(prefix, prefix_length, arg)); + p = prefix_path(prefix, prefix_length, arg); + checkout_file(p); + if (p != arg) + free((char*)p); } if (read_from_stdin) { @@ -284,6 +288,8 @@ int main(int argc, char **argv) strbuf_init(&buf); while (1) { char *path_name; + const char *p; + read_line(&buf, stdin, line_termination); if (buf.eof) break; @@ -291,7 +297,10 @@ int main(int argc, char **argv) path_name = unquote_c_style(buf.buf, NULL); else path_name = buf.buf; - checkout_file(prefix_path(prefix, prefix_length, path_name)); + p = prefix_path(prefix, prefix_length, path_name); + checkout_file(p); + if (p != path_name) + free((char *)p); if (path_name != buf.buf) free(path_name); } -- cgit v1.2.1 From fb69a760cc9103d1f8341a3c8ea09bd15a8a412d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 5 May 2006 22:53:56 -0700 Subject: update-index: plug memory leak from prefix_path() prefix_path() sometimes allocates new memory and returns it, and other times returns the incoming path argument intact. The callers need to be a bit careful not to leak memory. Signed-off-by: Junio C Hamano --- update-index.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/update-index.c b/update-index.c index 1870ac7966..d63f8ac998 100644 --- a/update-index.c +++ b/update-index.c @@ -364,23 +364,26 @@ static void update_one(const char *path, const char *prefix, int prefix_length) const char *p = prefix_path(prefix, prefix_length, path); if (!verify_path(p)) { fprintf(stderr, "Ignoring path %s\n", path); - return; + goto free_return; } if (mark_valid_only) { if (mark_valid(p)) die("Unable to mark file %s", path); - return; + goto free_return; } if (force_remove) { if (remove_file_from_cache(p)) die("git-update-index: unable to remove %s", path); report("remove '%s'", path); - return; + goto free_return; } if (add_file_to_cache(p)) die("Unable to process file %s", path); report("add '%s'", path); + free_return: + if (p != path) + free((char*)p); } static void read_index_info(int line_termination) @@ -735,6 +738,7 @@ int main(int argc, const char **argv) strbuf_init(&buf); while (1) { char *path_name; + const char *p; read_line(&buf, stdin, line_termination); if (buf.eof) break; @@ -742,11 +746,12 @@ int main(int argc, const char **argv) path_name = unquote_c_style(buf.buf, NULL); else path_name = buf.buf; - update_one(path_name, prefix, prefix_length); - if (set_executable_bit) { - const char *p = prefix_path(prefix, prefix_length, path_name); + p = prefix_path(prefix, prefix_length, path_name); + update_one(p, NULL, 0); + if (set_executable_bit) chmod_path(set_executable_bit, p); - } + if (p != path_name) + free((char*) p); if (path_name != buf.buf) free(path_name); } -- cgit v1.2.1 From 6f81bf16a91c4db5a02b81cbade89e73ca4d49b4 Mon Sep 17 00:00:00 2001 From: sean Date: Sat, 6 May 2006 14:14:02 -0400 Subject: Another config file parsing fix. If the variable we need to store should go into a section that currently only has a single variable (not matching the one we're trying to insert), we will already be into the next section before we notice we've bypassed the correct location to insert the variable. To handle this case we store the current location as soon as we find a variable matching the section of our new variable. This breakage was brought up by Linus. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- config.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 87fb22041e..41066e4f4e 100644 --- a/config.c +++ b/config.c @@ -336,8 +336,10 @@ static int store_aux(const char* key, const char* value) store.state = KEY_SEEN; store.seen++; } else if (strrchr(key, '.') - key == store.baselen && - !strncmp(key, store.key, store.baselen)) + !strncmp(key, store.key, store.baselen)) { store.state = SECTION_SEEN; + store.offset[store.seen] = ftell(config_file); + } } return 0; } -- cgit v1.2.1 From bd886fd3ea49b726493255d4adf5d20b31681713 Mon Sep 17 00:00:00 2001 From: sean Date: Sat, 6 May 2006 15:43:43 -0400 Subject: t1300-repo-config: two new config parsing tests. - correctly insert a new variable into a section that only contains a single (different) variable. - correctly insert a new section that matches the initial substring of an existing section. Signed-off-by: Sean Estabrooks Signed-off-by: Junio C Hamano --- t/t1300-repo-config.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 1bf728fb06..7090ea92c1 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -278,5 +278,36 @@ git-repo-config > output 2>&1 test_expect_success 'no arguments, but no crash' \ "test $? = 129 && grep usage output" +cat > .git/config << EOF +[a.b] + c = d +EOF + +git-repo-config a.x y + +cat > expect << EOF +[a.b] + c = d +[a] + x = y +EOF + +test_expect_success 'new section is partial match of another' 'cmp .git/config expect' + +git-repo-config b.x y +git-repo-config a.b c + +cat > expect << EOF +[a.b] + c = d +[a] + x = y + b = c +[b] + x = y +EOF + +test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect' + test_done -- cgit v1.2.1 From be65e7d9fbd3ae6fc097cedade2afe39805fcf4e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 7 May 2006 00:02:53 +0200 Subject: Fix users of prefix_path() to free() only when necessary Unfortunately, prefix_path() sometimes returns a newly xmalloc()ed buffer, and in other cases it returns a substring! For example, when calling git update-index ./hello.txt prefix_path() returns "hello.txt", but does not allocate a new buffer. The original code only checked if the result of prefix_path() was different from what was passed in, and thusly trigger a segmentation fault. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- checkout-index.c | 4 ++-- update-index.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/checkout-index.c b/checkout-index.c index 0b9cabc61c..cc3a745c14 100644 --- a/checkout-index.c +++ b/checkout-index.c @@ -277,7 +277,7 @@ int main(int argc, char **argv) die("git-checkout-index: don't mix '--stdin' and explicit filenames"); p = prefix_path(prefix, prefix_length, arg); checkout_file(p); - if (p != arg) + if (p < arg || p > arg + strlen(arg)) free((char*)p); } @@ -299,7 +299,7 @@ int main(int argc, char **argv) path_name = buf.buf; p = prefix_path(prefix, prefix_length, path_name); checkout_file(p); - if (p != path_name) + if (p < path_name || p > path_name + strlen(path_name)) free((char *)p); if (path_name != buf.buf) free(path_name); diff --git a/update-index.c b/update-index.c index d63f8ac998..00cde70645 100644 --- a/update-index.c +++ b/update-index.c @@ -382,7 +382,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length) die("Unable to process file %s", path); report("add '%s'", path); free_return: - if (p != path) + if (p < path || p > path + strlen(path)) free((char*)p); } @@ -594,7 +594,7 @@ static int do_unresolve(int ac, const char **av, const char *arg = av[i]; const char *p = prefix_path(prefix, prefix_length, arg); err |= unresolve_one(p); - if (p != arg) + if (p < arg || p > arg + strlen(arg)) free((char*)p); } return err; @@ -750,7 +750,7 @@ int main(int argc, const char **argv) update_one(p, NULL, 0); if (set_executable_bit) chmod_path(set_executable_bit, p); - if (p != path_name) + if (p < path_name || p > path_name + strlen(path_name)) free((char*) p); if (path_name != buf.buf) free(path_name); -- cgit v1.2.1