summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinquize <linquize@yahoo.com.hk>2013-09-17 23:55:11 +0800
committerLinquize <linquize@yahoo.com.hk>2013-09-18 00:09:09 +0800
commita025907e0d751ed1022e65365243ae97acf3f598 (patch)
tree25d2bb82d3cf622c5d3a9f06c7d1f6ef2f295511 /src
parentb99b10f285fec710273d1233b057ff33a6e44993 (diff)
downloadlibgit2-a025907e0d751ed1022e65365243ae97acf3f598.tar.gz
Can load default template directory
Diffstat (limited to 'src')
-rw-r--r--src/fileops.c9
-rw-r--r--src/fileops.h8
-rw-r--r--src/repository.c12
3 files changed, 24 insertions, 5 deletions
diff --git a/src/fileops.c b/src/fileops.c
index b7ae94b75..ba88dfec7 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -763,7 +763,8 @@ static int git_futils_find_in_dirlist(
continue;
GITERR_CHECK_ERROR(git_buf_set(path, scan, len));
- GITERR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name));
+ if (name)
+ GITERR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name));
if (git_path_exists(path->ptr))
return 0;
@@ -792,6 +793,12 @@ int git_futils_find_xdg_file(git_buf *path, const char *filename)
path, filename, GIT_FUTILS_DIR_XDG, "global/xdg");
}
+int git_futils_find_template_dir(git_buf *path)
+{
+ return git_futils_find_in_dirlist(
+ path, NULL, GIT_FUTILS_DIR_TEMPLATE, "template");
+}
+
int git_futils_fake_symlink(const char *old, const char *new)
{
int retcode = GIT_ERROR;
diff --git a/src/fileops.h b/src/fileops.h
index 0ac9b9007..64d3da70a 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -306,6 +306,14 @@ extern int git_futils_find_xdg_file(git_buf *path, const char *filename);
*/
extern int git_futils_find_system_file(git_buf *path, const char *filename);
+/**
+ * Find template directory.
+ *
+ * @param path buffer to write the full path into
+ * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error
+ */
+extern int git_futils_find_template_dir(git_buf *path);
+
typedef enum {
GIT_FUTILS_DIR_SYSTEM = 0,
GIT_FUTILS_DIR_GLOBAL = 1,
diff --git a/src/repository.c b/src/repository.c
index eead41201..e67d1f013 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -33,8 +33,6 @@
#define GIT_REPO_VERSION 0
-#define GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
-
static void set_odb(git_repository *repo, git_odb *odb)
{
if (odb) {
@@ -1136,6 +1134,9 @@ static int repo_init_structure(
if (external_tpl) {
git_config *cfg;
const char *tdir;
+ git_buf template_buf = GIT_BUF_INIT;
+
+ git_futils_find_template_dir(&template_buf);
if (opts->template_path)
tdir = opts->template_path;
@@ -1150,7 +1151,7 @@ static int repo_init_structure(
return error;
giterr_clear();
- tdir = GIT_TEMPLATE_DIR;
+ tdir = template_buf.ptr;
}
error = git_futils_cp_r(tdir, repo_dir,
@@ -1158,14 +1159,17 @@ static int repo_init_structure(
GIT_CPDIR_SIMPLE_TO_MODE, dmode);
if (error < 0) {
- if (strcmp(tdir, GIT_TEMPLATE_DIR) != 0)
+ if (strcmp(tdir, template_buf.ptr) != 0) {
+ git_buf_free(&template_buf);
return error;
+ }
/* if template was default, ignore error and use internal */
giterr_clear();
external_tpl = false;
error = 0;
}
+ git_buf_free(&template_buf);
}
/* Copy internal template