ref_resolves_to_object(): new function
Extract new function ref_resolves_to_object() from entry_resolves_to_object(). It can be used even if there is no ref_entry at hand. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jun 18, 2016 at 06:15 UTC
a873924483ec6ec548e94d723fe62875b1a4ec93
1 file changed
+20
-7
refs/files-backend.c
+20
-7
@@ -513,21 +513,34 @@ static void sort_ref_dir(struct ref_dir *dir)
513
}
514
515
/*
516
- * Return true iff the reference described by entry can be resolved to
517
- * an object in the database. Emit a warning if the referred-to
518
- * object does not exist.
516
+ * Return true if refname, which has the specified oid and flags, can
517
+ * be resolved to an object in the database. If the referred-to object
518
+ * does not exist, emit a warning and return false.
519
*/
520
-static int entry_resolves_to_object(struct ref_entry *entry)
520
+static int ref_resolves_to_object(const char *refname,
521
+ const struct object_id *oid,
522
+ unsigned int flags)
523
{
522
- if (entry->flag & REF_ISBROKEN)
524
+ if (flags & REF_ISBROKEN)
525
return 0;
524
- if (!has_sha1_file(entry->u.value.oid.hash)) {
525
- error("%s does not point to a valid object!", entry->name);
526
+ if (!has_sha1_file(oid->hash)) {
527
+ error("%s does not point to a valid object!", refname);
528
return 0;
529
}
530
return 1;
531
}
532
533
+/*
534
+ * Return true if the reference described by entry can be resolved to
535
+ * an object in the database; otherwise, emit a warning and return
536
+ * false.
537
+ */
538
+static int entry_resolves_to_object(struct ref_entry *entry)
539
+{
540
+ return ref_resolves_to_object(entry->name,
541
+ &entry->u.value.oid, entry->flag);
542
+}
543
+
544
/*
545
* current_ref is a performance hack: when iterating over references
546
* using the for_each_ref*() functions, current_ref is set to the