Commit e3baa3cc by nulltoken

status: Fix a sorting issue in the treewalker

This ensures that entries from the working directory are retrieved according to the following rules:

 - The file "subdir" should appear before the file "subdir.txt"
 - The folder "subdir" should appear after the file "subdir.txt"
parent a1bd78ea
...@@ -291,7 +291,7 @@ static int path_type_from(char *full_path, int is_dir) ...@@ -291,7 +291,7 @@ static int path_type_from(char *full_path, int is_dir)
if (!is_dir) if (!is_dir)
return GIT_STATUS_PATH_FILE; 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_IGNORE;
return GIT_STATUS_PATH_FOLDER; return GIT_STATUS_PATH_FOLDER;
...@@ -360,7 +360,13 @@ static int dirent_cb(void *state, char *a) ...@@ -360,7 +360,13 @@ static int dirent_cb(void *state, char *a)
if (m != NULL) { if (m != NULL) {
st->head_tree_relative_path[st->head_tree_relative_path_len] = '\0'; 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; m_name = st->head_tree_relative_path;
} else } else
m_name = NULL; m_name = NULL;
...@@ -378,7 +384,7 @@ static int dirent_cb(void *state, char *a) ...@@ -378,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) 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); 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; return GIT_SUCCESS;
} }
} }
...@@ -571,19 +577,32 @@ struct alphasorted_dirent_info { ...@@ -571,19 +577,32 @@ struct alphasorted_dirent_info {
static struct alphasorted_dirent_info *alphasorted_dirent_info_new(const char *path) static struct alphasorted_dirent_info *alphasorted_dirent_info_new(const char *path)
{ {
int is_dir; int is_dir, size;
struct alphasorted_dirent_info *di; struct alphasorted_dirent_info *di;
is_dir = git_futils_isdir(path) == GIT_SUCCESS ? 1 : 0; 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) if (di == NULL)
return NULL; return NULL;
memset(di, 0x0, sizeof(*di)); memset(di, 0x0, size);
strcpy(di->path, path); 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; return di;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment