Code

Free blame view data when reloading view
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index c963977bbdcdb71338534f27440563107ac9d8b1..810e5e785135ddbfb84b77c822ebb5ab3e7d6296 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -4911,6 +4911,7 @@ static bool
 blame_open(struct view *view)
 {
        char path[SIZEOF_STR];
+       size_t i;
 
        if (!view->prev && *opt_prefix) {
                string_copy(path, opt_file);
@@ -4928,6 +4929,24 @@ blame_open(struct view *view)
                        return FALSE;
        }
 
+       /* First pass: remove multiple references to the same commit. */
+       for (i = 0; i < view->lines; i++) {
+               struct blame *blame = view->line[i].data;
+
+               if (blame->commit && blame->commit->id[0])
+                       blame->commit->id[0] = 0;
+               else
+                       blame->commit = NULL;
+       }
+
+       /* Second pass: free existing references. */
+       for (i = 0; i < view->lines; i++) {
+               struct blame *blame = view->line[i].data;
+
+               if (blame->commit)
+                       free(blame->commit);
+       }
+
        setup_update(view, opt_file);
        string_format(view->ref, "%s ...", opt_file);