From 899cb7a876a13f0031484db799a84b613c690c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 22 Oct 2011 11:36:18 +0200 Subject: [PATCH 1/4] status: remove git_index_entry_bypos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function is already implemented (better) as git_index_get. Change the only caller to use that function. Signed-off-by: Carlos Martín Nieto --- src/status.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/status.c b/src/status.c index 1deade9a5..62b3fcb7f 100644 --- a/src/status.c +++ b/src/status.c @@ -337,17 +337,6 @@ static const git_tree_entry *git_tree_entry_bypos(git_tree *tree, unsigned int i return git_vector_get(&tree->entries, idx); } -/* - * Convenience method to enumerate the index. This method is not supposed to be exposed - * as part of the index API because it precludes that the index will not be altered - * while the enumeration is being processed. Which wouldn't be very API friendly :) - */ -static const git_index_entry *git_index_entry_bypos(git_index *index, unsigned int idx) -{ - assert(index); - return git_vector_get(&index->entries, idx); -} - /* Greatly inspired from JGit IndexTreeWalker */ /* https://github.com/spearce/jgit/blob/ed47e29c777accfa78c6f50685a5df2b8f5b8ff5/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java#L88 */ @@ -371,7 +360,7 @@ static int dirent_cb(void *state, char *a) while (1) { m = git_tree_entry_bypos(st->tree, st->tree_position); - entry = git_index_entry_bypos(st->index, st->index_position); + entry = git_index_get(st->index, st->index_position); if ((m == NULL) && (a == NULL) && (entry == NULL)) return GIT_SUCCESS; From c2892d61acfe4ec1544a87e2455bb086bee96516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 22 Oct 2011 11:46:22 +0200 Subject: [PATCH 2/4] status: remove git_tree_entry_bypos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only caller has been changed to treat a NULL tree as a special case and use the existing git_tree_entry_byindex. Signed-off-by: Carlos Martín Nieto --- src/status.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/status.c b/src/status.c index 62b3fcb7f..7449335c2 100644 --- a/src/status.c +++ b/src/status.c @@ -324,19 +324,6 @@ static int compare(const char *left, const char *right) return strcmp(left, right); } -/* - * Convenience method to enumerate a tree. Contrarily to the git_tree_entry_byindex() - * method, it allows the tree to be enumerated to be NULL. In this case, every returned - * tree entry will be NULL as well. - */ -static const git_tree_entry *git_tree_entry_bypos(git_tree *tree, unsigned int idx) -{ - if (tree == NULL) - return NULL; - - return git_vector_get(&tree->entries, idx); -} - /* Greatly inspired from JGit IndexTreeWalker */ /* https://github.com/spearce/jgit/blob/ed47e29c777accfa78c6f50685a5df2b8f5b8ff5/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java#L88 */ @@ -359,7 +346,11 @@ static int dirent_cb(void *state, char *a) a_name = (path_type != GIT_STATUS_PATH_NULL) ? a + st->workdir_path_len : NULL; while (1) { - m = git_tree_entry_bypos(st->tree, st->tree_position); + if (st->tree == NULL) + m = NULL; + else + m = git_tree_entry_byindex(st->tree, st->tree_position); + entry = git_index_get(st->index, st->index_position); if ((m == NULL) && (a == NULL) && (entry == NULL)) From 68a26dfa7c61b6421d7a32176e83b36420b7201b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 22 Oct 2011 12:33:49 +0200 Subject: [PATCH 3/4] status: reorder retrieve_head_tree error checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- src/status.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/status.c b/src/status.c index 7449335c2..bda4ec59a 100644 --- a/src/status.c +++ b/src/status.c @@ -142,16 +142,14 @@ static int retrieve_head_tree(git_tree **tree_out, git_repository *repo) *tree_out = NULL; error = git_repository_head(&resolved_head_ref, repo); - if (error != GIT_SUCCESS && error != GIT_ENOTFOUND) - return git__rethrow(error, "HEAD can't be resolved"); - /* * We assume that a situation where HEAD exists but can not be resolved is valid. * A new repository fits this description for instance. */ - if (error == GIT_ENOTFOUND) return GIT_SUCCESS; + if (error < GIT_SUCCESS) + return git__rethrow(error, "HEAD can't be resolved"); if ((error = git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref))) < GIT_SUCCESS) return git__rethrow(error, "The tip of HEAD can't be retrieved"); From 1ca715e07a3d99b8a79ac606f7ddb81a10709a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 22 Oct 2011 12:36:30 +0200 Subject: [PATCH 4/4] status: move GIT_STATUS_PATH_* into an enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Their actual values have no meaning, so pack them in an enum. Signed-off-by: Carlos Martín Nieto --- src/status.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/status.c b/src/status.c index bda4ec59a..c53c4acc9 100644 --- a/src/status.c +++ b/src/status.c @@ -166,17 +166,19 @@ exit: return error; } -#define GIT_STATUS_PATH_NULL -2 -#define GIT_STATUS_PATH_IGNORE -1 -#define GIT_STATUS_PATH_FILE 0 -#define GIT_STATUS_PATH_FOLDER 1 +enum path_type { + GIT_STATUS_PATH_NULL, + GIT_STATUS_PATH_IGNORE, + GIT_STATUS_PATH_FILE, + GIT_STATUS_PATH_FOLDER, +}; static int dirent_cb(void *state, char *full_path); static int alphasorted_futils_direach( char *path, size_t path_sz, int (*fn)(void *, char *), void *arg); -static int process_folder(struct status_st *st, const git_tree_entry *tree_entry, char *full_path, int path_type) +static int process_folder(struct status_st *st, const git_tree_entry *tree_entry, char *full_path, enum path_type path_type) { git_object *subtree = NULL; git_tree *pushed_tree = NULL; @@ -240,7 +242,7 @@ static int determine_status(struct status_st *st, const git_index_entry *index_entry, char *full_path, const char *status_path, - int path_type) + enum path_type path_type) { struct status_entry *e; int error = GIT_SUCCESS; @@ -329,7 +331,7 @@ static int dirent_cb(void *state, char *a) { const git_tree_entry *m; const git_index_entry *entry; - int path_type; + enum path_type path_type; int cmpma, cmpmi, cmpai, error; const char *pm, *pa, *pi; const char *m_name, *i_name, *a_name;