From 376b4938efdfa01f27c0e0222e0c8087198946d8 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 23 Feb 2014 20:54:28 -0500 Subject: [PATCH] Move refs helpers to refs module --- include/refs.h | 5 ++++- src/refs.c | 17 ++++++++++++++++- src/tig.c | 17 ----------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/include/refs.h b/include/refs.h index ff882c2..5686944 100644 --- a/include/refs.h +++ b/include/refs.h @@ -34,10 +34,13 @@ struct ref_list { struct ref **refs; /* References for this ID. */ }; +#define is_initial_commit() (!get_ref_head()) +#define is_head_commit(rev) (!strcmp((rev), "HEAD") || (get_ref_head() && !strncmp(rev, get_ref_head()->id, SIZEOF_REV - 1))) + struct ref *get_ref_head(); struct ref_list *get_ref_list(const char *id); void foreach_ref(bool (*visitor)(void *data, const struct ref *ref), void *data); -int reload_refs(const char *git_dir, const char *remote_name, char *head, size_t headlen); +int load_refs(bool force); int add_ref(const char *id, char *name, const char *remote_name, const char *head); #endif diff --git a/src/refs.c b/src/refs.c index 2af443f..0e941ec 100644 --- a/src/refs.c +++ b/src/refs.c @@ -13,6 +13,7 @@ #include "tig.h" #include "io.h" +#include "repo.h" #include "refs.h" static struct ref **refs = NULL; @@ -213,7 +214,7 @@ read_ref(char *id, size_t idlen, char *name, size_t namelen, void *data) return add_to_refs(id, idlen, name, namelen, data); } -int +static int reload_refs(const char *git_dir, const char *remote_name, char *head, size_t headlen) { const char *head_argv[] = { @@ -261,6 +262,20 @@ reload_refs(const char *git_dir, const char *remote_name, char *head, size_t hea } int +load_refs(bool force) +{ + static bool loaded = FALSE; + + if (force) + repo.head[0] = 0; + else if (loaded) + return OK; + + loaded = TRUE; + return reload_refs(repo.git_dir, repo.remote, repo.head, sizeof(repo.head)); +} + +int add_ref(const char *id, char *name, const char *remote_name, const char *head) { struct ref_opt opt = { remote_name, head }; diff --git a/src/tig.c b/src/tig.c index f92c7b5..c80efb2 100644 --- a/src/tig.c +++ b/src/tig.c @@ -114,9 +114,6 @@ static char opt_env_lines[64] = ""; static char opt_env_columns[64] = ""; static char *opt_env[] = { opt_env_lines, opt_env_columns, NULL }; -#define is_initial_commit() (!get_ref_head()) -#define is_head_commit(rev) (!strcmp((rev), "HEAD") || (get_ref_head() && !strncmp(rev, get_ref_head()->id, SIZEOF_REV - 1))) - static bool vertical_split_is_enabled(void) { @@ -130,20 +127,6 @@ vertical_split_is_enabled(void) return opt_vertical_split == VERTICAL_SPLIT_VERTICAL; } -static inline int -load_refs(bool force) -{ - static bool loaded = FALSE; - - if (force) - repo.head[0] = 0; - else if (loaded) - return OK; - - loaded = TRUE; - return reload_refs(repo.git_dir, repo.remote, repo.head, sizeof(repo.head)); -} - static inline void update_diff_context_arg(int diff_context) { -- 2.11.4.GIT