81
81
endfunction
82
82
endif
83
83
84
- let s: git_dirs = {}
85
84
86
- function ! s: update_git_branch (path )
85
+ " Fugitive special revisions. call '0' "staging" ?
86
+ let s: names = {' 0' : ' index' , ' 1' : ' ancestor' , ' 2' :' target' , ' 3' :' merged' }
87
+ let s: sha1size = get (g: , ' airline#extensions#branch#sha1_len' , 7 )
88
+
89
+ function ! s: update_git_branch ()
87
90
if ! s: has_fugitive
88
91
let s: vcs_config [' git' ].branch = ' '
89
92
return
90
93
endif
91
94
92
- let name = fugitive#head (7 )
93
- if empty (name)
94
- if has_key (s: git_dirs , a: path )
95
- let s: vcs_config [' git' ].branch = s: git_dirs [a: path ]
96
- return
97
- endif
95
+ let name = fugitive#head (s: sha1size )
98
96
99
- let dir = fugitive#extract_git_dir (a: path )
100
- if empty (dir )
101
- let name = ' '
102
- else
103
- try
104
- let line = join (readfile (dir . ' /HEAD' ))
105
- if strpart (line , 0 , 16 ) == ' ref: refs/heads/'
106
- let name = strpart (line , 16 )
107
- else
108
- " raw commit hash
109
- let name = strpart (line , 0 , 7 )
110
- endif
111
- catch
112
- let name = ' '
113
- endtry
97
+ try
98
+ let commit = fugitive#buffer ().commit ()
99
+
100
+ if has_key (s: names , commit)
101
+ let name = get (s: names , commit)." (" .name." )"
102
+ elseif ! empty (commit)
103
+ let ref = fugitive#repo ().git_chomp (' describe' , ' --all' , ' --exact-match' , commit)
104
+ if ref !~ " ^fatal: no tag exactly matches"
105
+ let name = s: format_name (substitute (ref, ' \v\C^%(heads/|remotes/|tags/)=' ,' ' ,' ' ))." (" .name." )"
106
+ else
107
+ let name = commit[0 :s: sha1size- 1 ]." (" .name." )"
108
+ endif
114
109
endif
115
- endif
110
+ catch
111
+ endtry
116
112
117
- let s: git_dirs [a: path ] = name
118
113
let s: vcs_config [' git' ].branch = name
119
114
endfunction
120
115
121
- function ! s: update_hg_branch (... )
122
- " path argument is not actually used, so we don't actually care about a:1
123
- " it is just needed, because update_git_branch needs it.
116
+ function ! s: update_hg_branch ()
124
117
if s: has_lawrencium
125
118
let cmd= ' LC_ALL=C hg qtop'
126
119
let stl = lawrencium#statusline ()
@@ -152,10 +145,8 @@ function! s:update_hg_branch(...)
152
145
endfunction
153
146
154
147
function ! s: update_branch ()
155
- let b: airline_fname_path = get (b: , ' airline_fname_path' ,
156
- \ exists (" *fnamemodify" ) ? fnamemodify (resolve (@% ), " :p:h" ) : expand (" %:p:h" ))
157
148
for vcs in keys (s: vcs_config )
158
- call {s: vcs_config [vcs].update_branch}(b: airline_fname_path )
149
+ call {s: vcs_config [vcs].update_branch}()
159
150
if b: buffer_vcs_config [vcs].branch != s: vcs_config [vcs].branch
160
151
let b: buffer_vcs_config [vcs].branch = s: vcs_config [vcs].branch
161
152
unlet ! b: airline_head
@@ -256,9 +247,6 @@ function! airline#extensions#branch#head()
256
247
endif
257
248
endif
258
249
259
- if has_key (heads, ' git' ) && ! s: check_in_path ()
260
- let b: airline_head = ' '
261
- endif
262
250
let minwidth = empty (get (b: , ' airline_hunks' , ' ' )) ? 14 : 7
263
251
let b: airline_head = airline#util#shorten (b: airline_head , 120 , minwidth)
264
252
return b: airline_head
@@ -273,35 +261,6 @@ function! airline#extensions#branch#get_head()
273
261
\ : printf (' %s%s' , empty (symbol) ? ' ' : symbol.(g: airline_symbols .space), head)
274
262
endfunction
275
263
276
- function ! s: check_in_path ()
277
- if ! exists (' b:airline_file_in_root' )
278
- let root = get (b: , ' git_dir' , get (b: , ' mercurial_dir' , ' ' ))
279
- let bufferpath = resolve (fnamemodify (expand (' %' ), ' :p' ))
280
-
281
- if ! filereadable (root) " not a file
282
- " if .git is a directory, it's the old submodule format
283
- if match (root, ' \.git$' ) >= 0
284
- let root = expand (fnamemodify (root, ' :h' ))
285
- else
286
- " else it's the newer format, and we need to guesstimate
287
- " 1) check for worktrees
288
- if match (root, ' worktrees' ) > -1
289
- " worktree can be anywhere, so simply assume true here
290
- return 1
291
- endif
292
- " 2) check for submodules
293
- let pattern = ' \.git[\\/]\(modules\)[\\/]'
294
- if match (root, pattern) >= 0
295
- let root = substitute (root, pattern, ' ' , ' ' )
296
- endif
297
- endif
298
- endif
299
-
300
- let b: airline_file_in_root = stridx (bufferpath, root) > -1
301
- endif
302
- return b: airline_file_in_root
303
- endfunction
304
-
305
264
function ! s: reset_untracked_cache (shellcmdpost )
306
265
" shellcmdpost - whether function was called as a result of ShellCmdPost hook
307
266
if ! g: airline #init#vim_async && ! has (' nvim' )
@@ -328,9 +287,8 @@ endfunction
328
287
function ! airline#extensions#branch#init (ext)
329
288
call airline#parts#define_function (' branch' , ' airline#extensions#branch#get_head' )
330
289
331
- autocmd BufReadPost * unlet ! b: airline_file_in_root
332
- autocmd ShellCmdPost ,CmdwinLeave * unlet ! b: airline_head b: airline_do_mq_check b: airline_fname_path
333
- autocmd User AirlineBeforeRefresh unlet ! b: airline_head b: airline_do_mq_check b: airline_fname_path
290
+ autocmd ShellCmdPost ,CmdwinLeave * unlet ! b: airline_head b: airline_do_mq_check
291
+ autocmd User AirlineBeforeRefresh unlet ! b: airline_head b: airline_do_mq_check
334
292
autocmd BufWritePost * call s: reset_untracked_cache (0 )
335
293
autocmd ShellCmdPost * call s: reset_untracked_cache (1 )
336
294
endfunction
0 commit comments