tree-diff: allow diff_tree_sha1 to accept NULL sha1
[gitweb.git] / environment.c
index e2e75c16602d8e5841c2461defaba7b9866115d8..4a3437d8a61256029655f25c76256f27a6189248 100644 (file)
@@ -10,6 +10,7 @@
 #include "cache.h"
 #include "refs.h"
 #include "fmt-merge-msg.h"
+#include "commit.h"
 
 int trust_executable_bit = 1;
 int trust_ctime = 1;
@@ -22,6 +23,7 @@ int prefer_symlink_refs;
 int is_bare_repository_cfg = -1; /* unspecified */
 int log_all_ref_updates = -1; /* unspecified */
 int warn_ambiguous_refs = 1;
+int warn_on_object_refname_ambiguity = 1;
 int repository_format_version;
 const char *git_commit_encoding;
 const char *git_log_output_encoding;
@@ -37,7 +39,6 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
 size_t delta_base_cache_limit = 16 * 1024 * 1024;
 unsigned long big_file_threshold = 512 * 1024 * 1024;
-const char *log_pack_access;
 const char *pager_program;
 int pager_use_color = 1;
 const char *editor_program;
@@ -97,6 +98,7 @@ const char * const local_repo_env[] = {
        INDEX_ENVIRONMENT,
        NO_REPLACE_OBJECTS_ENVIRONMENT,
        GIT_PREFIX_ENVIRONMENT,
+       GIT_SHALLOW_FILE_ENVIRONMENT,
        NULL
 };
 
@@ -123,14 +125,14 @@ static char *expand_namespace(const char *raw_namespace)
 
 static void setup_git_env(void)
 {
+       const char *gitfile;
+       const char *shallow_file;
+
        git_dir = getenv(GIT_DIR_ENVIRONMENT);
-       git_dir = git_dir ? xstrdup(git_dir) : NULL;
-       if (!git_dir) {
-               git_dir = read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
-               git_dir = git_dir ? xstrdup(git_dir) : NULL;
-       }
        if (!git_dir)
                git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+       gitfile = read_gitfile(git_dir);
+       git_dir = xstrdup(gitfile ? gitfile : git_dir);
        git_object_dir = getenv(DB_ENVIRONMENT);
        if (!git_object_dir) {
                git_object_dir = xmalloc(strlen(git_dir) + 9);
@@ -148,6 +150,9 @@ static void setup_git_env(void)
                read_replace_refs = 0;
        namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
        namespace_len = strlen(namespace);
+       shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
+       if (shallow_file)
+               set_alternate_shallow_file(shallow_file, 0);
 }
 
 int is_bare_repository(void)
@@ -156,11 +161,6 @@ int is_bare_repository(void)
        return is_bare_repository_cfg && !get_git_work_tree();
 }
 
-int have_git_dir(void)
-{
-       return !!git_dir;
-}
-
 const char *get_git_dir(void)
 {
        if (!git_dir)
@@ -177,7 +177,7 @@ const char *get_git_namespace(void)
 
 const char *strip_namespace(const char *namespaced_ref)
 {
-       if (prefixcmp(namespaced_ref, get_git_namespace()) != 0)
+       if (!starts_with(namespaced_ref, get_git_namespace()))
                return NULL;
        return namespaced_ref + namespace_len;
 }