3

Projects like GNU and the Linux kernel don't use Gitlab or Github, they use cgit. For example, here's the 114th line of main.c for GNU make:

https://git.savannah.gnu.org/cgit/make.git/tree/src/main.c#n114

and here's the 1340th line of printk.c for the Linux kernel:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/printk/printk.c#n1340

The trouble is these URLs have no commit ID, so they are really a link to whatever is the current commit, not a permalink to a specific commit. So the line number could end up pointing to a completely different part of code or break completely if the file is renamed or removed. Better links would look like this instead:

https://git.savannah.gnu.org/cgit/make.git/tree/src/main.c?id=d7ff21ecd70bbf9dfda7b3a136b22f631cd80d22#n114

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/printk/printk.c?id=457c89965399115e5cd8bf38f9c597293405703d#n1340

Here's an example of a link to a file that doesn't exist in the current tree:

https://git.savannah.gnu.org/cgit/make.git/tree/INSTALL?id=6c9e53d64804a856580876f2019ce4ea1e42b4e0#n70

so I'm pretty sure these count as permalinks.

If I were using Gitlab or Github, just pressing the y key would give me a permalink. With cgit, I need to do this:

  1. Note the line number (write it down or copy it somewhere).

    https://git.savannah.gnu.org/cgit/make.git/tree/src/main.c#n114

  2. Click "log".

    https://git.savannah.gnu.org/cgit/make.git/log/src/main.c

  3. Find the most recent commit and click the commit message.

    [SV 46013] Allow recursive variable overrides from Makefiles

    https://git.savannah.gnu.org/cgit/make.git/commit/src/main.c?id=d7ff21ecd70bbf9dfda7b3a136b22f631cd80d22

  4. Click the link in the "tree" field that points to the actual file (the second link).

    tree 65d7554922d1bc9bebfa22ca30741f4d6cd4c8ca /src/main.c

    https://git.savannah.gnu.org/cgit/make.git/tree/src/main.c?id=d7ff21ecd70bbf9dfda7b3a136b22f631cd80d22

  5. Look up the line number that I wrote down and navigate to that line.

    https://git.savannah.gnu.org/cgit/make.git/tree/src/main.c?id=d7ff21ecd70bbf9dfda7b3a136b22f631cd80d22#n114

  6. Copy the URL.

Back in June 2016, someone posted about this on the cgit mailing list:

I've been using some services that are backed by cgit and in accessing them I'm finding it awkward to get permalinks to lines of code.

[ . . . ]

While the default link available is convenient for immediate discussions, I usually prefer to have a permalink for email and issue tracker usage.

[ . . . ]

This seems a bit unnecessary. I'm wondering if there is a way for cgit to easily get from the first page that I opened from codesearch.openstack.org, to the permalink of the same file and line number at the point in time in the repository that I arrived at in a single step? Is there a key like github's 'press "y"', or an extra link that can be activated, or is this an enhancement?

--- Darragh Bailey, "Accessing permalinks", Wed Jun 15 15:32:20 CEST 2016

https://lists.zx2c4.com/pipermail/cgit/2016-June/003095.html

but it doesn't look like anything has come of it.

So here are the questions:

  • Are these links true permalinks?

  • Is there a more efficient way of getting permalinks from git repositories on cgit?

1 Answer 1

3
+50

Only slightly faster, it seems that you can go to the commit tab and press the button labeled Head (which seems to just add the hash of HEAD to the url) then go back to the tree tab and click on your line number.

https://i.sstatic.net/hXDwc.gif (I copied the line number and ctrl+f'd it to get back)

Certainly short of automatic, but it does seem at least a little less tedious.

3
  • Hm, not wrong, but often produces a different ID since HEAD doesn't necessarily represent a commit that affects the file of interest. Commented Jun 19, 2019 at 16:03
  • Are you talking about getting a hash for the most recent commit affecting that file? I noticed that there was a tree somehash /src/main.c link on the commit page. That sounds a lot like your step #4, although I could be wrong. imgur.com/a/2Rr9JZH
    – creallf
    Commented Jun 19, 2019 at 17:44
  • 1
    Yes, that's it. Not a deal-breaker, though. Commented Jun 23, 2019 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .