commit 5903ff6ef10b567d1d0d6c30317ed5b35d71e488 from: Stefan Sperling date: Sat Jun 29 20:36:44 2019 UTC stop matching loose objects once we've searched past the ID prefix commit - 4277420a1f45ca37345733120cbe89d19c550f92 commit + 5903ff6ef10b567d1d0d6c30317ed5b35d71e488 blob - 7eafcbdfc6475382a3c4e3036819fe4661d0da42 blob + 3c6ad6074d6b6b8a2339c9beffc2e8d30e7d7600 --- lib/repository.c +++ lib/repository.c @@ -976,6 +976,8 @@ match_loose_object(struct got_object_id **unique_id, c } 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, c 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) {