@matheusbsbs / matheus-bagliano / commits / a0db0d61fb
Fork 0

git-gui: Generate blame on uncommitted working tree file

If the user doesn't give us a revision parameter to our blame subcommand then we can generate blame against the working tree file by passing the file path off to blame with the --contents argument. In this case we cannot obtain the contents of the file from the ODB; instead we must obtain the contents by reading the working directory file as-is. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed May 8, 2007 at 22:48 UTC a0db0d61fbc447f13cb0aadf01c83eb193b22dc9
2 files changed +25 -11
git-gui.sh
+12 -8
@@ -1605,6 +1605,7 @@ browser {
1605 }
1606 blame {
1607 set subcommand_args {rev? path?}
1608 + set head {}
1609 set path {}
1610 set is_path 0
1611 foreach a $argv {
@@ -1614,27 +1615,30 @@ blame {
1615 break
1616 } elseif {$a eq {--}} {
1617 if {$path ne {}} {
1617 - if {$current_branch ne {}} usage
1618 - set current_branch $path
1618 + if {$head ne {}} usage
1619 + set head $path
1620 set path {}
1621 }
1622 set is_path 1
1622 - } elseif {$current_branch eq {}} {
1623 - if {$current_branch ne {}} usage
1624 - set current_branch $a
1623 + } elseif {$head eq {}} {
1624 + if {$head ne {}} usage
1625 + set head $a
1626 } else {
1627 usage
1628 }
1629 }
1630 unset is_path
1631
1631 - if {$current_branch eq {} && $path ne {}} {
1632 + if {$head eq {}} {
1633 set current_branch [git symbolic-ref HEAD]
1634 regsub ^refs/((heads|tags|remotes)/)? \
1635 $current_branch {} current_branch
1636 + } else {
1637 + set current_branch $head
1638 }
1636 - if {$current_branch eq {} || $path eq {}} usage
1637 - blame::new $current_branch $path
1639 +
1640 + if {$path eq {}} usage
1641 + blame::new $head $path
1642 return
1643 }
1644 citool -
lib/blame.tcl
+13 -3
@@ -170,8 +170,12 @@ constructor new {i_commit i_path} {
170 bind $top <Visibility> "focus $top"
171 bind $top <Destroy> [list delete_this $this]
172
173 - set cmd [list git cat-file blob "$commit:$path"]
174 - set fd [open "| $cmd" r]
173 + if {$commit eq {}} {
174 + set fd [open $path r]
175 + } else {
176 + set cmd [list git cat-file blob "$commit:$path"]
177 + set fd [open "| $cmd" r]
178 + }
179 fconfigure $fd -blocking 0 -translation lf -encoding binary
180 fileevent $fd readable [cb _read_file $fd]
181 }
@@ -194,7 +198,13 @@ method _read_file {fd} {
198 if {[eof $fd]} {
199 close $fd
200 _status $this
197 - set cmd [list git blame -M -C --incremental $commit -- $path]
201 + set cmd [list git blame -M -C --incremental]
202 + if {$commit eq {}} {
203 + lappend cmd --contents $path
204 + } else {
205 + lappend cmd $commit
206 + }
207 + lappend cmd -- $path
208 set fd [open "| $cmd" r]
209 fconfigure $fd -blocking 0 -translation lf -encoding binary
210 fileevent $fd readable [cb _read_blame $fd]