Skip to content

Commit 8e5efb8

Browse files
committed
Adjust to cgit
1 parent b73a8e9 commit 8e5efb8

21 files changed

+689
-1206
lines changed

COPYING.txt

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
Creative Commons Legal Code
2+
3+
CC0 1.0 Universal
4+
5+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12+
HEREUNDER.
13+
14+
Statement of Purpose
15+
16+
The laws of most jurisdictions throughout the world automatically confer
17+
exclusive Copyright and Related Rights (defined below) upon the creator
18+
and subsequent owner(s) (each and all, an "owner") of an original work of
19+
authorship and/or a database (each, a "Work").
20+
21+
Certain owners wish to permanently relinquish those rights to a Work for
22+
the purpose of contributing to a commons of creative, cultural and
23+
scientific works ("Commons") that the public can reliably and without fear
24+
of later claims of infringement build upon, modify, incorporate in other
25+
works, reuse and redistribute as freely as possible in any form whatsoever
26+
and for any purposes, including without limitation commercial purposes.
27+
These owners may contribute to the Commons to promote the ideal of a free
28+
culture and the further production of creative, cultural and scientific
29+
works, or to gain reputation or greater distribution for their Work in
30+
part through the use and efforts of others.
31+
32+
For these and/or other purposes and motivations, and without any
33+
expectation of additional consideration or compensation, the person
34+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35+
is an owner of Copyright and Related Rights in the Work, voluntarily
36+
elects to apply CC0 to the Work and publicly distribute the Work under its
37+
terms, with knowledge of his or her Copyright and Related Rights in the
38+
Work and the meaning and intended legal effect of CC0 on those rights.
39+
40+
1. Copyright and Related Rights. A Work made available under CC0 may be
41+
protected by copyright and related or neighboring rights ("Copyright and
42+
Related Rights"). Copyright and Related Rights include, but are not
43+
limited to, the following:
44+
45+
i. the right to reproduce, adapt, distribute, perform, display,
46+
communicate, and translate a Work;
47+
ii. moral rights retained by the original author(s) and/or performer(s);
48+
iii. publicity and privacy rights pertaining to a person's image or
49+
likeness depicted in a Work;
50+
iv. rights protecting against unfair competition in regards to a Work,
51+
subject to the limitations in paragraph 4(a), below;
52+
v. rights protecting the extraction, dissemination, use and reuse of data
53+
in a Work;
54+
vi. database rights (such as those arising under Directive 96/9/EC of the
55+
European Parliament and of the Council of 11 March 1996 on the legal
56+
protection of databases, and under any national implementation
57+
thereof, including any amended or successor version of such
58+
directive); and
59+
vii. other similar, equivalent or corresponding rights throughout the
60+
world based on applicable law or treaty, and any national
61+
implementations thereof.
62+
63+
2. Waiver. To the greatest extent permitted by, but not in contravention
64+
of, applicable law, Affirmer hereby overtly, fully, permanently,
65+
irrevocably and unconditionally waives, abandons, and surrenders all of
66+
Affirmer's Copyright and Related Rights and associated claims and causes
67+
of action, whether now known or unknown (including existing as well as
68+
future claims and causes of action), in the Work (i) in all territories
69+
worldwide, (ii) for the maximum duration provided by applicable law or
70+
treaty (including future time extensions), (iii) in any current or future
71+
medium and for any number of copies, and (iv) for any purpose whatsoever,
72+
including without limitation commercial, advertising or promotional
73+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74+
member of the public at large and to the detriment of Affirmer's heirs and
75+
successors, fully intending that such Waiver shall not be subject to
76+
revocation, rescission, cancellation, termination, or any other legal or
77+
equitable action to disrupt the quiet enjoyment of the Work by the public
78+
as contemplated by Affirmer's express Statement of Purpose.
79+
80+
3. Public License Fallback. Should any part of the Waiver for any reason
81+
be judged legally invalid or ineffective under applicable law, then the
82+
Waiver shall be preserved to the maximum extent permitted taking into
83+
account Affirmer's express Statement of Purpose. In addition, to the
84+
extent the Waiver is so judged Affirmer hereby grants to each affected
85+
person a royalty-free, non transferable, non sublicensable, non exclusive,
86+
irrevocable and unconditional license to exercise Affirmer's Copyright and
87+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
88+
maximum duration provided by applicable law or treaty (including future
89+
time extensions), (iii) in any current or future medium and for any number
90+
of copies, and (iv) for any purpose whatsoever, including without
91+
limitation commercial, advertising or promotional purposes (the
92+
"License"). The License shall be deemed effective as of the date CC0 was
93+
applied by Affirmer to the Work. Should any part of the License for any
94+
reason be judged legally invalid or ineffective under applicable law, such
95+
partial invalidity or ineffectiveness shall not invalidate the remainder
96+
of the License, and in such case Affirmer hereby affirms that he or she
97+
will not (i) exercise any of his or her remaining Copyright and Related
98+
Rights in the Work or (ii) assert any associated claims and causes of
99+
action with respect to the Work, in either case contrary to Affirmer's
100+
express Statement of Purpose.
101+
102+
4. Limitations and Disclaimers.
103+
104+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
105+
surrendered, licensed or otherwise affected by this document.
106+
b. Affirmer offers the Work as-is and makes no representations or
107+
warranties of any kind concerning the Work, express, implied,
108+
statutory or otherwise, including without limitation warranties of
109+
title, merchantability, fitness for a particular purpose, non
110+
infringement, or the absence of latent or other defects, accuracy, or
111+
the present or absence of errors, whether or not discoverable, all to
112+
the greatest extent permissible under applicable law.
113+
c. Affirmer disclaims responsibility for clearing rights of other persons
114+
that may apply to the Work or any use thereof, including without
115+
limitation any person's Copyright and Related Rights in the Work.
116+
Further, Affirmer disclaims responsibility for obtaining any necessary
117+
consents, permissions or other rights required for any use of the
118+
Work.
119+
d. Affirmer understands and acknowledges that Creative Commons is not a
120+
party to this document and has no duty or obligation with respect to
121+
this CC0 or use of the Work.
File renamed without changes.

README.md

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,70 @@
1-
# fugitive-gitlab.vim
1+
# fugitive-cgit.vim
22

3-
[![Fugitive GitLab](https://github.com/shumphrey/fugitive-gitlab.vim/actions/workflows/vader.yml/badge.svg?branch=master)](https://github.com/shumphrey/fugitive-gitlab.vim/actions/workflows/vader.yml)
3+
[![Fugitive cgit](https://github.com/sudotac/fugitive-cgit.vim/actions/workflows/vader.yml/badge.svg?branch=master)](https://github.com/sudotac/fugitive-cgit.vim/actions/workflows/vader.yml)
44

55
[fugitive.vim][] is undoubtedly the best Git wrapper of all time.
66

7-
This plugin allows you to use it with https://gitlab.com or your own
8-
private GitLab instance.
7+
This plugin allows you to use it with a cgit instance.
98

10-
* Enables `:GBrowse` from fugitive.vim to open GitLab URLs
11-
12-
* In commit messages, GitLab issues and users can be omni-completed
13-
(`<C-X><C-O>`, see `:help compl-omni`).
9+
* Enables `:GBrowse` from fugitive.vim to open cgit URLs
1410

1511
## Installation
1612

1713
Install it as you would install [fugitive.vim][]
1814
(you will also need [fugitive.vim][] installed)
1915

20-
To use private GitLab instances, add the following to your .vimrc
16+
To use cgit instances, add the following to your .vimrc
2117

22-
let g:fugitive_gitlab_domains = ['https://my.gitlab.com']
18+
let g:fugitive_cgit_domains = ['https://git.example.com']
2319

24-
If the private GitLab instance uses different URLs, for example, one for SSH
25-
and another for HTTPS, instead add the following to your .vimrc
20+
If the cgit instance uses different URLs, for example, one for SSH and another
21+
for HTTPS, instead add the following to your .vimrc
2622

27-
let g:fugitive_gitlab_domains = {'ssh://my-ssh.gitlab.com': 'https://my.gitlab.com'}
23+
let g:fugitive_cgit_domains = {'ssh://git.example.com': 'https://git.example.com'}
2824

29-
Fugitive command `:GBrowse` will now work with GitLab URLs.
25+
Fugitive command `:GBrowse` will now work with cgit URLs.
3026

31-
[Curl](http://curl.haxx.se/) is required for features
32-
that use the GitLab API (i.e., `:GBrowse` doesn't need it).
33-
[Generate a personal access token](https://gitlab.com/profile/personal_access_tokens)
34-
with api permissions and add it to your vimrc
27+
If you need more complicated configuration, please refer to
28+
`:help fugitive-cgit-config` for more details.
3529

36-
let g:gitlab_api_keys = {'gitlab.com': 'myaccesstoken'}
30+
## Requirements
3731

38-
To use omnicompletion with a private GitLab repository
32+
fugitive-cgit.vim requires a modern [fugitive.vim][].
3933

40-
let g:gitlab_api_keys = {'gitlab.com': 'mytoken1', 'my.gitlab.private': 'mytoken2' }
34+
[fugitive.vim]: https://github.com/tpope/vim-fugitive
4135

42-
Omnicompletion functionality is subject to change.
36+
## Examples
4337

44-
## Requirements
38+
### Linux kernel git repository
4539

46-
fugitive-gitlab.vim requires a modern [fugitive.vim][].
47-
API features require a GitLab instance with v4 of the API.
40+
```vim
41+
let g:fugitive_cgit_domains = ['https://git.kernel.org']
42+
```
4843

49-
[fugitive.vim]: https://github.com/tpope/vim-fugitive
44+
### ZX2C4 Git Repository
5045

51-
## FAQ
46+
```vim
47+
let g:fugitive_cgit_domains = {
48+
\ 'https://git.zx2c4.com': {
49+
\ 'root': 'https://git.zx2c4.com',
50+
\ 'remove-git-suffix': v:true
51+
\ }
52+
\ }
53+
```
5254

53-
> How do I turn off that preview window that shows the issue body?
55+
### GNU's Savannah
5456

55-
set completeopt-=preview
57+
```vim
58+
let g:fugitive_cgit_domains = {
59+
\ 'https://git.savannah.gnu.org': {
60+
\ 'root': 'https://git.savannah.gnu.org/cgit',
61+
\ 'prefix': 'git'
62+
\ }
63+
\ }
64+
```
65+
66+
## FAQ
5667

5768
> Why doesn't this plugin have a pun name?
5869
59-
I couldn't think of one.
70+
I couldn't think of one, either.

autoload/README

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11

2-
" autoload/gitlab/fugitive.vim - stuff relating to fugitive, e.g. :GBrowse
3-
" autoload/gitlab/api.vim - stuff relating to gitlab api
4-
" autoload/gitlab/omnifunc.vim - stuff relating to gitlab omnifunc
5-
" autoload/gitlab/utils.vim - shared utilities
2+
" autoload/cgit/fugitive.vim - stuff relating to fugitive, e.g. :GBrowse
3+
" autoload/cgit/utils.vim - shared utilities

autoload/cgit/fugitive.vim

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
if exists('g:autoloaded_fugitive_cgit_fugitive')
2+
finish
3+
endif
4+
let g:autoloaded_fugitive_cgit_fugitive = 1
5+
6+
function! cgit#fugitive#handler(opts, ...)
7+
let path = substitute(get(a:opts, 'path', ''), '^/', '', '')
8+
let commit = get(a:opts, 'commit')
9+
let type = get(a:opts, 'type')
10+
let line1 = get(a:opts, 'line1')
11+
let line2 = get(a:opts, 'line2')
12+
let remote = get(a:opts, 'remote')
13+
14+
let root = cgit#fugitive#homepage_for_remote(remote)
15+
if empty(root)
16+
return ''
17+
endif
18+
19+
" work out what branch/commit/tag/etc we're on
20+
" if file is a git/ref, we can go to a /commit cgit url
21+
" If the branch/tag doesn't exist upstream, the URL won't be valid
22+
" Could check upstream refs?
23+
if path =~# '^\.git/refs/heads/'
24+
return root . '/log/' . path[16:-1]
25+
elseif path =~# '^\.git/refs/tags/'
26+
return root . '/tag/?h=' . path[15:-1]
27+
elseif path =~# '^\.git/refs/.'
28+
return root . '/commit/' . path[10:-1]
29+
elseif path =~# '^\.git\>'
30+
return root
31+
endif
32+
33+
" check if 'commit' is actually commit-id or not.
34+
" FIXME: cannot handle the branch name which consists of 40 character hex string.
35+
" It's technically possible, though I haven't seen such a branch name...
36+
if commit =~# '^\x\{40\}'
37+
let key = 'id'
38+
else
39+
let key = 'h'
40+
endif
41+
42+
if type ==# 'tree' || path =~# '/$'
43+
let path = substitute(path, '/$', '', '')
44+
let dir = 'tree'
45+
elseif type ==# 'blob' || path =~# '[^/]$'
46+
let dir = 'tree'
47+
else
48+
let dir = 'commit'
49+
endif
50+
51+
" NOTE: Range selection is not supported in cgit
52+
return root.'/'.dir.'/'.path.'?'.key.'='.commit.(line2 ? '#n'.line1 : '')
53+
endfunction
54+
55+
function! cgit#fugitive#homepage_for_remote(url) abort
56+
let domains = cgit#utils#parse_cgit_domains()
57+
58+
" https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols
59+
" [full_url, scheme, host_with_port, host, path]
60+
" NOTE: In cgit, '.git' suffix should be preserved as-is.
61+
if a:url =~# '://'
62+
let match = matchlist(a:url, '^\(https\=://\|git://\|ssh://\)\%([^@/]\+@\)\=\(\([^/:]\+\)\%(:\d\+\)\=\)\(.\{-\}\%(\.git\)\=\)/\=$')
63+
else
64+
let match = matchlist(a:url, '^\([^@/]\+@\)\=\(\([^:/]\+\)\):\(.\{-\}\%(\.git\)\=\)/\=$')
65+
if empty(match)
66+
return ''
67+
endif
68+
let match[1] = 'ssh://'
69+
endif
70+
71+
if empty(match)
72+
return ''
73+
elseif has_key(domains, match[1] . match[2])
74+
let key = match[1] . match[2]
75+
elseif has_key(domains, match[1] . match[3])
76+
let key = match[1] . match[3]
77+
elseif has_key(domains, match[2])
78+
let key = match[2]
79+
elseif has_key(domains, match[3])
80+
let key = match[3]
81+
else
82+
return ''
83+
endif
84+
85+
let root = get(domains[key], 'root')
86+
if empty(root)
87+
return ''
88+
elseif root !~# '://'
89+
let root = (match[1] =~# '^http://' ? 'http://' : 'https://') . root
90+
endif
91+
92+
let path = match[4]
93+
if get(domains[key], 'remove-git-suffix')
94+
let path = substitute(path, '\.git$', '', '')
95+
endif
96+
97+
let prefix = get(domains[key], 'prefix')
98+
if type(prefix) == type('') && !empty(prefix) && strpart(path, 0, strlen(prefix)) == prefix
99+
let path = strpart(path, strlen(prefix))
100+
endif
101+
return substitute(root, '/\+$', '', '') . '/' . substitute(path, '^/\+', '', '')
102+
endfunction
103+
104+
" vim: set ts=4 sw=4 et foldmethod=indent foldnestmax=1 :

autoload/cgit/utils.vim

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
if exists('g:autoloaded_fugitive_cgit_utils')
2+
finish
3+
endif
4+
let g:autoloaded_fugitive_cgit_utils = 1
5+
6+
function! cgit#utils#throw(string) abort
7+
let v:errmsg = 'cgit: '.a:string
8+
throw v:errmsg
9+
endfunction
10+
11+
function! cgit#utils#parse_cgit_domains() abort
12+
let dict_or_list = get(g:, 'fugitive_cgit_domains', {})
13+
let domains = {} " no pre-defined domains
14+
15+
if type(dict_or_list) == type([])
16+
for domain in dict_or_list
17+
let lhs = substitute(substitute(domain, '^.\{-\}://', '', ''), '/.*', '', '')
18+
let domains[lhs] = {'root': domain}
19+
endfor
20+
elseif type(dict_or_list) == type({})
21+
for [key, val] in items(dict_or_list)
22+
if type(val) == type('')
23+
let domains[key] = {'root': val}
24+
elseif type(val) == type({})
25+
if !has_key(val, 'root')
26+
call cgit#utils#throw($"g:fugitive_cgit_domains['{key}']['root'] is required")
27+
endif
28+
let domains[key] = val
29+
else
30+
call cgit#utils#throw($"g:fugitive_cgit_domains['{key}'] should be a string or a dictionary")
31+
endif
32+
endfor
33+
endif
34+
return domains
35+
endfunction
36+
37+
" vim: set ts=4 sw=4 et foldmethod=indent foldnestmax=1 :

0 commit comments

Comments
 (0)