sha1_file: refactor has_sha1_file_with_flags

has_sha1_file_with_flags() implements many mechanisms in common with sha1_object_info_extended(). Make has_sha1_file_with_flags() a convenience function for sha1_object_info_extended() instead. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Jun 21, 2017 at 17:40 UTC e83e71c5e15f2c6aaf9bdb8ee9593a46c3bb9a5b
4 files changed +13 -23
builtin/fetch.c
+6 -4
@@ -249,9 +249,11 @@ static void find_non_local_tags(struct transport *transport,
249 */
250 if (ends_with(ref->name, "^{}")) {
251 if (item &&
252 - !has_object_file_with_flags(&ref->old_oid, HAS_SHA1_QUICK) &&
252 + !has_object_file_with_flags(&ref->old_oid,
253 + OBJECT_INFO_QUICK) &&
254 !will_fetch(head, ref->old_oid.hash) &&
254 - !has_sha1_file_with_flags(item->util, HAS_SHA1_QUICK) &&
255 + !has_sha1_file_with_flags(item->util,
256 + OBJECT_INFO_QUICK) &&
257 !will_fetch(head, item->util))
258 item->util = NULL;
259 item = NULL;
@@ -265,7 +267,7 @@ static void find_non_local_tags(struct transport *transport,
267 * fetch.
268 */
269 if (item &&
268 - !has_sha1_file_with_flags(item->util, HAS_SHA1_QUICK) &&
270 + !has_sha1_file_with_flags(item->util, OBJECT_INFO_QUICK) &&
271 !will_fetch(head, item->util))
272 item->util = NULL;
273
@@ -286,7 +288,7 @@ static void find_non_local_tags(struct transport *transport,
288 * checked to see if it needs fetching.
289 */
290 if (item &&
289 - !has_sha1_file_with_flags(item->util, HAS_SHA1_QUICK) &&
291 + !has_sha1_file_with_flags(item->util, OBJECT_INFO_QUICK) &&
292 !will_fetch(head, item->util))
293 item->util = NULL;
294
builtin/index-pack.c
+2 -1
@@ -794,7 +794,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
794
795 if (startup_info->have_repository) {
796 read_lock();
797 - collision_test_needed = has_sha1_file_with_flags(oid->hash, HAS_SHA1_QUICK);
797 + collision_test_needed =
798 + has_sha1_file_with_flags(oid->hash, OBJECT_INFO_QUICK);
799 read_unlock();
800 }
801
cache.h
+3 -8
@@ -1268,15 +1268,10 @@ int read_loose_object(const char *path,
1268 void **contents);
1269
1270 /*
1271 - * Return true iff we have an object named sha1, whether local or in
1272 - * an alternate object database, and whether packed or loose. This
1273 - * function does not respect replace references.
1274 - *
1275 - * If the QUICK flag is set, do not re-check the pack directory
1276 - * when we cannot find the object (this means we may give a false
1277 - * negative answer if another process is simultaneously repacking).
1271 + * Convenience for sha1_object_info_extended() with a NULL struct
1272 + * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
1273 + * nonzero flags to also set other flags.
1274 */
1279 -#define HAS_SHA1_QUICK 0x1
1275 extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
1276 static inline int has_sha1_file(const unsigned char *sha1)
1277 {
sha1_file.c
+2 -10
@@ -3494,18 +3494,10 @@ int has_sha1_pack(const unsigned char *sha1)
3494
3495 int has_sha1_file_with_flags(const unsigned char *sha1, int flags)
3496 {
3497 - struct pack_entry e;
3498 -
3497 if (!startup_info->have_repository)
3498 return 0;
3501 - if (find_pack_entry(sha1, &e))
3502 - return 1;
3503 - if (has_loose_object(sha1))
3504 - return 1;
3505 - if (flags & HAS_SHA1_QUICK)
3506 - return 0;
3507 - reprepare_packed_git();
3508 - return find_pack_entry(sha1, &e);
3499 + return sha1_object_info_extended(sha1, NULL,
3500 + flags | OBJECT_INFO_SKIP_CACHED) >= 0;
3501 }
3502
3503 int has_object_file(const struct object_id *oid)