tangled
alpha
login
or
join now
julien.rbrt.fr
/
tangled-core
forked from
tangled.org/core
0
fork
atom
Monorepo for Tangled — https://tangled.org
0
fork
atom
overview
issues
pulls
pipelines
impl async resolver for multiple idents
oppi.li
1 year ago
89adf353
5e88220f
+53
-16
7 changed files
expand all
collapse all
unified
split
appview
pages
pages.go
templates
repo
blob.html
commit.html
resolver.go
state
repo.go
knotserver
git
diff.go
types
diff.go
+1
-1
appview/pages/pages.go
···
366
366
func (p *Pages) RepoBlob(w io.Writer, params RepoBlobParams) error {
367
367
if params.Lines < 5000 {
368
368
c := params.Contents
369
369
-
style := styles.Get("xcode")
369
369
+
style := styles.Get("bw")
370
370
formatter := chromahtml.New(
371
371
chromahtml.InlineCode(true),
372
372
chromahtml.WithLineNumbers(true),
+1
-1
appview/pages/templates/repo/blob.html
···
22
22
{{ end }}
23
23
{{ end }}
24
24
</div>
25
25
-
<div id="file-info">
25
25
+
<div id="file-info" class="text-gray-500 text-xs">
26
26
{{ .Lines }} lines
27
27
<span class="select-none px-2 [&:before]:content-['·']"></span>
28
28
{{ byteFmt .SizeHint }}
+1
-1
appview/pages/templates/repo/commit.html
···
108
108
{{ else }}
109
109
<pre class="overflow-auto">
110
110
{{- range .TextFragments -}}
111
111
-
<div class="bg-gray-100 text-gray-500 select-none">{{ .Comment }}</div>
111
111
+
<div class="bg-gray-100 text-gray-500 select-none">{{ .Header }}</div>
112
112
113
113
{{- range .Lines -}}
114
114
{{- if eq .Op.String "+" -}}
+32
appview/resolver.go
···
2
2
3
3
import (
4
4
"context"
5
5
+
"sync"
5
6
6
7
"github.com/bluesky-social/indigo/atproto/identity"
7
8
"github.com/bluesky-social/indigo/atproto/syntax"
···
25
26
26
27
return r.directory.Lookup(ctx, *id)
27
28
}
29
29
+
30
30
+
func (r *Resolver) ResolveIdents(ctx context.Context, idents []string) []*identity.Identity {
31
31
+
results := make([]*identity.Identity, len(idents))
32
32
+
var wg sync.WaitGroup
33
33
+
34
34
+
// Create a channel to handle context cancellation
35
35
+
done := make(chan struct{})
36
36
+
defer close(done)
37
37
+
38
38
+
// Start a goroutine for each identifier
39
39
+
for idx, ident := range idents {
40
40
+
wg.Add(1)
41
41
+
go func(index int, id string) {
42
42
+
defer wg.Done()
43
43
+
44
44
+
select {
45
45
+
case <-ctx.Done():
46
46
+
results[index] = nil
47
47
+
case <-done:
48
48
+
results[index] = nil
49
49
+
default:
50
50
+
// Resolve the identifier - if error, identity will be nil
51
51
+
identity, _ := r.ResolveIdent(ctx, id)
52
52
+
results[index] = identity
53
53
+
}
54
54
+
}(idx, ident)
55
55
+
}
56
56
+
57
57
+
wg.Wait()
58
58
+
return results
59
59
+
}
+14
-9
appview/state/repo.go
···
480
480
481
481
did := item[0]
482
482
483
483
-
var handle string
484
484
-
id, err := s.resolver.ResolveIdent(ctx, did)
485
485
-
if err != nil {
486
486
-
handle = ""
487
487
-
} else {
488
488
-
handle = string(id.Handle)
489
489
-
}
490
490
-
491
483
c := pages.Collaborator{
492
484
Did: did,
493
493
-
Handle: handle,
485
485
+
Handle: "",
494
486
Role: role,
495
487
}
496
488
collaborators = append(collaborators, c)
489
489
+
}
490
490
+
491
491
+
// populate all collborators with handles
492
492
+
identsToResolve := make([]string, len(collaborators))
493
493
+
for i, collab := range collaborators {
494
494
+
identsToResolve[i] = collab.Did
495
495
+
}
496
496
+
497
497
+
resolvedIdents := s.resolver.ResolveIdents(ctx, identsToResolve)
498
498
+
for i, resolved := range resolvedIdents {
499
499
+
if resolved != nil {
500
500
+
collaborators[i].Handle = resolved.Handle.String()
501
501
+
}
497
502
}
498
503
499
504
return collaborators, nil
+2
-2
knotserver/git/diff.go
···
66
66
67
67
for _, tf := range d.TextFragments {
68
68
ndiff.TextFragments = append(ndiff.TextFragments, types.TextFragment{
69
69
-
Comment: tf.Comment,
70
70
-
Lines: tf.Lines,
69
69
+
Header: tf.Header(),
70
70
+
Lines: tf.Lines,
71
71
})
72
72
for _, l := range tf.Lines {
73
73
switch l.Op {
+2
-2
types/diff.go
···
6
6
)
7
7
8
8
type TextFragment struct {
9
9
-
Comment string `json:"comment"`
10
10
-
Lines []gitdiff.Line `json:"lines"`
9
9
+
Header string `json:"comment"`
10
10
+
Lines []gitdiff.Line `json:"lines"`
11
11
}
12
12
13
13
type Diff struct {