Skip to content

Commit bbbe98c

Browse files
authored
Merge branch 'main' into label_delete_event_fix
2 parents be0855d + 274f4ae commit bbbe98c

File tree

31 files changed

+1165
-1061
lines changed

31 files changed

+1165
-1061
lines changed

cmd/serv.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,6 @@ func runServ(ctx context.Context, c *cli.Command) error {
229229
username := repoPathFields[0]
230230
reponame := strings.TrimSuffix(repoPathFields[1], ".git") // “the-repo-name" or "the-repo-name.wiki"
231231

232-
// LowerCase and trim the repoPath as that's how they are stored.
233-
// This should be done after splitting the repoPath into username and reponame
234-
// so that username and reponame are not affected.
235-
repoPath = strings.ToLower(strings.TrimSpace(repoPath))
236-
237232
if !repo.IsValidSSHAccessRepoName(reponame) {
238233
return fail(ctx, "Invalid repo name", "Invalid repo name: %s", reponame)
239234
}
@@ -280,6 +275,11 @@ func runServ(ctx context.Context, c *cli.Command) error {
280275
return fail(ctx, extra.UserMsg, "ServCommand failed: %s", extra.Error)
281276
}
282277

278+
// LowerCase and trim the repoPath as that's how they are stored.
279+
// This should be done after splitting the repoPath into username and reponame
280+
// so that username and reponame are not affected.
281+
repoPath = strings.ToLower(results.OwnerName + "/" + results.RepoName + ".git")
282+
283283
// LFS SSH protocol
284284
if verb == git.CmdVerbLfsTransfer {
285285
token, err := getLFSAuthToken(ctx, lfsVerb, results)

models/asymkey/gpg_key_add.go

Lines changed: 71 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -72,96 +72,90 @@ func AddGPGKey(ctx context.Context, ownerID int64, content, token, signature str
7272
return nil, err
7373
}
7474

75-
ctx, committer, err := db.TxContext(ctx)
76-
if err != nil {
77-
return nil, err
78-
}
79-
defer committer.Close()
80-
81-
keys := make([]*GPGKey, 0, len(ekeys))
82-
83-
verified := false
84-
// Handle provided signature
85-
if signature != "" {
86-
signer, err := openpgp.CheckArmoredDetachedSignature(ekeys, strings.NewReader(token), strings.NewReader(signature), nil)
87-
if err != nil {
88-
signer, err = openpgp.CheckArmoredDetachedSignature(ekeys, strings.NewReader(token+"\n"), strings.NewReader(signature), nil)
89-
}
90-
if err != nil {
91-
signer, err = openpgp.CheckArmoredDetachedSignature(ekeys, strings.NewReader(token+"\r\n"), strings.NewReader(signature), nil)
92-
}
93-
if err != nil {
94-
log.Debug("AddGPGKey CheckArmoredDetachedSignature failed: %v", err)
95-
return nil, ErrGPGInvalidTokenSignature{
96-
ID: ekeys[0].PrimaryKey.KeyIdString(),
97-
Wrapped: err,
75+
return db.WithTx2(ctx, func(ctx context.Context) ([]*GPGKey, error) {
76+
keys := make([]*GPGKey, 0, len(ekeys))
77+
78+
verified := false
79+
// Handle provided signature
80+
if signature != "" {
81+
signer, err := openpgp.CheckArmoredDetachedSignature(ekeys, strings.NewReader(token), strings.NewReader(signature), nil)
82+
if err != nil {
83+
signer, err = openpgp.CheckArmoredDetachedSignature(ekeys, strings.NewReader(token+"\n"), strings.NewReader(signature), nil)
9884
}
85+
if err != nil {
86+
signer, err = openpgp.CheckArmoredDetachedSignature(ekeys, strings.NewReader(token+"\r\n"), strings.NewReader(signature), nil)
87+
}
88+
if err != nil {
89+
log.Debug("AddGPGKey CheckArmoredDetachedSignature failed: %v", err)
90+
return nil, ErrGPGInvalidTokenSignature{
91+
ID: ekeys[0].PrimaryKey.KeyIdString(),
92+
Wrapped: err,
93+
}
94+
}
95+
ekeys = []*openpgp.Entity{signer}
96+
verified = true
9997
}
100-
ekeys = []*openpgp.Entity{signer}
101-
verified = true
102-
}
103-
104-
if len(ekeys) > 1 {
105-
id2key := map[string]*openpgp.Entity{}
106-
newEKeys := make([]*openpgp.Entity, 0, len(ekeys))
107-
for _, ekey := range ekeys {
108-
id := ekey.PrimaryKey.KeyIdString()
109-
if original, has := id2key[id]; has {
110-
// Coalesce this with the other one
111-
for _, subkey := range ekey.Subkeys {
112-
if subkey.PublicKey == nil {
113-
continue
114-
}
115-
found := false
11698

117-
for _, originalSubkey := range original.Subkeys {
118-
if originalSubkey.PublicKey == nil {
99+
if len(ekeys) > 1 {
100+
id2key := map[string]*openpgp.Entity{}
101+
newEKeys := make([]*openpgp.Entity, 0, len(ekeys))
102+
for _, ekey := range ekeys {
103+
id := ekey.PrimaryKey.KeyIdString()
104+
if original, has := id2key[id]; has {
105+
// Coalesce this with the other one
106+
for _, subkey := range ekey.Subkeys {
107+
if subkey.PublicKey == nil {
119108
continue
120109
}
121-
if originalSubkey.PublicKey.KeyId == subkey.PublicKey.KeyId {
122-
found = true
123-
break
110+
found := false
111+
112+
for _, originalSubkey := range original.Subkeys {
113+
if originalSubkey.PublicKey == nil {
114+
continue
115+
}
116+
if originalSubkey.PublicKey.KeyId == subkey.PublicKey.KeyId {
117+
found = true
118+
break
119+
}
120+
}
121+
if !found {
122+
original.Subkeys = append(original.Subkeys, subkey)
124123
}
125124
}
126-
if !found {
127-
original.Subkeys = append(original.Subkeys, subkey)
128-
}
129-
}
130-
for name, identity := range ekey.Identities {
131-
if _, has := original.Identities[name]; has {
132-
continue
125+
for name, identity := range ekey.Identities {
126+
if _, has := original.Identities[name]; has {
127+
continue
128+
}
129+
original.Identities[name] = identity
133130
}
134-
original.Identities[name] = identity
131+
continue
135132
}
136-
continue
133+
id2key[id] = ekey
134+
newEKeys = append(newEKeys, ekey)
137135
}
138-
id2key[id] = ekey
139-
newEKeys = append(newEKeys, ekey)
140-
}
141-
ekeys = newEKeys
142-
}
143-
144-
for _, ekey := range ekeys {
145-
// Key ID cannot be duplicated.
146-
has, err := db.GetEngine(ctx).Where("key_id=?", ekey.PrimaryKey.KeyIdString()).
147-
Get(new(GPGKey))
148-
if err != nil {
149-
return nil, err
150-
} else if has {
151-
return nil, ErrGPGKeyIDAlreadyUsed{ekey.PrimaryKey.KeyIdString()}
136+
ekeys = newEKeys
152137
}
153138

154-
// Get DB session
139+
for _, ekey := range ekeys {
140+
// Key ID cannot be duplicated.
141+
has, err := db.GetEngine(ctx).Where("key_id=?", ekey.PrimaryKey.KeyIdString()).
142+
Get(new(GPGKey))
143+
if err != nil {
144+
return nil, err
145+
} else if has {
146+
return nil, ErrGPGKeyIDAlreadyUsed{ekey.PrimaryKey.KeyIdString()}
147+
}
155148

156-
key, err := parseGPGKey(ctx, ownerID, ekey, verified)
157-
if err != nil {
158-
return nil, err
159-
}
149+
key, err := parseGPGKey(ctx, ownerID, ekey, verified)
150+
if err != nil {
151+
return nil, err
152+
}
160153

161-
if err = addGPGKey(ctx, key, content); err != nil {
162-
return nil, err
154+
if err = addGPGKey(ctx, key, content); err != nil {
155+
return nil, err
156+
}
157+
keys = append(keys, key)
163158
}
164-
keys = append(keys, key)
165-
}
166-
return keys, committer.Commit()
159+
return keys, nil
160+
})
167161
}

models/fixtures/user_redirect.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
id: 1
33
lower_name: olduser1
44
redirect_user_id: 1
5+
-
6+
id: 2
7+
lower_name: olduser2
8+
redirect_user_id: 2

0 commit comments

Comments
 (0)