719
return ret;
720
}
721
722
-static void one_remote_object(const char *hex)
722
+static void one_remote_object(const unsigned char *sha1)
723
{
724
- unsigned char sha1[20];
724
struct object *obj;
725
727
- if (get_sha1_hex(hex, sha1) != 0)
728
- return;
729
-
726
obj = lookup_object(sha1);
727
if (!obj)
728
obj = parse_object(sha1);
1016
void (*userFunc)(struct remote_ls_ctx *ls),
1017
void *userData);
1018
1019
+/* extract hex from sharded "xx/x{40}" filename */
1020
+static int get_sha1_hex_from_objpath(const char *path, unsigned char *sha1)
1021
+{
1022
+ char hex[40];
1023
+
1024
+ if (strlen(path) != 41)
1025
+ return -1;
1026
+
1027
+ memcpy(hex, path, 2);
1028
+ path += 2;
1029
+ path++; /* skip '/' */
1030
+ memcpy(hex, path, 38);
1031
+
1032
+ return get_sha1_hex(hex, sha1);
1033
+}
1034
+
1035
static void process_ls_object(struct remote_ls_ctx *ls)
1036
{
1037
unsigned int *parent = (unsigned int *)ls->userData;
1026
- char *path = ls->dentry_name;
1027
- char *obj_hex;
1038
+ const char *path = ls->dentry_name;
1039
+ unsigned char sha1[20];
1040
1041
if (!strcmp(ls->path, ls->dentry_name) && (ls->flags & IS_DIR)) {
1042
remote_dir_exists[*parent] = 1;
1043
return;
1044
}
1045
1034
- if (strlen(path) != 49)
1046
+ if (!skip_prefix(path, "objects/", &path) ||
1047
+ get_sha1_hex_from_objpath(path, sha1))
1048
return;
1036
- path += 8;
1037
- obj_hex = xmalloc(strlen(path));
1038
- /* NB: path is not null-terminated, can not use strlcpy here */
1039
- memcpy(obj_hex, path, 2);
1040
- strcpy(obj_hex + 2, path + 3);
1041
- one_remote_object(obj_hex);
1042
- free(obj_hex);
1049
+
1050
+ one_remote_object(sha1);
1051
}
1052
1053
static void process_ls_ref(struct remote_ls_ctx *ls)