Skip to content

Commit a8c4047

Browse files
torvaldsJunio C Hamano
authored andcommitted
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>
1 parent 171dccd commit a8c4047

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

builtin-grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
378378
* decide if we want to descend into "abc"
379379
* directory.
380380
*/
381-
strcpy(path_buf + len + entry.pathlen, "/");
381+
strcpy(path_buf + len + tree_entry_len(entry.path, entry.sha1), "/");
382382

383383
if (!pathspec_matches(paths, down))
384384
;

builtin-pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ static void add_pbase_object(struct tree_desc *tree,
854854
unsigned long size;
855855
enum object_type type;
856856

857-
if (entry.pathlen != cmplen ||
857+
if (tree_entry_len(entry.path, entry.sha1) != cmplen ||
858858
memcmp(entry.path, name, cmplen) ||
859859
!has_sha1_file(entry.sha1) ||
860860
(type = sha1_object_info(entry.sha1, &size)) < 0)

merge-tree.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void resolve(const char *base, struct name_entry *branch1, struct name_en
188188

189189
static int unresolved_directory(const char *base, struct name_entry n[3])
190190
{
191-
int baselen;
191+
int baselen, pathlen;
192192
char *newbase;
193193
struct name_entry *p;
194194
struct tree_desc t[3];
@@ -205,10 +205,11 @@ static int unresolved_directory(const char *base, struct name_entry n[3])
205205
if (!S_ISDIR(p->mode))
206206
return 0;
207207
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);
209210
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);
212213

213214
buf0 = fill_tree_descriptor(t+0, n[0].sha1);
214215
buf1 = fill_tree_descriptor(t+1, n[1].sha1);

tree-walk.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
2020
static int entry_compare(struct name_entry *a, struct name_entry *b)
2121
{
2222
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);
2525
}
2626

2727
static void entry_clear(struct name_entry *a)
@@ -32,7 +32,6 @@ static void entry_clear(struct name_entry *a)
3232
static void entry_extract(struct tree_desc *t, struct name_entry *a)
3333
{
3434
a->sha1 = tree_entry_extract(t, &a->path, &a->mode);
35-
a->pathlen = tree_entry_len(a->path, a->sha1);
3635
}
3736

3837
void update_tree_entry(struct tree_desc *desc)
@@ -93,7 +92,6 @@ int tree_entry(struct tree_desc *desc, struct name_entry *entry)
9392

9493
entry->path = path;
9594
len = strlen(path);
96-
entry->pathlen = len;
9795

9896
path += len + 1;
9997
entry->sha1 = (const unsigned char *) path;

tree-walk.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ struct name_entry {
1010
const unsigned char *sha1;
1111
const char *path;
1212
unsigned int mode;
13-
int pathlen;
1413
};
1514

1615
static inline int tree_entry_len(const char *name, const unsigned char *sha1)

tree.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ int read_tree_recursive(struct tree *tree,
101101
if (S_ISDIR(entry.mode)) {
102102
int retval;
103103
char *newbase;
104+
unsigned int pathlen = tree_entry_len(entry.path, entry.sha1);
104105

105-
newbase = xmalloc(baselen + 1 + entry.pathlen);
106+
newbase = xmalloc(baselen + 1 + pathlen);
106107
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] = '/';
109110
retval = read_tree_recursive(lookup_tree(entry.sha1),
110111
newbase,
111-
baselen + entry.pathlen + 1,
112+
baselen + pathlen + 1,
112113
stage, match, fn);
113114
free(newbase);
114115
if (retval)

0 commit comments

Comments
 (0)