remove unused dirty flag

This commit is contained in:
Erik Winter 2021-09-23 06:44:40 +02:00
parent f8cd648119
commit 33c473eadf
3 changed files with 10 additions and 20 deletions

View File

@ -88,8 +88,8 @@ func (rr *RemoteRepository) CleanUp() error {
} }
for _, msg := range msgs { for _, msg := range msgs {
id, _ := task.FieldFromBody(task.FIELD_ID, msg.Body) id := task.FieldFromBody(task.FIELD_ID, msg.Body)
versionStr, _ := task.FieldFromBody(task.FIELD_VERSION, msg.Body) versionStr := task.FieldFromBody(task.FIELD_VERSION, msg.Body)
version, _ := strconv.Atoi(versionStr) version, _ := strconv.Atoi(versionStr)
if _, ok := msgsSet[id]; !ok { if _, ok := msgsSet[id]; !ok {
msgsSet[id] = []msgInfo{} msgsSet[id] = []msgInfo{}
@ -141,7 +141,7 @@ func (rr *RemoteRepository) Remove(tasks []*task.Task) error {
} }
for _, msg := range msgs { for _, msg := range msgs {
id, _ := task.FieldFromBody(task.FIELD_ID, msg.Body) id := task.FieldFromBody(task.FIELD_ID, msg.Body)
if _, ok := tMap[id]; ok { if _, ok := tMap[id]; ok {
toBeRemoved = append(toBeRemoved, msg) toBeRemoved = append(toBeRemoved, msg)
} }

View File

@ -89,8 +89,7 @@ func NewFromMessage(msg *mstore.Message) *Task {
bodyFields := map[string]string{} bodyFields := map[string]string{}
for _, f := range bodyFieldNames { for _, f := range bodyFieldNames {
value, _ := FieldFromBody(f, msg.Body) bodyFields[f] = FieldFromBody(f, msg.Body)
bodyFields[f] = value
} }
// apply precedence rules // apply precedence rules
@ -238,16 +237,14 @@ func (t *Task) GenerateFromRecurrer(date Date) (*Task, error) {
}, nil }, nil
} }
func FieldFromBody(field, body string) (string, bool) { func FieldFromBody(field, body string) string {
value := "" value := ""
dirty := false
lines := strings.Split(body, "\n") lines := strings.Split(body, "\n")
for _, line := range lines { for _, line := range lines {
line = strings.TrimSpace(strings.TrimPrefix(line, QUOTE_PREFIX)) line = strings.TrimSpace(strings.TrimPrefix(line, QUOTE_PREFIX))
if line == PREVIOUS_SEPARATOR { if line == PREVIOUS_SEPARATOR {
return value, dirty return value
} }
parts := strings.SplitN(line, FIELD_SEPARATOR, 2) parts := strings.SplitN(line, FIELD_SEPARATOR, 2)
@ -256,16 +253,12 @@ func FieldFromBody(field, body string) (string, bool) {
} }
fieldName := strings.ToLower(strings.TrimSpace(parts[0])) fieldName := strings.ToLower(strings.TrimSpace(parts[0]))
if fieldName == field { if fieldName == field && value == "" {
if value == "" {
value = lowerAndTrim(parts[1]) value = lowerAndTrim(parts[1])
} else {
dirty = true
}
} }
} }
return value, dirty return value
} }
func FieldFromSubject(field, subject string) string { func FieldFromSubject(field, subject string) string {

View File

@ -363,7 +363,6 @@ func TestFieldFromBody(t *testing.T) {
field string field string
body string body string
expValue string expValue string
expDirty bool
}{ }{
{ {
name: "empty field", name: "empty field",
@ -398,7 +397,6 @@ field: valuea
field: valueb field: valueb
`, `,
expValue: "valuea", expValue: "valuea",
expDirty: true,
}, },
{ {
name: "colons", name: "colons",
@ -451,9 +449,8 @@ field: valuea
}, },
} { } {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
actValue, actDirty := task.FieldFromBody(tc.field, tc.body) actValue := task.FieldFromBody(tc.field, tc.body)
test.Equals(t, tc.expValue, actValue) test.Equals(t, tc.expValue, actValue)
test.Equals(t, tc.expDirty, actDirty)
}) })
} }
} }