stop matching loose objects once we've searched past the ID prefix
diff --git a/lib/repository.c b/lib/repository.c
index 7eafcbd..3c6ad60 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -976,6 +976,8 @@ match_loose_object(struct got_object_id **unique_id, const char *path_objects,
}
while ((dent = readdir(dir)) != NULL) {
char *id_str;
+ int cmp;
+
if (strcmp(dent->d_name, ".") == 0 ||
strcmp(dent->d_name, "..") == 0)
continue;
@@ -988,10 +990,13 @@ match_loose_object(struct got_object_id **unique_id, const char *path_objects,
if (!got_parse_sha1_digest(id.sha1, id_str))
continue;
- if (strncmp(id_str_prefix, id_str,
- strlen(id_str_prefix)) != 0) {
+ cmp = strncmp(id_str, id_str_prefix, strlen(id_str_prefix));
+ if (cmp < 0) {
free(id_str);
continue;
+ } else if (cmp > 0) {
+ free(id_str);
+ break;
}
if (*unique_id == NULL) {