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>
This commit is contained in:
parent
3e45ee1ef2
commit
a0db0d61fb
20
git-gui.sh
20
git-gui.sh
@ -1605,6 +1605,7 @@ browser {
|
|||||||
}
|
}
|
||||||
blame {
|
blame {
|
||||||
set subcommand_args {rev? path?}
|
set subcommand_args {rev? path?}
|
||||||
|
set head {}
|
||||||
set path {}
|
set path {}
|
||||||
set is_path 0
|
set is_path 0
|
||||||
foreach a $argv {
|
foreach a $argv {
|
||||||
@ -1614,27 +1615,30 @@ blame {
|
|||||||
break
|
break
|
||||||
} elseif {$a eq {--}} {
|
} elseif {$a eq {--}} {
|
||||||
if {$path ne {}} {
|
if {$path ne {}} {
|
||||||
if {$current_branch ne {}} usage
|
if {$head ne {}} usage
|
||||||
set current_branch $path
|
set head $path
|
||||||
set path {}
|
set path {}
|
||||||
}
|
}
|
||||||
set is_path 1
|
set is_path 1
|
||||||
} elseif {$current_branch eq {}} {
|
} elseif {$head eq {}} {
|
||||||
if {$current_branch ne {}} usage
|
if {$head ne {}} usage
|
||||||
set current_branch $a
|
set head $a
|
||||||
} else {
|
} else {
|
||||||
usage
|
usage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset is_path
|
unset is_path
|
||||||
|
|
||||||
if {$current_branch eq {} && $path ne {}} {
|
if {$head eq {}} {
|
||||||
set current_branch [git symbolic-ref HEAD]
|
set current_branch [git symbolic-ref HEAD]
|
||||||
regsub ^refs/((heads|tags|remotes)/)? \
|
regsub ^refs/((heads|tags|remotes)/)? \
|
||||||
$current_branch {} current_branch
|
$current_branch {} current_branch
|
||||||
|
} else {
|
||||||
|
set current_branch $head
|
||||||
}
|
}
|
||||||
if {$current_branch eq {} || $path eq {}} usage
|
|
||||||
blame::new $current_branch $path
|
if {$path eq {}} usage
|
||||||
|
blame::new $head $path
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
citool -
|
citool -
|
||||||
|
@ -170,8 +170,12 @@ constructor new {i_commit i_path} {
|
|||||||
bind $top <Visibility> "focus $top"
|
bind $top <Visibility> "focus $top"
|
||||||
bind $top <Destroy> [list delete_this $this]
|
bind $top <Destroy> [list delete_this $this]
|
||||||
|
|
||||||
|
if {$commit eq {}} {
|
||||||
|
set fd [open $path r]
|
||||||
|
} else {
|
||||||
set cmd [list git cat-file blob "$commit:$path"]
|
set cmd [list git cat-file blob "$commit:$path"]
|
||||||
set fd [open "| $cmd" r]
|
set fd [open "| $cmd" r]
|
||||||
|
}
|
||||||
fconfigure $fd -blocking 0 -translation lf -encoding binary
|
fconfigure $fd -blocking 0 -translation lf -encoding binary
|
||||||
fileevent $fd readable [cb _read_file $fd]
|
fileevent $fd readable [cb _read_file $fd]
|
||||||
}
|
}
|
||||||
@ -194,7 +198,13 @@ method _read_file {fd} {
|
|||||||
if {[eof $fd]} {
|
if {[eof $fd]} {
|
||||||
close $fd
|
close $fd
|
||||||
_status $this
|
_status $this
|
||||||
set cmd [list git blame -M -C --incremental $commit -- $path]
|
set cmd [list git blame -M -C --incremental]
|
||||||
|
if {$commit eq {}} {
|
||||||
|
lappend cmd --contents $path
|
||||||
|
} else {
|
||||||
|
lappend cmd $commit
|
||||||
|
}
|
||||||
|
lappend cmd -- $path
|
||||||
set fd [open "| $cmd" r]
|
set fd [open "| $cmd" r]
|
||||||
fconfigure $fd -blocking 0 -translation lf -encoding binary
|
fconfigure $fd -blocking 0 -translation lf -encoding binary
|
||||||
fileevent $fd readable [cb _read_blame $fd]
|
fileevent $fd readable [cb _read_blame $fd]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user