diff --git a/autoload/magit/git.vim b/autoload/magit/git.vim index 5a75e22eb72f97f338284e695f006d63e8970cc4..3a5d9debdfd8031c121954a6b7623ccdd843312f 100644 --- a/autoload/magit/git.vim +++ b/autoload/magit/git.vim @@ -276,6 +276,42 @@ function! magit#git#git_unapply(header, selection, mode) endif endfunction +" magit#git#submodule_status: helper function to return the submodule status +" return submodule status function! magit#git#submodule_status() return system(g:magit_git_cmd . " submodule status") endfunction + +" magit#git#get_branch_name: get the branch name given a reference +" WARNING does not seem to work with SHA1 +" param[in] ref can be HEAD or a branch name +" return branch name +function! magit#git#get_branch_name(ref) + return magit#utils#strip(magit#utils#system(g:magit_git_cmd . " rev-parse --abbrev-ref " . a:ref)) +endfunction + +" magit#git#get_commit_subject: get the subject of a commit (first line) +" param[in] ref: reference, can be SHA1, brnach name or HEAD +" return commit subject +function! magit#git#get_commit_subject(ref) + silent let git_result=magit#utils#strip(magit#utils#system(g:magit_git_cmd . " show --no-patch --format=\"%s\" " . a:ref)) + if ( v:shell_error != 0 ) + return "" + endif + return git_result +endfunction + +" magit#git#get_remote_branch: get the branch name of the default remote, for +" upstream and push +" WARNING does not work with SHA1 +" param[in] ref: reference, can be HEAD or branch name +" param[in] type: type of default remote: upstream or push +" return the remote branch name, 'none' if it has not +function! magit#git#get_remote_branch(ref, type) + silent let git_result=magit#utils#strip(magit#utils#system( + \ g:magit_git_cmd . " rev-parse --abbrev-ref=loose " . a:ref . "@{" . a:type . "}")) + if ( v:shell_error != 0 ) + return "none" + endif + return git_result +endfunction diff --git a/common/magit_common.vim b/common/magit_common.vim index abfe32a23b4b90836330e461c69748fc489b5e58..f1f812371e6d69e0074b4b5edc8bdcc6b7d4cbd3 100644 --- a/common/magit_common.vim +++ b/common/magit_common.vim @@ -11,10 +11,11 @@ let g:magit_sections = { \ } let g:magit_section_info = { - \ 'cur_repo': 'Current repository', - \ 'cur_branch': 'Current branch', - \ 'cur_commit': 'Last commit', - \ 'commit_mode': 'Commit mode', + \ 'cur_repo': 'Repository:', + \ 'cur_head': 'Head:', + \ 'cur_upstream': 'Upstream:', + \ 'cur_push': 'Push:', + \ 'commit_mode': 'Commit mode:', \ } let g:magit_git_status_code = { diff --git a/plugin/magit.vim b/plugin/magit.vim index d08561c7767237b783b978c0a8d34fac8795bd14..d531c8d16c07e4a3dd83684be61f02333e299a48 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -52,22 +52,61 @@ if (g:magit_refresh_gutter == 1 || g:magit_refresh_gitgutter == 1) endif " }}} +" s:mg_cut_str cut a string given a limit size +" param[in] str string to cut +" param[in] limit maximum number of column +" return string cut on limit +function! s:mg_cut_str(str, limit) + if ( len(a:str) < a:limit ) + return a:str + elseif ( ( a:limit - 3 ) < 0 ) + return "" + else + return printf("%.*S...", a:limit - 3, a:str) + endif +endfunction " s:mg_get_info: this function writes in current buffer current git state " WARNING: this function writes in file, it should only be called through " protected functions like magit#update_buffer function! s:mg_get_info() + let align_w=12 + + let repo_line=printf("%-".align_w."S %s", + \ g:magit_section_info.cur_repo, + \ magit#git#top_dir() + \ ) + + let head_br=magit#git#get_branch_name("HEAD") + let upstream_br=magit#git#get_remote_branch("HEAD", "upstream") + let push_br=magit#git#get_remote_branch("HEAD", "push") + let max_br_w = max([len(head_br), len(upstream_br), len(push_br)]) + + let limit=winwidth(0)-align_w-max_br_w-3 + let head_msg=s:mg_cut_str(magit#git#get_commit_subject("HEAD"), limit) + let upstream_msg=s:mg_cut_str(magit#git#get_commit_subject(upstream_br), limit) + let push_msg=s:mg_cut_str(magit#git#get_commit_subject(push_br), limit) + + let head_line=printf("%-".align_w."S %-".max_br_w."S %s", + \ g:magit_section_info.cur_head, head_br, head_msg) + let upstream_line=printf("%-".align_w."S %-".max_br_w."S %s", + \ g:magit_section_info.cur_upstream, upstream_br, upstream_msg) + let push_line=printf("%-".align_w."S %-".max_br_w."S %s", + \ g:magit_section_info.cur_push, push_br, push_msg) + + silent put =g:magit_sections.info silent put =magit#utils#underline(g:magit_sections.info) silent put ='' - let branch=magit#utils#system(g:magit_git_cmd . " rev-parse --abbrev-ref HEAD") - let commit=magit#utils#system(g:magit_git_cmd . " show -s --oneline") - silent put =g:magit_section_info.cur_repo . ': ' . magit#git#top_dir() - silent put =g:magit_section_info.cur_branch . ': ' . branch - silent put =g:magit_section_info.cur_commit . ': ' . commit + silent put =repo_line + silent put =head_line + silent put =upstream_line + silent put =push_line + if ( b:magit_current_commit_mode != '' ) - silent put =g:magit_section_info.commit_mode . ': ' - \ . g:magit_commit_mode[b:magit_current_commit_mode] + let commit_mode_line=printf("%-".align_w."S %s", g:magit_section_info.commit_mode, + \ g:magit_commit_mode[b:magit_current_commit_mode]) + silent put =commit_mode_line endif silent put ='' silent put ='Press ? to display help' diff --git a/syntax/magit.vim b/syntax/magit.vim index 732c5d34c11044043374c2fbdfce7287d42a6883..6225e8765c18dee7612a34798f5bdcd7c2d26e5c 100644 --- a/syntax/magit.vim +++ b/syntax/magit.vim @@ -33,14 +33,18 @@ execute 'syn region gitHunk start=/' . \ g:magit_hunk_re . '/ end=/\%(' . g:magit_end_diff_re . '\|' . g:magit_hunk_re \ '\)\@=/ contains=@diff fold' -execute 'syn match gitInfoRepo "\%(' . g:magit_section_info.cur_repo . ':\)\@<=.*$" oneline' -execute 'syn match gitInfoBranch "\%(' . g:magit_section_info.cur_branch . ':\)\@<=.*$" oneline' -execute 'syn match gitCommitMode "\%(' . g:magit_section_info.commit_mode . ':\)\@<=.*$" oneline' -execute 'syn match gitInfoCommit "\%(' . g:magit_section_info.cur_commit . ':\)\@<=.*$" contains=infoSha1 oneline' -syntax match infoSha1 containedin=gitInfoCommit "\x\{7,}" +execute 'syn match gitInfoRepo "\%(' . g:magit_section_info.cur_repo . '\)\@<=.*$" oneline' +execute 'syn match gitInfoHead "\%(' . g:magit_section_info.cur_head . '\s*\)\@<=\S\+" oneline' +execute 'syn match gitInfoUpstream "\%(' . g:magit_section_info.cur_upstream . '\s*\)\@<=\S\+" oneline' +execute 'syn match gitInfoPush "\%(' . g:magit_section_info.cur_push . '\s*\)\@<=\S\+" oneline' +execute 'syn match gitCommitMode "\%(' . g:magit_section_info.commit_mode . '\)\@<=.*$" oneline' +"execute 'syn match gitInfoCommit "\%(' . g:magit_section_info.cur_commit . '\)\@<=.*$" contains=infoSha1 oneline' +"syntax match infoSha1 containedin=gitInfoCommit "\x\{7,}" highlight default link gitInfoRepo Directory -highlight default link gitInfoBranch Identifier +highlight default link gitInfoHead Identifier +highlight default link gitInfoUpstream Identifier +highlight default link gitInfoPush Identifier highlight default link gitCommitMode Special highlight default link infoSha1 Identifier