- commit
- 48e8c7f
- parent
- 2e37871
- author
- Eric Bower
- date
- 2024-05-30 16:42:22 -0400 EDT
refactor
M
cli.go
+13,
-4
1@@ -155,8 +155,11 @@ Here's how it works:
2 return nil
3 }
4
5- for _, patch := range patches {
6- wish.Printf(sesh, "%s\n\n\n", patch.RawText)
7+ for idx, patch := range patches {
8+ wish.Printf(sesh, patch.RawText)
9+ if idx < len(patches)-1 {
10+ wish.Printf(sesh, "\n\n\n")
11+ }
12 }
13
14 return nil
15@@ -201,7 +204,7 @@ Here's how it works:
16 "%s %s %s\n%s <%s>\n%s\n\n---\n%s\n%s\n\n\n",
17 patch.Title,
18 reviewTxt,
19- patch.CommitSha,
20+ truncateSha(patch.CommitSha),
21 patch.AuthorName,
22 patch.AuthorEmail,
23 patch.AuthorDate,
24@@ -253,7 +256,7 @@ Here's how it works:
25 "%s\t%s\t%s\t%s <%s>\t%s\n",
26 patch.Title,
27 reviewTxt,
28- patch.CommitSha,
29+ truncateSha(patch.CommitSha),
30 patch.AuthorName,
31 patch.AuthorEmail,
32 patch.AuthorDate,
33@@ -339,6 +342,12 @@ Here's how it works:
34 if err != nil {
35 return err
36 }
37+
38+ if len(patches) == 0 {
39+ wish.Println(sesh, "Patches submitted! However none were saved, probably because they already exist in the system")
40+ return nil
41+ }
42+
43 reviewTxt := ""
44 if isReview {
45 err = pr.UpdatePatchRequest(prID, "review")
M
pr.go
+11,
-16
1@@ -126,12 +126,13 @@ func (cmd PrCmd) calcContentSha(diffFiles []*gitdiff.File, header *gitdiff.Patch
2 header.AuthorDate,
3 )
4 for _, diff := range diffFiles {
5- content += fmt.Sprintf(
6- "%s->%s %s..%s %s-%s\n",
7+ dff := fmt.Sprintf(
8+ "%s->%s %s..%s %s->%s\n",
9 diff.OldName, diff.NewName,
10 diff.OldOIDPrefix, diff.NewOIDPrefix,
11 diff.OldMode.String(), diff.NewMode.String(),
12 )
13+ content += dff
14 }
15 sha := sha256.Sum256([]byte(content))
16 shaStr := hex.EncodeToString(sha[:])
17@@ -178,8 +179,8 @@ func (cmd PrCmd) parsePatchSet(patchset io.Reader) ([]*Patch, error) {
18 Title: header.Title,
19 Body: header.Body,
20 BodyAppendix: header.BodyAppendix,
21- ContentSha: contentSha,
22 CommitSha: header.SHA,
23+ ContentSha: contentSha,
24 RawText: patchRaw,
25 })
26 }
27@@ -188,15 +189,15 @@ func (cmd PrCmd) parsePatchSet(patchset io.Reader) ([]*Patch, error) {
28 }
29
30 func (cmd PrCmd) createPatch(tx *sqlx.Tx, patch *Patch) (int64, error) {
31- var patchExists *Patch
32- _ = tx.Select(&patchExists, "SELECT * FROM patches WHERE patch_request_id = ? AND content_sha = ?", patch.PatchRequestID, patch.ContentSha)
33- if patchExists.ID == 0 {
34+ patchExists := []Patch{}
35+ _ = cmd.Backend.DB.Select(&patchExists, "SELECT * FROM patches WHERE patch_request_id = ? AND content_sha = ?", patch.PatchRequestID, patch.ContentSha)
36+ if len(patchExists) > 0 {
37 return 0, ErrPatchExists
38 }
39
40 var patchID int64
41 row := tx.QueryRow(
42- "INSERT INTO patches (pubkey, patch_request_id, author_name, author_email, author_date, title, body, body_appendix, commit_sha, content_sha, raw_text) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
43+ "INSERT INTO patches (pubkey, patch_request_id, author_name, author_email, author_date, title, body, body_appendix, commit_sha, content_sha, raw_text) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
44 patch.Pubkey,
45 patch.PatchRequestID,
46 patch.AuthorName,
47@@ -205,8 +206,8 @@ func (cmd PrCmd) createPatch(tx *sqlx.Tx, patch *Patch) (int64, error) {
48 patch.Title,
49 patch.Body,
50 patch.BodyAppendix,
51- patch.ContentSha,
52 patch.CommitSha,
53+ patch.ContentSha,
54 patch.RawText,
55 )
56 err := row.Scan(&patchID)
57@@ -226,10 +227,7 @@ func (cmd PrCmd) SubmitPatchRequest(repoID string, pubkey string, patchset io.Re
58 }
59
60 defer func() {
61- err := tx.Rollback()
62- if err != nil {
63- cmd.Backend.Logger.Error("rollback", "err", err)
64- }
65+ _ = tx.Rollback()
66 }()
67
68 patches, err := cmd.parsePatchSet(patchset)
69@@ -288,10 +286,7 @@ func (cmd PrCmd) SubmitPatchSet(prID int64, pubkey string, review bool, patchset
70 }
71
72 defer func() {
73- err := tx.Rollback()
74- if err != nil {
75- cmd.Backend.Logger.Error("rollback", "err", err)
76- }
77+ _ = tx.Rollback()
78 }()
79
80 patches, err := cmd.parsePatchSet(patchset)
M
ssh.go
+6,
-1
1@@ -29,7 +29,12 @@ func GitSshServer() {
2 }
3
4 cfg := NewGitCfg()
5- logger := slog.Default()
6+ opts := &slog.HandlerOptions{
7+ AddSource: true,
8+ }
9+ logger := slog.New(
10+ slog.NewTextHandler(os.Stdout, opts),
11+ )
12 dbh, err := Open(filepath.Join(cfg.DataPath, "pr.db"), logger)
13 if err != nil {
14 panic(err)