Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
refs: extract a function ref_resolves_to_object()
author
Michael Haggerty
<mhagger@alum.mit.edu>
Mon, 22 Apr 2013 19:52:18 +0000
(21:52 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Wed, 1 May 2013 22:33:10 +0000
(15:33 -0700)
It is a nice unit of work and soon will be needed from multiple
locations.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
7618fd8
)
diff --git
a/refs.c
b/refs.c
index 03c19be2c1326a10ff40c5a7e183ae78ed06f18e..5d760b4f0572d823102f5aeb501fad82f2b22830 100644
(file)
--- a/
refs.c
+++ b/
refs.c
@@
-529,6
+529,22
@@
static void sort_ref_dir(struct ref_dir *dir)
/* Include broken references in a do_for_each_ref*() iteration: */
#define DO_FOR_EACH_INCLUDE_BROKEN 0x01
/* Include broken references in a do_for_each_ref*() iteration: */
#define DO_FOR_EACH_INCLUDE_BROKEN 0x01
+/*
+ * Return true iff the reference described by entry can be resolved to
+ * an object in the database. Emit a warning if the referred-to
+ * object does not exist.
+ */
+static int ref_resolves_to_object(struct ref_entry *entry)
+{
+ if (entry->flag & REF_ISBROKEN)
+ return 0;
+ if (!has_sha1_file(entry->u.value.sha1)) {
+ error("%s does not point to a valid object!", entry->name);
+ return 0;
+ }
+ return 1;
+}
+
/*
* current_ref is a performance hack: when iterating over references
* using the for_each_ref*() functions, current_ref is set to the
/*
* current_ref is a performance hack: when iterating over references
* using the for_each_ref*() functions, current_ref is set to the
@@
-550,14
+566,10
@@
static int do_one_ref(const char *base, each_ref_fn fn, int trim,
if (prefixcmp(entry->name, base))
return 0;
if (prefixcmp(entry->name, base))
return 0;
- if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {
- if (entry->flag & REF_ISBROKEN)
- return 0; /* ignore broken refs e.g. dangling symref */
- if (!has_sha1_file(entry->u.value.sha1)) {
- error("%s does not point to a valid object!", entry->name);
- return 0;
- }
- }
+ if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
+ !ref_resolves_to_object(entry))
+ return 0;
+
current_ref = entry;
retval = fn(entry->name + trim, entry->u.value.sha1, entry->flag, cb_data);
current_ref = NULL;
current_ref = entry;
retval = fn(entry->name + trim, entry->u.value.sha1, entry->flag, cb_data);
current_ref = NULL;