632
return ret;
633
}
634
635
-static int find_cache_pos(struct traverse_info *, const struct name_entry *);
635
+static int find_cache_pos(struct traverse_info *, const char *p, size_t len);
636
637
static void restore_cache_bottom(struct traverse_info *info, int bottom)
638
{
651
if (o->diff_index_cached)
652
return 0;
653
ret = o->cache_bottom;
654
- pos = find_cache_pos(info->prev, &info->name);
654
+ pos = find_cache_pos(info->prev, info->name, info->namelen);
655
656
if (pos < -1)
657
o->cache_bottom = -2 - pos;
690
char *name = xmalloc(len + 1 /* slash */ + 1 /* NUL */);
691
int pos;
692
693
- make_traverse_path(name, info, names);
693
+ make_traverse_path(name, info, names->path, names->pathlen);
694
name[len++] = '/';
695
name[len] = '\0';
696
pos = index_name_pos(o->src_index, name, len);
811
newinfo = *info;
812
newinfo.prev = info;
813
newinfo.pathspec = info->pathspec;
814
- newinfo.name = *p;
814
+ newinfo.name = p->path;
815
+ newinfo.namelen = p->pathlen;
816
+ newinfo.mode = p->mode;
817
newinfo.pathlen += tree_entry_len(p) + 1;
818
newinfo.df_conflicts |= df_conflicts;
819
865
* itself - the caller needs to do the final check for the cache
866
* entry having more data at the end!
867
*/
866
-static int do_compare_entry_piecewise(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
868
+static int do_compare_entry_piecewise(const struct cache_entry *ce,
869
+ const struct traverse_info *info,
870
+ const char *name, size_t namelen,
871
+ unsigned mode)
872
{
868
- int len, pathlen, ce_len;
873
+ int pathlen, ce_len;
874
const char *ce_name;
875
876
if (info->prev) {
877
int cmp = do_compare_entry_piecewise(ce, info->prev,
873
- &info->name);
878
+ info->name, info->namelen,
879
+ info->mode);
880
if (cmp)
881
return cmp;
882
}
890
ce_len -= pathlen;
891
ce_name = ce->name + pathlen;
892
887
- len = tree_entry_len(n);
888
- return df_name_compare(ce_name, ce_len, S_IFREG, n->path, len, n->mode);
893
+ return df_name_compare(ce_name, ce_len, S_IFREG, name, namelen, mode);
894
}
895
896
static int do_compare_entry(const struct cache_entry *ce,
897
const struct traverse_info *info,
893
- const struct name_entry *n)
898
+ const char *name, size_t namelen,
899
+ unsigned mode)
900
{
895
- int len, pathlen, ce_len;
901
+ int pathlen, ce_len;
902
const char *ce_name;
903
int cmp;
904
908
* it is quicker to use the precomputed version.
909
*/
910
if (!info->traverse_path)
905
- return do_compare_entry_piecewise(ce, info, n);
911
+ return do_compare_entry_piecewise(ce, info, name, namelen, mode);
912
913
cmp = strncmp(ce->name, info->traverse_path, info->pathlen);
914
if (cmp)
923
ce_len -= pathlen;
924
ce_name = ce->name + pathlen;
925
920
- len = tree_entry_len(n);
921
- return df_name_compare(ce_name, ce_len, S_IFREG, n->path, len, n->mode);
926
+ return df_name_compare(ce_name, ce_len, S_IFREG, name, namelen, mode);
927
}
928
929
static int compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
930
{
926
- int cmp = do_compare_entry(ce, info, n);
931
+ int cmp = do_compare_entry(ce, info, n->path, n->pathlen, n->mode);
932
if (cmp)
933
return cmp;
934
944
{
945
if (!info->prev)
946
return 1;
942
- if (do_compare_entry(ce, info->prev, &info->name))
947
+ if (do_compare_entry(ce, info->prev,
948
+ info->name, info->namelen, info->mode))
949
return 0;
950
/*
951
* If ce (blob) is the same name as the path (which is a tree
970
ce->ce_flags = create_ce_flags(stage);
971
ce->ce_namelen = len;
972
oidcpy(&ce->oid, &n->oid);
967
- make_traverse_path(ce->name, info, n);
973
+ make_traverse_path(ce->name, info, n->path, n->pathlen);
974
975
return ce;
976
}
1063
* the directory.
1064
*/
1065
static int find_cache_pos(struct traverse_info *info,
1060
- const struct name_entry *p)
1066
+ const char *p, size_t p_len)
1067
{
1068
int pos;
1069
struct unpack_trees_options *o = info->data;
1070
struct index_state *index = o->src_index;
1071
int pfxlen = info->pathlen;
1066
- int p_len = tree_entry_len(p);
1072
1073
for (pos = o->cache_bottom; pos < index->cache_nr; pos++) {
1074
const struct cache_entry *ce = index->cache[pos];
1104
ce_len = ce_slash - ce_name;
1105
else
1106
ce_len = ce_namelen(ce) - pfxlen;
1102
- cmp = name_compare(p->path, p_len, ce_name, ce_len);
1107
+ cmp = name_compare(p, p_len, ce_name, ce_len);
1108
/*
1109
* Exact match; if we have a directory we need to
1110
* delay returning it.
1119
* E.g. ce_name == "t-i", and p->path == "t"; we may
1120
* have "t/a" in the index.
1121
*/
1117
- if (p_len < ce_len && !memcmp(ce_name, p->path, p_len) &&
1122
+ if (p_len < ce_len && !memcmp(ce_name, p, p_len) &&
1123
ce_name[p_len] < '/')
1124
continue; /* keep looking */
1125
break;
1130
static struct cache_entry *find_cache_entry(struct traverse_info *info,
1131
const struct name_entry *p)
1132
{
1128
- int pos = find_cache_pos(info, p);
1133
+ int pos = find_cache_pos(info, p->path, p->pathlen);
1134
struct unpack_trees_options *o = info->data;
1135
1136
if (0 <= pos)
1143
{
1144
if (info->prev) {
1145
debug_path(info->prev);
1141
- if (*info->prev->name.path)
1146
+ if (*info->prev->name)
1147
putchar('/');
1148
}
1144
- printf("%s", info->name.path);
1149
+ printf("%s", info->name);
1150
}
1151
1152
static void debug_name_entry(int i, struct name_entry *n)