sequencer: refactor transform_todos() to work on a todo_list
[gitweb.git] / tree-walk.c
index e11b3063afa610239162dc45c24528dd144c4759..79bafbd1a23c4a9e20ec623c084778904c534be7 100644 (file)
@@ -2,6 +2,7 @@
 #include "tree-walk.h"
 #include "unpack-trees.h"
 #include "dir.h"
+#include "object-store.h"
 #include "tree.h"
 #include "pathspec.h"
 
@@ -26,8 +27,9 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
 {
        const char *path;
        unsigned int mode, len;
+       const unsigned hashsz = the_hash_algo->rawsz;
 
-       if (size < 23 || buf[size - 21]) {
+       if (size < hashsz + 3 || buf[size - (hashsz + 1)]) {
                strbuf_addstr(err, _("too-short tree object"));
                return -1;
        }
@@ -105,7 +107,7 @@ static void entry_extract(struct tree_desc *t, struct name_entry *a)
 static int update_tree_entry_internal(struct tree_desc *desc, struct strbuf *err)
 {
        const void *buf = desc->buffer;
-       const unsigned char *end = desc->entry.oid->hash + 20;
+       const unsigned char *end = desc->entry.oid->hash + the_hash_algo->rawsz;
        unsigned long size = desc->size;
        unsigned long len = end - (const unsigned char *)buf;
 
@@ -488,7 +490,7 @@ int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
 struct dir_state {
        void *tree;
        unsigned long size;
-       unsigned char sha1[20];
+       struct object_id oid;
 };
 
 static int find_tree_entry(struct tree_desc *t, const char *name, struct object_id *result, unsigned *mode)
@@ -576,7 +578,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob
  * See the code for enum follow_symlink_result for a description of
  * the return values.
  */
-enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_sha1, const char *name, unsigned char *result, struct strbuf *result_path, unsigned *mode)
+enum follow_symlinks_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned *mode)
 {
        int retval = MISSING_OBJECT;
        struct dir_state *parents = NULL;
@@ -589,7 +591,7 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
 
        init_tree_desc(&t, NULL, 0UL);
        strbuf_addstr(&namebuf, name);
-       hashcpy(current_tree_oid.hash, tree_sha1);
+       oidcpy(&current_tree_oid, tree_oid);
 
        while (1) {
                int find_result;
@@ -609,11 +611,11 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
                        ALLOC_GROW(parents, parents_nr + 1, parents_alloc);
                        parents[parents_nr].tree = tree;
                        parents[parents_nr].size = size;
-                       hashcpy(parents[parents_nr].sha1, root.hash);
+                       oidcpy(&parents[parents_nr].oid, &root);
                        parents_nr++;
 
                        if (namebuf.buf[0] == '\0') {
-                               hashcpy(result, root.hash);
+                               oidcpy(result, &root);
                                retval = FOUND;
                                goto done;
                        }
@@ -663,7 +665,7 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
 
                /* We could end up here via a symlink to dir/.. */
                if (namebuf.buf[0] == '\0') {
-                       hashcpy(result, parents[parents_nr - 1].sha1);
+                       oidcpy(result, &parents[parents_nr - 1].oid);
                        retval = FOUND;
                        goto done;
                }
@@ -677,7 +679,7 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
 
                if (S_ISDIR(*mode)) {
                        if (!remainder) {
-                               hashcpy(result, current_tree_oid.hash);
+                               oidcpy(result, &current_tree_oid);
                                retval = FOUND;
                                goto done;
                        }
@@ -687,7 +689,7 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
                                      1 + first_slash - namebuf.buf);
                } else if (S_ISREG(*mode)) {
                        if (!remainder) {
-                               hashcpy(result, current_tree_oid.hash);
+                               oidcpy(result, &current_tree_oid);
                                retval = FOUND;
                        } else {
                                retval = NOT_DIR;
@@ -1105,7 +1107,7 @@ enum interesting tree_entry_interesting(const struct name_entry *entry,
         *   5  |  file |    1     |    1     |   0
         *   6  |  file |    1     |    2     |   0
         *   7  |  file |    2     |   -1     |   2
-        *   8  |  file |    2     |    0     |   2
+        *   8  |  file |    2     |    0     |   1
         *   9  |  file |    2     |    1     |   0
         *  10  |  file |    2     |    2     |  -1
         * -----+-------+----------+----------+-------
@@ -1116,7 +1118,7 @@ enum interesting tree_entry_interesting(const struct name_entry *entry,
         *  15  |  dir  |    1     |    1     |   1 (*)
         *  16  |  dir  |    1     |    2     |   0
         *  17  |  dir  |    2     |   -1     |   2
-        *  18  |  dir  |    2     |    0     |   2
+        *  18  |  dir  |    2     |    0     |   1
         *  19  |  dir  |    2     |    1     |   1 (*)
         *  20  |  dir  |    2     |    2     |  -1
         *
@@ -1132,7 +1134,12 @@ enum interesting tree_entry_interesting(const struct name_entry *entry,
 
        negative = do_match(entry, base, base_offset, ps, 1);
 
-       /* #3, #4, #7, #8, #13, #14, #17, #18 */
+       /* #8, #18 */
+       if (positive == all_entries_interesting &&
+           negative == entry_not_interesting)
+               return entry_interesting;
+
+       /* #3, #4, #7, #13, #14, #17 */
        if (negative <= entry_not_interesting)
                return positive;