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.

Phase 2: issue CLI, cross-references, backlinks, filter and search

c1e3e3ca696c2bae8692775977fdae21ed50bc4a · Keenan Nemetz · 18d ago · parent 37c01e5a

Phase 2: issue CLI, cross-references, backlinks, filter and search

The issue format needed no client, and still does not: every one of these is
sugar over files anyone can write. The CLI exists so the common case is not
ceremony.

- `vole issue new|comment|close|reopen|list|show` works on the clone in the
  current directory. It fetches the issues branch first so its commit is a
  fast-forward the server will accept, validates locally so a malformed issue
  never costs a round trip, then pushes. Writing goes through gitx.CommitFiles,
  the shared CAS path, so a concurrent author's commit cannot be clobbered.
- Ids may be abbreviated. `list` prints eight characters, so every id-taking
  command resolves prefixes and refuses an ambiguous one with the candidates
  listed. This was a real bug: list printed short ids while comment and close
  demanded the full ULID, so copying the id from the CLI's own output failed.
  The integration test now drives the CLI with a prefix.
- `#<ulid>` in an issue body or comment renders as a link. Rewriting happens on
  the markdown source, skipping fenced blocks so a reference inside a code
  sample stays literal; a test asserts both halves.
- Backlinks: commits whose message mentions an id are listed on the issue, found
  with `git log --grep`. git does the search, so there is no second index.
- Filtering and search on the list page: state, label, and a LIKE over title and
  body, backed by an `issue_labels` table and an indexed `body` column.

Notifications are deliberately not built. The web is read-only and has no user
identity, so "in-app" has nobody to notify and email would need subscriptions,
which need a store. The honest fit is a per-repo Atom feed when someone wants
one; the roadmap says so rather than leaving a phantom item.

Verified by hand with a clone and a key: filed an issue, listed it, commented
using the short id, closed it, confirmed the web showed the closed state, the
rendered comment and the label filter, and that an ambiguous prefix is refused.

internal/gitx/trees.go +99

@@ -0,0 +1,99 @@
1 package gitx
2
3 import (
4 "fmt"
5 "strings"
6 )
7
8 // FlatTree reads every blob under commit as a path -> content map. Callers mutate
9 // the map and hand it back to WriteFlatTree, which is the simplest way to express
10 // "update one file in a tree" without a worktree.
11 func (r *Repo) FlatTree(commit string) (map[string][]byte, error) {
12 out := map[string][]byte{}
13 if commit == "" {
14 return out, nil
15 }
16 entries, err := r.LsTreeR(commit)
17 if err != nil {
18 return nil, err
19 }
20 for _, e := range entries {
21 if e.Type != "blob" {
22 continue // submodules and symlink targets are not ours to rewrite
23 }
24 data, err := r.BlobBySHA(e.SHA)
25 if err != nil {
26 return nil, err
27 }
28 out[e.Name] = data
29 }
30 return out, nil
31 }
32
33 // WriteFlatTree writes a nested tree from flat paths and returns its id.
34 func WriteFlatTree(g *Repo, files map[string][]byte) (string, error) {
35 var entries []Entry
36 dirs := map[string]map[string][]byte{}
37 for path, content := range files {
38 parts := strings.SplitN(path, "/", 2)
39 if len(parts) == 1 {
40 blob, err := g.HashObject(content)
41 if err != nil {
42 return "", err
43 }
44 entries = append(entries, Entry{Mode: "100644", Type: "blob", SHA: blob, Name: parts[0]})
45 continue
46 }
47 if dirs[parts[0]] == nil {
48 dirs[parts[0]] = map[string][]byte{}
49 }
50 dirs[parts[0]][parts[1]] = content
51 }
52 for name, sub := range dirs {
53 sha, err := WriteFlatTree(g, sub)
54 if err != nil {
55 return "", err
56 }
57 entries = append(entries, Entry{Mode: "040000", Type: "tree", SHA: sha, Name: name})
58 }
59 return g.MkTree(entries)
60 }
61
62 // CommitFiles applies mutate to the tree behind ref and moves the ref with a
63 // compare-and-swap, retrying when another writer wins. It is the single write
64 // path for metadata refs; a second implementation would eventually disagree
65 // about ordering or retries, and that shows up as lost data.
66 func CommitFiles(g *Repo, ref string, mutate func(map[string][]byte) error, message, author string) (string, error) {
67 const maxAttempts = 64
68 var lastErr error
69 for attempt := 0; attempt < maxAttempts; attempt++ {
70 old, err := g.RevParseRaw(ref)
71 if err != nil {
72 return "", err
73 }
74 files, err := g.FlatTree(old)
75 if err != nil {
76 return "", err
77 }
78 if err := mutate(files); err != nil {
79 return "", err
80 }
81 tree, err := WriteFlatTree(g, files)
82 if err != nil {
83 return "", err
84 }
85 commit, err := g.CommitTreeAs(tree, old, message, author)
86 if err != nil {
87 return "", err
88 }
89 ok, err := g.UpdateRefCAS(ref, commit, old)
90 if err != nil {
91 return "", err
92 }
93 if ok {
94 return commit, nil
95 }
96 lastErr = fmt.Errorf("%s: lost %d ref race(s)", ref, attempt+1)
97 }
98 return "", lastErr
99 }