summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--file/git-hist.c63
-rw-r--r--file/git-hist.h9
-rw-r--r--gui/common.h3
-rw-r--r--gui/gui.c14
-rw-r--r--gui/sheet.c2
-rw-r--r--main.c6
6 files changed, 62 insertions, 35 deletions
diff --git a/file/git-hist.c b/file/git-hist.c
index fd3d455..25c987e 100644
--- a/file/git-hist.c
+++ b/file/git-hist.c
@@ -31,13 +31,16 @@
*/
-static struct hist *history = NULL;
+struct history {
+ struct hist *head;
+ struct hist *history; /* any order */
+};
/* ----- History retrieval ------------------------------------------------- */
-static struct hist *new_commit(unsigned branch)
+static struct hist *new_commit(struct history *history, unsigned branch)
{
struct hist *h;
@@ -48,8 +51,8 @@ static struct hist *new_commit(unsigned branch)
h->n_newer = 0;
h->older = NULL;
h->n_older = 0;
- h->next = history;
- history = h;
+ h->next = history->history;
+ history->history = h;
return h;
}
@@ -62,7 +65,8 @@ static void uplink(struct hist *down, struct hist *up)
}
-static struct hist *find_commit(const git_commit *commit)
+static struct hist *find_commit(struct history *history,
+ const git_commit *commit)
{
struct hist *h;
@@ -71,14 +75,15 @@ static struct hist *find_commit(const git_commit *commit)
* git_oid_equal(git_object_id(a), git_object_id(b))
*/
- for (h = history; h; h = h->next)
+ for (h = history->history; h; h = h->next)
if (h->commit == commit)
break;
return h;
}
-static void recurse(struct hist *h, unsigned n_branches)
+static void recurse(struct history *history, struct hist *h,
+ unsigned n_branches)
{
unsigned n, i;
@@ -97,19 +102,19 @@ static void recurse(struct hist *h, unsigned n_branches)
if (git_commit_parent(&commit, h->commit, i))
pfatal_git("git_commit_parent");
- found = find_commit(commit);
+ found = find_commit(history, commit);
if (found) {
uplink(found, h);
h->older[i] = found;
} else {
struct hist *new;
- new = new_commit(n_branches);
+ new = new_commit(history, n_branches);
new->commit = commit;
h->older[i] = new;
n_branches++;
uplink(new, h);
- recurse(new, n_branches);
+ recurse(history, new, n_branches);
}
}
}
@@ -128,13 +133,17 @@ bool vcs_git_try(const char *path)
}
-struct hist *vcs_git_hist(const char *path)
+struct history *vcs_git_history(const char *path)
{
+ struct history *history;
struct hist *head, *dirty;
git_repository *repo;
git_oid oid;
- head = new_commit(0);
+ history = alloc_type(struct history);
+ history->history = NULL;
+
+ head = new_commit(history, 0);
git_init_once();
@@ -148,18 +157,30 @@ struct hist *vcs_git_hist(const char *path)
if (git_commit_lookup(&head->commit, repo, &oid))
pfatal_git(git_repository_path(repo));
- recurse(head, 1);
+ recurse(history, head, 1);
- if (!git_repo_is_dirty(repo))
- return head;
+ if (!git_repo_is_dirty(repo)) {
+ history->head = head;
+ return history;
+ }
- dirty = new_commit(0);
+ dirty = new_commit(history, 0);
dirty->older = alloc_type(struct hist *);
dirty->older[0] = head;
dirty->n_older = 1;
uplink(head, dirty);
- return dirty;
+ history->head = dirty;
+ return history;
+}
+
+
+/* ----- Get the head ------------------------------------------------------ */
+
+
+struct hist *vcs_head(const struct history *history)
+{
+ return history->head;
}
@@ -243,12 +264,12 @@ static void hist_iterate_recurse(struct hist *h,
}
-void hist_iterate(struct hist *hist,
+void hist_iterate(struct history *history, struct hist *hist,
void (*fn)(void *user, struct hist *h), void *user)
{
struct hist *h;
- for (h = history; h; h = h->next)
+ for (h = history->history; h; h = h->next)
h->seen = 0;
hist_iterate_recurse(hist, fn, user);
}
@@ -273,7 +294,7 @@ static void dump_one(void *user, struct hist *h)
}
-void dump_hist(struct hist *h)
+void dump_hist(struct history *history, struct hist *h)
{
- hist_iterate(h, dump_one, NULL);
+ hist_iterate(history, h, dump_one, NULL);
}
diff --git a/file/git-hist.h b/file/git-hist.h
index ce2670e..b3b9c70 100644
--- a/file/git-hist.h
+++ b/file/git-hist.h
@@ -33,15 +33,18 @@ struct hist {
unsigned seen; /* for traversal */
};
+struct history;
+
bool vcs_git_try(const char *path);
-struct hist *vcs_git_hist(const char *path);
+struct history *vcs_git_history(const char *path);
+struct hist *vcs_head(const struct history *history);
char *vcs_git_get_rev(struct hist *h);
const char *vcs_git_summary(struct hist *hist);
char *vcs_git_long_for_pango(struct hist *hist,
char *(*formatter)(const char *fmt, ...));
-void hist_iterate(struct hist *h,
+void hist_iterate(struct history *history, struct hist *h,
void (*fn)(void *user, struct hist *h), void *user);
-void dump_hist(struct hist *h);
+void dump_hist(struct history *history, struct hist *h);
#endif /* !FILE_GIT_HIST_H */
diff --git a/gui/common.h b/gui/common.h
index 5148041..6ebc56b 100644
--- a/gui/common.h
+++ b/gui/common.h
@@ -80,7 +80,8 @@ struct gui {
int x, y; /* center, in eeschema coordinates */
struct gui_hist *hist; /* revision history; NULL if none */
- struct hist *vcs_hist; /* underlying VCS data; NULL if none */
+ struct history *vcs_history;
+ /* underlying VCS data; NULL if none */
enum gui_mode {
showing_sheet,
diff --git a/gui/gui.c b/gui/gui.c
index f203f6c..8cb17d8 100644
--- a/gui/gui.c
+++ b/gui/gui.c
@@ -391,8 +391,9 @@ static void get_revisions(struct gui *gui, const struct file_names *fn,
.limit = limit ? limit < 0 ? -limit : limit : -1,
};
- if (gui->vcs_hist)
- hist_iterate(gui->vcs_hist, add_hist, &add_hist_ctx);
+ if (gui->vcs_history)
+ hist_iterate(gui->vcs_history, vcs_head(gui->vcs_history),
+ add_hist, &add_hist_ctx);
else
add_hist(&add_hist_ctx, NULL);
}
@@ -412,15 +413,16 @@ static void count_history(void *user, struct hist *h)
static void get_history(struct gui *gui, const char *sch_name, int limit)
{
if (!vcs_git_try(sch_name)) {
- gui->vcs_hist = NULL;
+ gui->vcs_history = NULL;
return;
}
- gui->vcs_hist = vcs_git_hist(sch_name);
+ gui->vcs_history = vcs_git_history(sch_name);
if (limit)
gui->hist_size = limit > 0 ? limit : -limit;
else
- hist_iterate(gui->vcs_hist, count_history, gui);
+ hist_iterate(gui->vcs_history, vcs_head(gui->vcs_history),
+ count_history, gui);
}
@@ -448,7 +450,7 @@ int run_gui(const struct file_names *fn, bool recurse, int limit)
struct gui gui = {
.scale = 1 / 16.0,
.hist = NULL,
- .vcs_hist = NULL,
+ .vcs_history = NULL,
.mode = showing_sheet,
.sheet_overlays = NULL,
.hist_overlays = NULL,
diff --git a/gui/sheet.c b/gui/sheet.c
index f39bbd8..b1cb67c 100644
--- a/gui/sheet.c
+++ b/gui/sheet.c
@@ -364,7 +364,7 @@ void go_to_sheet(struct gui *gui, struct gui_sheet *sheet)
gui->curr_sheet = sheet;
if (gui->old_hist)
render_delta(gui);
- if (gui->vcs_hist)
+ if (gui->vcs_history && vcs_head(gui->vcs_history))
do_revision_overlays(gui);
do_sheet_overlays(gui);
zoom_to_extents(gui);
diff --git a/main.c b/main.c
index fddd9fa..618efd5 100644
--- a/main.c
+++ b/main.c
@@ -223,10 +223,10 @@ int main(int argc, char **argv)
}
if (history) {
- struct hist *h;
+ struct history *vcs_history = vcs_git_history(history);
+ struct hist *h = vcs_head(vcs_history);
- h = vcs_git_hist(history);
- dump_hist(h);
+ dump_hist(vcs_history, h);
return 0;
}