Thread (31 messages) flat view 31 messages, 4 authors, 2016-06-15

Re: [PATCH 02/16] list-objects: limit traversing within the given subtree if core.subtree is set

From: Elijah Newren <hidden>
Date: 2016-06-15 22:49:14

Hi,

2010/7/31 Nguyễn Thái Ngọc Duy [off-list ref]:
quoted hunk ↗ jump to hunk
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 list-objects.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/list-objects.c b/list-objects.c
index 8953548..1b25b54 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -61,12 +61,15 @@ static void process_tree(struct rev_info *revs,
                        struct tree *tree,
                        show_object_fn show,
                        struct name_path *path,
-                        const char *name)
+                        const char *name,
+                        const char *subtree)
 {
       struct object *obj = &tree->object;
       struct tree_desc desc;
       struct name_entry entry;
       struct name_path me;
+       const char *slash;
+       int subtree_len;
Perhaps slash should be initialized to NULL?  Otherwise I think it
will be used uninitialized.
quoted hunk ↗ jump to hunk
       if (!revs->tree_objects)
               return;
@@ -82,13 +85,21 @@ static void process_tree(struct rev_info *revs,
       me.elem = name;
       me.elem_len = strlen(name);

+       if (subtree) {
+               slash = strchr(subtree, '/');
+               subtree_len = slash ? slash - subtree : strlen(subtree);
+       }
+
       init_tree_desc(&desc, tree->buffer, tree->size);

       while (tree_entry(&desc, &entry)) {
-               if (S_ISDIR(entry.mode))
-                       process_tree(revs,
-                                    lookup_tree(entry.sha1),
-                                    show, &me, entry.path);
+               if (S_ISDIR(entry.mode)) {
+                       if (!subtree || !strncmp(entry.path, subtree, subtree_len))
Only one subdirectory allowed?  What if someone wants a sparse clone
containing two or more directories?  (Actually, that's not so much of
a "what if" -- it's exactly what I want in about half my usecases for
sparse clones.)
+                               process_tree(revs,
+                                            lookup_tree(entry.sha1),
+                                            show, &me, entry.path,
+                                            slash && slash[1] ? slash+1 : NULL);
If I read correctly, slash will be used uninitialized here whenever
subtree == NULL.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help