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 {
id, _ := task.FieldFromBody(task.FIELD_ID, msg.Body)
versionStr, _ := task.FieldFromBody(task.FIELD_VERSION, msg.Body)
id := task.FieldFromBody(task.FIELD_ID, msg.Body)
versionStr := task.FieldFromBody(task.FIELD_VERSION, msg.Body)
version, _ := strconv.Atoi(versionStr)
if _, ok := msgsSet[id]; !ok {
msgsSet[id] = []msgInfo{}
@ -141,7 +141,7 @@ func (rr *RemoteRepository) Remove(tasks []*task.Task) error {
}
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 {
toBeRemoved = append(toBeRemoved, msg)
}

View File

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

View File

@ -363,7 +363,6 @@ func TestFieldFromBody(t *testing.T) {
field string
body string
expValue string
expDirty bool
}{
{
name: "empty field",
@ -398,7 +397,6 @@ field: valuea
field: valueb
`,
expValue: "valuea",
expDirty: true,
},
{
name: "colons",
@ -451,9 +449,8 @@ field: valuea
},
} {
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.expDirty, actDirty)
})
}
}