Skip to content

Commit 335c6e7

Browse files
pimyn-girgisa-nogikh
authored andcommitted
pkg/email: extract base-commit hash from emails
If the author of a patch series provides a base-commit tag, extract and store the hash.
1 parent 64c076e commit 335c6e7

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

pkg/email/lore/parse.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ type Thread struct {
2525

2626
// Series represents a single patch series sent over email.
2727
type Series struct {
28-
Subject string
29-
MessageID string
30-
Version int
31-
Corrupted string // If non-empty, contains a reason why the series better be ignored.
32-
Tags []string
33-
Patches []Patch
28+
Subject string
29+
MessageID string
30+
Version int
31+
Corrupted string // If non-empty, contains a reason why the series better be ignored.
32+
Tags []string
33+
Patches []Patch
34+
BaseCommitHint string
3435
}
3536

3637
type Patch struct {
@@ -88,6 +89,9 @@ func PatchSeries(emails []*Email) []*Series {
8889
if !ok {
8990
continue
9091
}
92+
if series.BaseCommitHint == "" { // Usually base-commit is in patch 0 or 1. Check them all to be safe.
93+
series.BaseCommitHint = email.BaseCommitHint
94+
}
9195
seq := patch.Seq.ValueOr(1)
9296
if seq == 0 {
9397
// The cover email is not of interest.

pkg/email/parser.go

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ import (
2020
)
2121

2222
type Email struct {
23-
BugIDs []string
24-
MessageID string
25-
InReplyTo string
26-
Date time.Time
27-
Link string
28-
Subject string
29-
MailingList string
30-
Author string
31-
OwnEmail bool
32-
Cc []string
33-
RawCc []string // unstripped emails
34-
Body string // text/plain part
35-
Patch string // attached patch, if any
36-
Commands []*SingleCommand
23+
BugIDs []string
24+
MessageID string
25+
InReplyTo string
26+
Date time.Time
27+
Link string
28+
Subject string
29+
MailingList string
30+
Author string
31+
OwnEmail bool
32+
Cc []string
33+
RawCc []string // unstripped emails
34+
Body string // text/plain part
35+
Patch string // attached patch, if any
36+
BaseCommitHint string // Hash of base-commit, if provided.
37+
Commands []*SingleCommand
3738
}
3839

3940
type SingleCommand struct {
@@ -179,20 +180,21 @@ func Parse(r io.Reader, ownEmails, goodLists, domains []string) (*Email, error)
179180
}
180181
date, _ := mail.ParseDate(msg.Header.Get("Date"))
181182
email := &Email{
182-
BugIDs: unique(bugIDs),
183-
MessageID: msg.Header.Get("Message-ID"),
184-
InReplyTo: extractInReplyTo(msg.Header),
185-
Date: date,
186-
Link: link,
187-
Author: author,
188-
OwnEmail: fromMe,
189-
MailingList: mailingList,
190-
Subject: subject,
191-
Cc: ccList,
192-
RawCc: mergeRawAddresses(from, originalFroms, to, cc),
193-
Body: bodyStr,
194-
Patch: patch,
195-
Commands: cmds,
183+
BugIDs: unique(bugIDs),
184+
MessageID: msg.Header.Get("Message-ID"),
185+
InReplyTo: extractInReplyTo(msg.Header),
186+
Date: date,
187+
Link: link,
188+
Author: author,
189+
OwnEmail: fromMe,
190+
MailingList: mailingList,
191+
Subject: subject,
192+
Cc: ccList,
193+
RawCc: mergeRawAddresses(from, originalFroms, to, cc),
194+
Body: bodyStr,
195+
Patch: patch,
196+
Commands: cmds,
197+
BaseCommitHint: extractBaseCommitHint(bodyStr),
196198
}
197199
return email, nil
198200
}
@@ -575,3 +577,13 @@ func decodeSubject(rawSubject string) string {
575577
}
576578
return decodedSubject
577579
}
580+
581+
var baseCommitRegex = regexp.MustCompile(`(?m)^base-commit:\s*([0-9a-fA-F]{40})\r?$`)
582+
583+
func extractBaseCommitHint(email string) string {
584+
matches := baseCommitRegex.FindStringSubmatch(email)
585+
if matches != nil {
586+
return matches[1]
587+
}
588+
return ""
589+
}

0 commit comments

Comments
 (0)