name-rev: refactor logic to see if a new candidate is a better name
[gitweb.git] / builtin / hash-object.c
index 56df77b0c2a299fcba56a2542f7adb34869ced9f..bbeaf20bcca1ae1e9bfa55b5a8e4adbed83c00e8 100644 (file)
@@ -102,7 +102,6 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
                OPT_END()
        };
        int i;
-       int prefix_length = -1;
        const char *errstr = NULL;
 
        argc = parse_options(argc, argv, NULL, hash_object_options,
@@ -113,9 +112,8 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
        else
                prefix = setup_git_directory_gently(&nongit);
 
-       prefix_length = prefix ? strlen(prefix) : 0;
        if (vpath && prefix)
-               vpath = xstrdup(prefix_filename(prefix, prefix_length, vpath));
+               vpath = xstrdup(prefix_filename(prefix, vpath));
 
        git_config(git_default_config, NULL);
 
@@ -146,9 +144,8 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
                const char *arg = argv[i];
                char *to_free = NULL;
 
-               if (0 <= prefix_length)
-                       arg = to_free =
-                               xstrdup(prefix_filename(prefix, prefix_length, arg));
+               if (prefix)
+                       arg = to_free = prefix_filename(prefix, arg);
                hash_object(arg, type, no_filters ? NULL : vpath ? vpath : arg,
                            flags, literally);
                free(to_free);