~ewintr/gte

33c473eadf11363b3b132913ab77e252defe26c9 — Erik Winter 2 months ago f8cd648
remove unused dirty flag
3 files changed, 10 insertions(+), 20 deletions(-)

M internal/storage/remote.go
M internal/task/task.go
M internal/task/task_test.go
M internal/storage/remote.go => internal/storage/remote.go +3 -3
@@ 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)
			}

M internal/task/task.go => internal/task/task.go +6 -13
@@ 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 == "" {
				value = lowerAndTrim(parts[1])
			} else {
				dirty = true
			}
		if fieldName == field && value == "" {
			value = lowerAndTrim(parts[1])
		}
	}

	return value, dirty
	return value
}

func FieldFromSubject(field, subject string) string {

M internal/task/task_test.go => internal/task/task_test.go +1 -4
@@ 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)
		})
	}
}