Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Code

394 commit(s) on main

Default the run verbs to origin Keenan Nemetz · 6m ago 2e6aa96e
history blame raw 1.7 KiB
1package index
2
3// The `#42` alias, as the index sees it.
4//
5// The number is derived from history (metadata.LoadNumbers) and cached here so a
6// page render does not walk git. It is not authoritative: `vole admin index
7// rebuild` recomputes every row from the metadata branch, and the answer is the
8// same because the history is.
9
10// Numbers returns every entity number in a repo, keyed by entity id.
11func (s *Store) Numbers(repoID string) (map[string]int, error) {
12 rows, err := s.db.Query(`SELECT id, number FROM entity_numbers WHERE repo_id=?`, repoID)
13 if err != nil {
14 return nil, err
15 }
16 defer rows.Close()
17 out := map[string]int{}
18 for rows.Next() {
19 var id string
20 var number int
21 if err := rows.Scan(&id, &number); err != nil {
22 return nil, err
23 }
24 out[id] = number
25 }
26 return out, rows.Err()
27}
28
29// Number returns the alias for one entity and which kind it is. An entity the
30// branch does not number (a stale index, or one that does not exist) reports
31// ok=false rather than zero.
32func (s *Store) Number(repoID, id string) (number int, kind string, ok bool) {
33 err := s.db.QueryRow(`SELECT number, kind FROM entity_numbers WHERE repo_id=? AND id=?`, repoID, id).
34 Scan(&number, &kind)
35 return number, kind, err == nil
36}
37
38// ByNumber resolves `#42` to the entity it names and its kind. Issues and change
39// requests share one sequence, so the kind is part of the answer: the caller
40// decides whether an issue or a request was asked for.
41func (s *Store) ByNumber(repoID string, number int) (id, kind string, ok bool) {
42 err := s.db.QueryRow(`SELECT id, kind FROM entity_numbers WHERE repo_id=? AND number=?`, repoID, number).
43 Scan(&id, &kind)
44 return id, kind, err == nil
45}
46