Skip to content

Commit

Permalink
feat(routers): support gitweb such as git.samba.org (#149)
Browse files Browse the repository at this point in the history
feat(parser): support `git.samba.org/samba.git`

feat(routers): support prioritized matching list (undocumented hidden feature)

perf(test): improve unit tests to cover more use cases
  • Loading branch information
linrongbin16 authored Nov 24, 2023
1 parent dd7fdd1 commit d1d2482
Show file tree
Hide file tree
Showing 9 changed files with 874 additions and 174 deletions.
10 changes: 9 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
- [ ] macOS
- [ ] linux

## Tasks
## Hosts

- [ ] Test on [github.com](https://github.com).
- [ ] Test on [gitlab.com](https://gitlab.com).
- [ ] Test on [bitbucket.org](https://bitbucket.org).
- [ ] Test on [codeberg.org](https://codeberg.org).
- [ ] Test on [git.samba.org](https://git.samba.org).

## Functions

- [ ] Use `GitLink` to copy git link.
- [ ] Use `GitLink!` to open git link in browser.
Expand Down
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ For now supported platforms are:
- [gitlab.com](https://gitlab.com/)
- [bitbucket.org](https://bitbucket.org/)
- [codeberg.org](https://codeberg.org/)
- [git.samba.org](https://git.samba.org/)

PRs are welcomed for other git host websites!

Expand All @@ -38,6 +39,7 @@ PRs are welcomed for other git host websites!
- [Highlighting](#highlighting)
- [Self-host Git Hosts](#self-host-git-hosts)
- [Fully Customize Urls](#fully-customize-urls)
- [GitWeb](#gitweb)
- [Highlight Group](#highlight-group)
- [Development](#development)
- [Contribute](#contribute)
Expand Down Expand Up @@ -208,6 +210,14 @@ require('gitlinker').setup({
.. "{(string.len(_A.FILE) >= 3 and _A.FILE:sub(#_A.FILE-2) == '.md') and '?display=source' or ''}" -- '?display=source'
.. "#L{_A.LSTART}"
.. "{(_A.LEND > _A.LSTART and ('-L' .. _A.LEND) or '')}",
-- example:
-- main repo: https://git.samba.org/?p=samba.git;a=blob;f=wscript;hb=83e8971c0f1c1db8c3574f83107190ac1ac23db0#l6
-- dev repo: https://git.samba.org/?p=bbaumbach/samba.git;a=blob;f=wscript;hb=8de348e9d025d336a7985a9025fe08b7096c0394#l7
["^git%.samba%.org"] = "https://git.samba.org/?"
.. "p={string.len(_A.REPO) == 0 and _A.USER or (_A.USER .. '/' .. _A.REPO .. '.git')};a=blob;" -- 'p=samba.git' or 'p=bbaumbach/samba.git'
.. "f={_A.FILE};"
.. "hb={_A.REV}"
.. "#l{_A.LSTART}",
},
blame = {
-- example: https://github.com/linrongbin16/gitlinker.nvim/blame/9679445c7a24783d27063cd65f525f02def5f128/lua/gitlinker.lua#L3-L4
Expand Down Expand Up @@ -294,12 +304,13 @@ require('gitlinker').setup({
})
```

There're 3 groups of builtin APIs you can directly use:
You can directly use below builtin APIs:

- `github_browse`/`github_blame`: for [github.com](https://github.com/).
- `gitlab_browse`/`gitlab_blame`: for [gitlab.com](https://gitlab.com/).
- `bitbucket_browse`/`bitbucket_blame`: for [bitbucket.org](https://bitbucket.org/).
- `codeberg_browse`/`codeberg_blame`: for [codeberg.org](https://codeberg.org/).
- `samba_browse`: for [git.samba.org](https://git.samba.org/) (blame not support).

### Fully Customize Urls

Expand Down Expand Up @@ -385,11 +396,44 @@ The available variables are the same with the `lk` parameter passing to hook fun
- `_A.HOST`: `github.com`, `gitlab.com`, `bitbucket.org`, etc.
- `_A.USER`: `linrongbin16` (for this plugin), `neovim` (for [neovim](https://github.com/neovim/neovim)), etc.
- `_A.REPO`: `gitlinker.nvim`, `neovim`, etc.
- **Note: for easier writing, the `.git` suffix has been removed.**
- **Note:** for easier writing, the `.git` suffix has been removed.
- `_A.REV`: git commit, e.g. `dbf3922382576391fbe50b36c55066c1768b08b6`.
- `_A.FILE`: file name, e.g. `lua/gitlinker/routers.lua`.
- `_A.LSTART`/`_A.LEND`: start/end line numbers, e.g. `#L37-L156`.

### GitWeb

For [GitWeb](https://git-scm.com/book/en/v2/Git-on-the-Server-GitWeb), there're two types of urls: the main repository and the user's dev repository. For example on [git.samba.org](https://git.samba.org/):

- Main repo: https://git.samba.org/?p=samba.git;a=blob;f=wscript;hb=83e8971c0f1c1db8c3574f83107190ac1ac23db0#l7.
- User's dev repo: https://git.samba.org/?p=bbaumbach/samba.git;a=blob;f=wscript;hb=8de348e9d025d336a7985a9025fe08b7096c0394#l7.

Take a closer look at them:

```bash
# main repo
https://git.samba.org/?p=samba.git;a=blob;f=wscript;hb=83e8971c0f1c1db8c3574f83107190ac1ac23db0#l7
| | | | | |
protocol host repo file rev line number

# user dev repo
https://git.samba.org/?p=bbaumbach/samba.git;a=blob;f=wscript;hb=8de348e9d025d336a7985a9025fe08b7096c0394#l7
| | | | | | |
protocol host user repo file rev line number
```

> Also see difference between `h` and `hb` in gitweb url:
>
> 1. https://stackoverflow.com/q/14444593/4438921.
> 2. https://stackoverflow.com/a/14444767/4438921.
The difference is: the main repo doesn't have the `user` component, it's just `https://git.samba.org/?p=samba.git`. To support such case, `user` and `repo` components have a little bit different:

- `lk.user` (`_A.USER`): the value is `samba.git`.
- `lk.repo` (`_A.REPO`): the value is `` (empty string).

> Actually it should be more likely the `lk.user` is empty string, and `lk.repo` is `samba.git`, but I'm just parsing it in this way.
## Highlight Group

| Highlight Group | Default Group | Description |
Expand Down
Loading

0 comments on commit d1d2482

Please sign in to comment.