summaryrefslogtreecommitdiff
path: root/file
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-27 14:26:41 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-08-27 14:42:00 (GMT)
commit223875a1d7274c2bf4644f4f9a2ba44e371824c3 (patch)
treebc119c2905164793edf25427db8c134b72757a7f /file
parent2f17c67c59af7713888508fd9bfc49b79c486e5a (diff)
downloadeeshow-223875a1d7274c2bf4644f4f9a2ba44e371824c3.zip
eeshow-223875a1d7274c2bf4644f4f9a2ba44e371824c3.tar.gz
eeshow-223875a1d7274c2bf4644f4f9a2ba44e371824c3.tar.bz2
file/git-hist.c (hist_iterate): "last child" logic was broken
This caused commits to be placed out of sequence when iterating.
Diffstat (limited to 'file')
-rw-r--r--file/git-hist.c25
-rw-r--r--file/git-hist.h1
2 files changed, 23 insertions, 3 deletions
diff --git a/file/git-hist.c b/file/git-hist.c
index bd9d56d..bfb3bc3 100644
--- a/file/git-hist.c
+++ b/file/git-hist.c
@@ -214,15 +214,34 @@ fail:
}
-void hist_iterate(struct hist *h,
+/*
+ * We use the "seen" counter to make sure we only show a commit after all newer
+ * commits have been shown. We could accomplish the same by reordering the
+ * h->older array of all ancestors each time we find a branch, but this works
+ * just as well, has only the small disadvantage that we're modifying the
+ * history entries during traversal, and is simpler.
+ */
+
+static void hist_iterate_recurse(struct hist *h,
void (*fn)(void *user, struct hist *h), void *user)
{
unsigned i;
fn(user, h);
for (i = 0; i != h->n_older; i++)
- if (h->older[i]->newer[h->older[i]->n_newer - 1] == h)
- hist_iterate(h->older[i], fn, user);
+ if (++h->older[i]->seen == h->older[i]->n_newer)
+ hist_iterate_recurse(h->older[i], fn, user);
+}
+
+
+void hist_iterate(struct hist *hist,
+ void (*fn)(void *user, struct hist *h), void *user)
+{
+ struct hist *h;
+
+ for (h = history; h; h = h->next)
+ h->seen = 0;
+ hist_iterate_recurse(hist, fn, user);
}
diff --git a/file/git-hist.h b/file/git-hist.h
index 1e70112..ce2670e 100644
--- a/file/git-hist.h
+++ b/file/git-hist.h
@@ -30,6 +30,7 @@ struct hist {
unsigned n_older;
struct hist *next; /* no specific order */
+ unsigned seen; /* for traversal */
};