Remove "pathlen" from "struct name_entry"
Since we have the "tree_entry_len()" helper function these days, and don't need to do a full strlen(), there's no point in saving the path length - it's just redundant information. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Mar 21, 2007 at 10:07 UTC
a8c40471ab0851bf9a58f7dc76f121258e0690e2
6 files changed
+14
-15
builtin-grep.c
+1
-1
@@ -378,7 +378,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
378
* decide if we want to descend into "abc"
379
* directory.
380
*/
381
- strcpy(path_buf + len + entry.pathlen, "/");
381
+ strcpy(path_buf + len + tree_entry_len(entry.path, entry.sha1), "/");
382
383
if (!pathspec_matches(paths, down))
384
;
builtin-pack-objects.c
+1
-1
@@ -854,7 +854,7 @@ static void add_pbase_object(struct tree_desc *tree,
854
unsigned long size;
855
enum object_type type;
856
857
- if (entry.pathlen != cmplen ||
857
+ if (tree_entry_len(entry.path, entry.sha1) != cmplen ||
858
memcmp(entry.path, name, cmplen) ||
859
!has_sha1_file(entry.sha1) ||
860
(type = sha1_object_info(entry.sha1, &size)) < 0)
merge-tree.c
+5
-4
@@ -188,7 +188,7 @@ static void resolve(const char *base, struct name_entry *branch1, struct name_en
188
189
static int unresolved_directory(const char *base, struct name_entry n[3])
190
{
191
- int baselen;
191
+ int baselen, pathlen;
192
char *newbase;
193
struct name_entry *p;
194
struct tree_desc t[3];
@@ -205,10 +205,11 @@ static int unresolved_directory(const char *base, struct name_entry n[3])
205
if (!S_ISDIR(p->mode))
206
return 0;
207
baselen = strlen(base);
208
- newbase = xmalloc(baselen + p->pathlen + 2);
208
+ pathlen = tree_entry_len(p->path, p->sha1);
209
+ newbase = xmalloc(baselen + pathlen + 2);
210
memcpy(newbase, base, baselen);
210
- memcpy(newbase + baselen, p->path, p->pathlen);
211
- memcpy(newbase + baselen + p->pathlen, "/", 2);
211
+ memcpy(newbase + baselen, p->path, pathlen);
212
+ memcpy(newbase + baselen + pathlen, "/", 2);
213
214
buf0 = fill_tree_descriptor(t+0, n[0].sha1);
215
buf1 = fill_tree_descriptor(t+1, n[1].sha1);
tree-walk.c
+2
-4
@@ -20,8 +20,8 @@ void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
20
static int entry_compare(struct name_entry *a, struct name_entry *b)
21
{
22
return base_name_compare(
23
- a->path, a->pathlen, a->mode,
24
- b->path, b->pathlen, b->mode);
23
+ a->path, tree_entry_len(a->path, a->sha1), a->mode,
24
+ b->path, tree_entry_len(b->path, b->sha1), b->mode);
25
}
26
27
static void entry_clear(struct name_entry *a)
@@ -32,7 +32,6 @@ static void entry_clear(struct name_entry *a)
32
static void entry_extract(struct tree_desc *t, struct name_entry *a)
33
{
34
a->sha1 = tree_entry_extract(t, &a->path, &a->mode);
35
- a->pathlen = tree_entry_len(a->path, a->sha1);
35
}
36
37
void update_tree_entry(struct tree_desc *desc)
@@ -93,7 +92,6 @@ int tree_entry(struct tree_desc *desc, struct name_entry *entry)
92
93
entry->path = path;
94
len = strlen(path);
96
- entry->pathlen = len;
95
96
path += len + 1;
97
entry->sha1 = (const unsigned char *) path;
tree-walk.h
-1
@@ -10,7 +10,6 @@ struct name_entry {
10
const unsigned char *sha1;
11
const char *path;
12
unsigned int mode;
13
- int pathlen;
13
};
14
15
static inline int tree_entry_len(const char *name, const unsigned char *sha1)
tree.c
+5
-4
@@ -101,14 +101,15 @@ int read_tree_recursive(struct tree *tree,
101
if (S_ISDIR(entry.mode)) {
102
int retval;
103
char *newbase;
104
+ unsigned int pathlen = tree_entry_len(entry.path, entry.sha1);
105
105
- newbase = xmalloc(baselen + 1 + entry.pathlen);
106
+ newbase = xmalloc(baselen + 1 + pathlen);
107
memcpy(newbase, base, baselen);
107
- memcpy(newbase + baselen, entry.path, entry.pathlen);
108
- newbase[baselen + entry.pathlen] = '/';
108
+ memcpy(newbase + baselen, entry.path, pathlen);
109
+ newbase[baselen + pathlen] = '/';
110
retval = read_tree_recursive(lookup_tree(entry.sha1),
111
newbase,
111
- baselen + entry.pathlen + 1,
112
+ baselen + pathlen + 1,
113
stage, match, fn);
114
free(newbase);
115
if (retval)