@@ -1837,6 +1837,16 @@ static int read_ancestry(const char *graft_file)
1837
1837
return 0 ;
1838
1838
}
1839
1839
1840
+ static int update_auto_abbrev (int auto_abbrev , struct origin * suspect )
1841
+ {
1842
+ const char * uniq = find_unique_abbrev (suspect -> commit -> object .sha1 ,
1843
+ auto_abbrev );
1844
+ int len = strlen (uniq );
1845
+ if (auto_abbrev < len )
1846
+ return len ;
1847
+ return auto_abbrev ;
1848
+ }
1849
+
1840
1850
/*
1841
1851
* How many columns do we need to show line numbers, authors,
1842
1852
* and filenames?
@@ -1847,12 +1857,16 @@ static void find_alignment(struct scoreboard *sb, int *option)
1847
1857
int longest_dst_lines = 0 ;
1848
1858
unsigned largest_score = 0 ;
1849
1859
struct blame_entry * e ;
1860
+ int compute_auto_abbrev = (abbrev < 0 );
1861
+ int auto_abbrev = default_abbrev ;
1850
1862
1851
1863
for (e = sb -> ent ; e ; e = e -> next ) {
1852
1864
struct origin * suspect = e -> suspect ;
1853
1865
struct commit_info ci ;
1854
1866
int num ;
1855
1867
1868
+ if (compute_auto_abbrev )
1869
+ auto_abbrev = update_auto_abbrev (auto_abbrev , suspect );
1856
1870
if (strcmp (suspect -> path , sb -> path ))
1857
1871
* option |= OUTPUT_SHOW_NAME ;
1858
1872
num = strlen (suspect -> path );
@@ -1880,6 +1894,10 @@ static void find_alignment(struct scoreboard *sb, int *option)
1880
1894
max_orig_digits = decimal_width (longest_src_lines );
1881
1895
max_digits = decimal_width (longest_dst_lines );
1882
1896
max_score_digits = decimal_width (largest_score );
1897
+
1898
+ if (compute_auto_abbrev )
1899
+ /* one more abbrev length is needed for the boundary commit */
1900
+ abbrev = auto_abbrev + 1 ;
1883
1901
}
1884
1902
1885
1903
/*
@@ -2353,10 +2371,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2353
2371
parse_done :
2354
2372
argc = parse_options_end (& ctx );
2355
2373
2356
- if (abbrev == -1 )
2357
- abbrev = default_abbrev ;
2358
- /* one more abbrev length is needed for the boundary commit */
2359
- abbrev ++ ;
2374
+ if (0 < abbrev )
2375
+ /* one more abbrev length is needed for the boundary commit */
2376
+ abbrev ++ ;
2360
2377
2361
2378
if (revs_file && read_ancestry (revs_file ))
2362
2379
die_errno ("reading graft file '%s' failed" , revs_file );
0 commit comments