# HG changeset patch # User Sean E. Russell # Date 1634074287 18000 # Tue Oct 12 16:31:27 2021 -0500 # Node ID c6e7a4d4cfd140db46d451a5bf748e1cd556a7c4 # Parent dac711bc3df99336addd9a86902040d69b12b944 When merging tasks, remove duplicate project and context tags diff --git a/main.go b/main.go --- a/main.go +++ b/main.go @@ -127,21 +127,37 @@ t.Completed = b.Completed || a.Completed sort.Strings(a.Projects) sort.Strings(b.Projects) - t.Projects = make([]string, len(a.Projects)) - for i, ap := range a.Projects { - t.Projects[i] = ap + t.Projects = make([]string, 0, len(a.Projects)) + // Remove duplicate project tags + prjcts := make(map[string]bool) + for _, ap := range a.Projects { + if !prjcts[ap] { + t.Projects = append(t.Projects, ap) + prjcts[ap] = true + } } for _, bp := range b.Projects { - t.Projects = append(t.Projects, bp) + if !prjcts[bp] { + t.Projects = append(t.Projects, bp) + prjcts[bp] = true + } } sort.Strings(a.Contexts) sort.Strings(b.Contexts) - t.Contexts = make([]string, len(a.Contexts)) - for i, ap := range a.Contexts { - t.Contexts[i] = ap + t.Contexts = make([]string, 0, len(a.Contexts)) + // Remove duplicate context tags + ctxts := make(map[string]bool) + for _, ap := range a.Contexts { + if !ctxts[ap] { + t.Contexts = append(t.Contexts, ap) + ctxts[ap] = true + } } for _, bp := range b.Contexts { - t.Contexts = append(t.Contexts, bp) + if !ctxts[bp] { + t.Contexts = append(t.Contexts, bp) + ctxts[bp] = true + } } t.AdditionalTags = make(map[string]string) for k, v := range a.AdditionalTags {