summaryrefslogtreecommitdiff
path: root/src/repository.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/repository.c')
-rw-r--r--src/repository.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/src/repository.c b/src/repository.c
index 7d243398b..bb7ef396d 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include <stdarg.h>
@@ -288,7 +270,6 @@ cleanup:
int git_repository_config(
git_config **out,
git_repository *repo,
- const char *user_config_path,
const char *system_config_path)
{
char config_path[GIT_PATH_MAX];
@@ -305,10 +286,9 @@ int git_repository_config(
if (error < GIT_SUCCESS)
goto cleanup;
- if (user_config_path != NULL) {
- error = git_config_add_file_ondisk(*out, user_config_path, 2);
- if (error < GIT_SUCCESS)
- goto cleanup;
+ error = git_config_find_global(config_path);
+ if (error == GIT_SUCCESS) {
+ error = git_config_add_file_ondisk(*out, config_path, 2);
}
if (system_config_path != NULL) {
@@ -729,19 +709,31 @@ int git_repository_head_detached(git_repository *repo)
return 1;
}
-int git_repository_head_orphan(git_repository *repo)
+int git_repository_head(git_reference **head_out, git_repository *repo)
{
git_reference *ref;
int error;
+ *head_out = NULL;
+
error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE);
if (error < GIT_SUCCESS)
- return error;
-
- if (git_reference_type(ref) == GIT_REF_OID)
- return 0;
+ return git__rethrow(GIT_ENOTAREPO, "Failed to locate the HEAD");
error = git_reference_resolve(&ref, ref);
+ if (error < GIT_SUCCESS)
+ return git__rethrow(error, "Failed to resolve the HEAD");
+
+ *head_out = ref;
+ return GIT_SUCCESS;
+}
+
+int git_repository_head_orphan(git_repository *repo)
+{
+ git_reference *ref;
+ int error;
+
+ error = git_repository_head(&ref, repo);
return error == GIT_ENOTFOUND ? 1 : error;
}