sha1_name.c: rename "now" to "current"
[gitweb.git] / sha1_name.c
index 03ffc2caaa6524a3361bc47a89e101ced2f0e987..c5c4591f98989e48b13f2625a9f09f09e546a2f8 100644 (file)
@@ -17,6 +17,13 @@ static int find_short_object_filename(int len, const char *name, unsigned char *
        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;
@@ -86,11 +93,11 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
                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;
@@ -102,17 +109,17 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
                        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;
                                        }
@@ -992,16 +999,6 @@ static void diagnose_invalid_index_path(int stage,
 }
 
 
-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, "../"))
@@ -1019,9 +1016,9 @@ static char *resolve_relative_path(const char *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);
@@ -1134,3 +1131,22 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
        }
        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);
+}