static struct alternate_object_database *fakeent;
if (!fakeent) {
+ /*
+ * Create a "fake" alternate object database that
+ * points to our own object database, to make it
+ * easier to get a temporary working space in
+ * alt->name/alt->base while iterating over the
+ * object databases including our own.
+ */
const char *objdir = get_object_directory();
int objdir_len = strlen(objdir);
int entlen = objdir_len + 43;
last = num;
while (first < last) {
uint32_t mid = (first + last) / 2;
- const unsigned char *now;
+ const unsigned char *current;
int cmp;
- now = nth_packed_object_sha1(p, mid);
- cmp = hashcmp(match, now);
+ current = nth_packed_object_sha1(p, mid);
+ cmp = hashcmp(match, current);
if (!cmp) {
first = mid;
break;
last = mid;
}
if (first < num) {
- const unsigned char *now, *next;
- now = nth_packed_object_sha1(p, first);
- if (match_sha(len, match, now)) {
+ const unsigned char *current, *next;
+ current = nth_packed_object_sha1(p, first);
+ if (match_sha(len, match, current)) {
next = nth_packed_object_sha1(p, first+1);
- if (!next|| !match_sha(len, match, next)) {
+ if (!next|| !match_sha(len, match, next)) {
/* unique within this pack */
if (!found) {
- found_sha1 = now;
+ found_sha1 = current;
found++;
}
- else if (hashcmp(found_sha1, now)) {
+ else if (hashcmp(found_sha1, current)) {
found = 2;
break;
}
}
-int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
- int only_to_die, const char *prefix)
-{
- struct object_context oc;
- int ret;
- ret = get_sha1_with_context_1(name, sha1, &oc, only_to_die, prefix);
- *mode = oc.mode;
- return ret;
-}
-
static char *resolve_relative_path(const char *rel)
{
if (prefixcmp(rel, "./") && prefixcmp(rel, "../"))
rel);
}
-int get_sha1_with_context_1(const char *name, unsigned char *sha1,
- struct object_context *oc,
- int only_to_die, const char *prefix)
+static int get_sha1_with_context_1(const char *name, unsigned char *sha1,
+ struct object_context *oc,
+ int only_to_die, const char *prefix)
{
int ret, bracket_depth;
int namelen = strlen(name);
}
return ret;
}
+
+/*
+ * Call this function when you know "name" given by the end user must
+ * name an object but it doesn't; the function _may_ die with a better
+ * diagnostic message than "no such object 'name'", e.g. "Path 'doc' does not
+ * exist in 'HEAD'" when given "HEAD:doc", or it may return in which case
+ * you have a chance to diagnose the error further.
+ */
+void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
+{
+ struct object_context oc;
+ unsigned char sha1[20];
+ get_sha1_with_context_1(name, sha1, &oc, 1, prefix);
+}
+
+int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc)
+{
+ return get_sha1_with_context_1(str, sha1, orc, 0, NULL);
+}