git-gui: Unabbreviate commit SHA-1s prior to display
If the end-user feeds us an abbreviated SHA-1 on the command line for `git gui browser` or `git gui blame` we now unabbreviate the value through `git rev-parse` so that the title section of the blame or browser window shows the user the complete SHA-1 as Git determined it to be. If the abbreviated value was ambiguous we now complain with the standard error message(s) as reported by git-rev-parse --verify, so that the user can understand what might be wrong and correct their command line. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jul 8, 2007 at 21:19 UTC
02087abccea681bc0e1f6a9607e97df79ebbf2d9
1 file changed
+20
-1
git-gui.sh
+20
-1
@@ -1746,7 +1746,18 @@ browser {
1746
set subcommand_args {rev?}
1747
switch [llength $argv] {
1748
0 { load_current_branch }
1749
- 1 { set current_branch [lindex $argv 0] }
1749
+ 1 {
1750
+ set current_branch [lindex $argv 0]
1751
+ if {[regexp {^[0-9a-f]{1,39}$} $current_branch]} {
1752
+ if {[catch {
1753
+ set current_branch \
1754
+ [git rev-parse --verify $current_branch]
1755
+ } err]} {
1756
+ puts stderr $err
1757
+ exit 1
1758
+ }
1759
+ }
1760
+ }
1761
default usage
1762
}
1763
browser::new $current_branch
@@ -1781,6 +1792,14 @@ blame {
1792
if {$head eq {}} {
1793
load_current_branch
1794
} else {
1795
+ if {[regexp {^[0-9a-f]{1,39}$} $head]} {
1796
+ if {[catch {
1797
+ set head [git rev-parse --verify $head]
1798
+ } err]} {
1799
+ puts stderr $err
1800
+ exit 1
1801
+ }
1802
+ }
1803
set current_branch $head
1804
}
1805