Thread (40 messages) 40 messages, 2 authors, 2016-06-15

Re: [RFC PATCH 07/15] cache_tree_update(): Capability to handle tree entries missing from index

flat view

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:49:30
Subsystem: the rest · Maintainer: Linus Torvalds

On Sun, Sep 5, 2010 at 10:13 AM, Elijah Newren [off-list ref] wrote:
quoted hunk ↗ jump to hunk
+static void add_missing_paths_before(const char *path,
+                                    int pathlen,
+                                    int baselen,
+                                    struct tree_desc *desc,
+                                    struct strbuf *buffer)
+{
+       if (!git_sparse_pathspecs)
+               return; /* No paths are missing */
+
+       for (; desc->size; update_tree_entry(desc)) {
+               struct name_entry entry = desc->entry;
+               int entlen = strlen(entry.path);
+
+               /* We only want paths before path */
+               if (path)
+                       /*
+                        * FIXME: if entlen < pathlen, do I need to
+                        * use strncmp instead? Does entry.path being
+                        * NUL-terminated ensure memcmp exits
+                        * early?
+                        */
+                       if (memcmp(entry.path,
+                                  path+baselen,
+                                  pathlen-baselen) >= 0)
+                               break;
If you do "break;" here, the current entry remains in "desc" and will
be used to regenerate a duplicate tree in
add_missing_paths_before(NULL, 0, 0, ..);. That entry is added the
first time by update_one itself before the second add_missing() call.
This fixes it for me
diff --git a/cache-tree.c b/cache-tree.c
index 79c28cc..1655738 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -278,17 +278,19 @@ static void add_missing_paths_before(const char *path,
 		int entlen = strlen(entry.path);

 		/* We only want paths before path */
-		if (path)
+		if (path) {
 			/*
 			 * FIXME: if entlen < pathlen, do I need to
 			 * use strncmp instead? Does entry.path being
 			 * NUL-terminated ensure memcmp exits
 			 * early?
 			 */
-			if (memcmp(entry.path,
-				   path+baselen,
-				   pathlen-baselen) >= 0)
+			int result = memcmp(entry.path, path+baselen, pathlen-baselen);
+			if (result > 0)
 				break;
+			if (!result)
+				continue;
+		}

 		/* We only want paths "missing" from index due to sparsity */
 		if (path) {
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help