summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2011-10-29 14:06:36 -0700
committerVicent Martí <tanoku@gmail.com>2011-10-29 14:06:36 -0700
commitd3104fa0a3f3711729b45346e475354440d46cc3 (patch)
treeb003647853dbe3b0b703abc41654a5da36587c2e
parent89fb8f025a1f72b90f1f9563c85bf43b7f66ba60 (diff)
parente3baa3ccf3b606517b3819913228c030854b8d77 (diff)
downloadlibgit2-d3104fa0a3f3711729b45346e475354440d46cc3.tar.gz
Merge pull request #468 from nulltoken/ntk/fix/issue-465
Status: fix segfault (#465) and order issues
-rw-r--r--src/status.c75
-rw-r--r--tests/resources/status/.gitted/COMMIT_EDITMSG2
-rw-r--r--tests/resources/status/.gitted/ORIG_HEAD2
-rw-r--r--tests/resources/status/.gitted/indexbin1080 -> 1160 bytes
-rw-r--r--tests/resources/status/.gitted/logs/HEAD1
-rw-r--r--tests/resources/status/.gitted/logs/refs/heads/master1
-rw-r--r--tests/resources/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f2
-rw-r--r--tests/resources/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0bin0 -> 331 bytes
-rw-r--r--tests/resources/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972ebin0 -> 38 bytes
-rw-r--r--tests/resources/status/.gitted/refs/heads/master2
-rw-r--r--tests/resources/status/subdir.txt2
11 files changed, 57 insertions, 30 deletions
diff --git a/src/status.c b/src/status.c
index 1fc3794ea..d50199d9a 100644
--- a/src/status.c
+++ b/src/status.c
@@ -183,26 +183,28 @@ static int process_folder(struct status_st *st, const git_tree_entry *tree_entry
git_object *subtree = NULL;
git_tree *pushed_tree = NULL;
int error, pushed_tree_position = 0;
- git_otype tree_entry_type;
-
- tree_entry_type = git_tree_entry_type(tree_entry);
-
- switch (tree_entry_type) {
- case GIT_OBJ_TREE:
- error = git_tree_entry_2object(&subtree, ((git_object *)(st->tree))->repo, tree_entry);
- pushed_tree = st->tree;
- pushed_tree_position = st->tree_position;
- st->tree = (git_tree *)subtree;
- st->tree_position = 0;
- st->head_tree_relative_path_len += 1 + tree_entry->filename_len; /* path + '/' + name */
- break;
-
- case GIT_OBJ_BLOB:
- /* No op */
- break;
-
- default:
- error = git__throw(GIT_EINVALIDTYPE, "Unexpected tree entry type"); /* TODO: How should we deal with submodules? */
+ git_otype tree_entry_type = GIT_OBJ_BAD;
+
+ if (tree_entry != NULL) {
+ tree_entry_type = git_tree_entry_type(tree_entry);
+
+ switch (tree_entry_type) {
+ case GIT_OBJ_TREE:
+ error = git_tree_entry_2object(&subtree, ((git_object *)(st->tree))->repo, tree_entry);
+ pushed_tree = st->tree;
+ pushed_tree_position = st->tree_position;
+ st->tree = (git_tree *)subtree;
+ st->tree_position = 0;
+ st->head_tree_relative_path_len += 1 + tree_entry->filename_len; /* path + '/' + name */
+ break;
+
+ case GIT_OBJ_BLOB:
+ /* No op */
+ break;
+
+ default:
+ error = git__throw(GIT_EINVALIDTYPE, "Unexpected tree entry type"); /* TODO: How should we deal with submodules? */
+ }
}
if (full_path != NULL && path_type == GIT_STATUS_PATH_FOLDER)
@@ -289,7 +291,7 @@ static int path_type_from(char *full_path, int is_dir)
if (!is_dir)
return GIT_STATUS_PATH_FILE;
- if (!git__suffixcmp(full_path, "/" DOT_GIT))
+ if (!git__suffixcmp(full_path, "/" DOT_GIT "/"))
return GIT_STATUS_PATH_IGNORE;
return GIT_STATUS_PATH_FOLDER;
@@ -358,7 +360,13 @@ static int dirent_cb(void *state, char *a)
if (m != NULL) {
st->head_tree_relative_path[st->head_tree_relative_path_len] = '\0';
- git_path_join(st->head_tree_relative_path, st->head_tree_relative_path, m->filename);
+
+ /* When the tree entry is a folder, append a forward slash to its name */
+ if (git_tree_entry_type(m) == GIT_OBJ_TREE)
+ git_path_join_n(st->head_tree_relative_path, 3, st->head_tree_relative_path, m->filename, "");
+ else
+ git_path_join(st->head_tree_relative_path, st->head_tree_relative_path, m->filename);
+
m_name = st->head_tree_relative_path;
} else
m_name = NULL;
@@ -376,7 +384,7 @@ static int dirent_cb(void *state, char *a)
if((error = determine_status(st, pm != NULL, pi != NULL, pa != NULL, m, entry, a, status_path(pm, pi, pa), path_type)) < GIT_SUCCESS)
return git__rethrow(error, "An error occured while determining the status of '%s'", a);
- if (pa != NULL)
+ if ((pa != NULL) || (path_type == GIT_STATUS_PATH_FOLDER))
return GIT_SUCCESS;
}
}
@@ -569,19 +577,32 @@ struct alphasorted_dirent_info {
static struct alphasorted_dirent_info *alphasorted_dirent_info_new(const char *path)
{
- int is_dir;
+ int is_dir, size;
struct alphasorted_dirent_info *di;
is_dir = git_futils_isdir(path) == GIT_SUCCESS ? 1 : 0;
+ size = sizeof(*di) + (is_dir ? GIT_PATH_MAX : strlen(path)) + 2;
- di = git__malloc(sizeof(*di) + (is_dir ? GIT_PATH_MAX : strlen(path)) + 1);
+ di = git__malloc(size);
if (di == NULL)
return NULL;
- memset(di, 0x0, sizeof(*di));
+ memset(di, 0x0, size);
strcpy(di->path, path);
- di->is_dir = is_dir;
+
+ if (is_dir) {
+ di->is_dir = 1;
+
+ /*
+ * Append a forward slash to the name to force folders
+ * to be ordered in a similar way than in a tree
+ *
+ * The file "subdir" should appear before the file "subdir.txt"
+ * The folder "subdir" should appear after the file "subdir.txt"
+ */
+ di->path[strlen(path)] = '/';
+ }
return di;
}
diff --git a/tests/resources/status/.gitted/COMMIT_EDITMSG b/tests/resources/status/.gitted/COMMIT_EDITMSG
index ff887ba13..1a25cd4a6 100644
--- a/tests/resources/status/.gitted/COMMIT_EDITMSG
+++ b/tests/resources/status/.gitted/COMMIT_EDITMSG
@@ -1 +1 @@
-add subdir
+Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker
diff --git a/tests/resources/status/.gitted/ORIG_HEAD b/tests/resources/status/.gitted/ORIG_HEAD
index c2805f422..b46871fd6 100644
--- a/tests/resources/status/.gitted/ORIG_HEAD
+++ b/tests/resources/status/.gitted/ORIG_HEAD
@@ -1 +1 @@
-0017bd4ab1ec30440b17bae1680cff124ab5f1f6
+735b6a258cd196a8f7c9428419b02c1dca93fd75
diff --git a/tests/resources/status/.gitted/index b/tests/resources/status/.gitted/index
index 5c4b18841..d793791c9 100644
--- a/tests/resources/status/.gitted/index
+++ b/tests/resources/status/.gitted/index
Binary files differ
diff --git a/tests/resources/status/.gitted/logs/HEAD b/tests/resources/status/.gitted/logs/HEAD
index e876bd80b..7b95b3cf1 100644
--- a/tests/resources/status/.gitted/logs/HEAD
+++ b/tests/resources/status/.gitted/logs/HEAD
@@ -1,2 +1,3 @@
0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny <jasonpenny4@gmail.com> 1308050070 -0400 commit (initial): initial
0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny <jasonpenny4@gmail.com> 1308954538 -0400 commit: add subdir
+735b6a258cd196a8f7c9428419b02c1dca93fd75 26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f nulltoken <emeric.fermas@gmail.com> 1319911544 +0200 commit: Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker
diff --git a/tests/resources/status/.gitted/logs/refs/heads/master b/tests/resources/status/.gitted/logs/refs/heads/master
index e876bd80b..7b95b3cf1 100644
--- a/tests/resources/status/.gitted/logs/refs/heads/master
+++ b/tests/resources/status/.gitted/logs/refs/heads/master
@@ -1,2 +1,3 @@
0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny <jasonpenny4@gmail.com> 1308050070 -0400 commit (initial): initial
0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny <jasonpenny4@gmail.com> 1308954538 -0400 commit: add subdir
+735b6a258cd196a8f7c9428419b02c1dca93fd75 26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f nulltoken <emeric.fermas@gmail.com> 1319911544 +0200 commit: Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker
diff --git a/tests/resources/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f b/tests/resources/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f
new file mode 100644
index 000000000..f7dddc4ff
--- /dev/null
+++ b/tests/resources/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f
@@ -0,0 +1,2 @@
+xMn )V (̀BD޾LЍRȷވ@,9̜tNj6f`M6Z;h Zp ڙY,37/;42x&<z #^
+䮁ZQ0嫫pޙ`l?{@)1+=#ö6j#֧qP>gϟۉIm|j \ No newline at end of file
diff --git a/tests/resources/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0 b/tests/resources/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0
new file mode 100644
index 000000000..b75481b51
--- /dev/null
+++ b/tests/resources/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0
Binary files differ
diff --git a/tests/resources/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972e b/tests/resources/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972e
new file mode 100644
index 000000000..cfc2413d5
--- /dev/null
+++ b/tests/resources/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972e
Binary files differ
diff --git a/tests/resources/status/.gitted/refs/heads/master b/tests/resources/status/.gitted/refs/heads/master
index b46871fd6..3e2e2a07a 100644
--- a/tests/resources/status/.gitted/refs/heads/master
+++ b/tests/resources/status/.gitted/refs/heads/master
@@ -1 +1 @@
-735b6a258cd196a8f7c9428419b02c1dca93fd75
+26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f
diff --git a/tests/resources/status/subdir.txt b/tests/resources/status/subdir.txt
new file mode 100644
index 000000000..e8ee89e15
--- /dev/null
+++ b/tests/resources/status/subdir.txt
@@ -0,0 +1,2 @@
+Is it a bird?
+Is it a plane?