prefix=$(HOME)
bindir=$(prefix)/bin
-etcdir=$(prefix)/etc
-etcgitdir=$(etcdir)/git-core
+template_dir=$(prefix)/share/git-core/templates/
# dest=
CC?=gcc
endif
CFLAGS += '-DSHA1_HEADER=$(SHA1_HEADER)'
-CFLAGS += '-DDEFAULT_GIT_TEMPLATE_ENVIRONMENT="$(etcgitdir)/templates"'
all: $(PROG)
+all:
+ $(MAKE) -C templates
.PRECIOUS: %.o
git-%: %.o $(LIB_FILE)
git-http-pull: LIBS += -lcurl
git-rev-list: LIBS += $(OPENSSL_LIBSSL)
+init-db.o: init-db.c
+ $(CC) -c $(CFLAGS) -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir)"' $*.c
+
$(LIB_OBJS): $(LIB_H)
$(DIFF_OBJS): diffcore.h
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"
-#define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIRECTORY"
-#ifndef DEFAULT_GIT_TEMPLATE_ENVIRONMENT
-#define DEFAULT_GIT_TEMPLATE_ENVIRONMENT "/etc/git-core/templates"
-#endif
extern char *get_object_directory(void);
extern char *get_refs_directory(void);
*/
#include "cache.h"
+#ifndef DEFAULT_GIT_TEMPLATE_DIR
+#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates/"
+#endif
+
static void safe_create_dir(const char *dir)
{
if (mkdir(dir, 0777) < 0) {
}
}
-static void copy_templates(const char *git_dir)
+static void copy_templates(const char *git_dir, int len, char *template_dir)
{
char path[PATH_MAX];
char template_path[PATH_MAX];
- char *template_dir;
- int len, template_len;
+ int template_len;
DIR *dir;
- strcpy(path, git_dir);
- len = strlen(path);
- template_dir = gitenv(TEMPLATE_DIR_ENVIRONMENT);
if (!template_dir)
- template_dir = DEFAULT_GIT_TEMPLATE_ENVIRONMENT;
+ template_dir = DEFAULT_GIT_TEMPLATE_DIR;
strcpy(template_path, template_dir);
template_len = strlen(template_path);
if (template_path[template_len-1] != '/') {
template_path[template_len++] = '/';
template_path[template_len] = 0;
}
-
dir = opendir(template_path);
- if (!dir)
+ if (!dir) {
+ fprintf(stderr, "warning: templates not found %s\n",
+ template_dir);
return;
+ }
+
+ memcpy(path, git_dir, len);
copy_templates_1(path, len,
template_path, template_len,
dir);
closedir(dir);
}
-static void create_default_files(const char *git_dir)
+static void create_default_files(const char *git_dir,
+ char *template_path)
{
unsigned len = strlen(git_dir);
static char path[PATH_MAX];
exit(1);
}
}
- path[len] = 0;
- copy_templates(path);
+ copy_templates(path, len, template_path);
}
+static const char init_db_usage[] =
+"git-init-db [--template=<template-directory>]";
+
/*
* If you want to, you can share the DB area with any number of branches.
* That has advantages: you can save space by sharing all the SHA1 objects.
{
const char *git_dir;
const char *sha1_dir;
- char *path;
+ char *path, *template_dir = NULL;
int len, i;
+ for (i = 1; i < argc; i++, argv++) {
+ char *arg = argv[1];
+ if (arg[0] != '-')
+ break;
+ else if (!strncmp(arg, "--template=", 11))
+ template_dir = arg+11;
+ else
+ die(init_db_usage);
+ }
+
/*
* Set up the default .git directory contents
*/
fprintf(stderr, "defaulting to local storage area\n");
}
safe_create_dir(git_dir);
- create_default_files(git_dir);
+ create_default_files(git_dir, template_dir);
/*
* And set up the object store.
-# make
+# make and install sample templates
INSTALL=install
prefix=$(HOME)
-etcdir=$(prefix)/etc
-etcgitdir=$(etcdir)/git-core
-templatedir=$(etcgitdir)/templates
+template_dir=$(prefix)/share/git-core/templates/
# dest=
-all:
+all: boilerplates custom
+ find blt
+
+# Put templates that can be copied straight from the source
+# in a file direc--tory--file in the source. They will be
+# just copied to the destination.
+boilerplates:
+ ls *--* 2>/dev/null | \
+ while read boilerplate; \
+ do \
+ case "$$boilerplate" in *~) continue ;; esac && \
+ dst=`echo "$$boilerplate" | sed -e 's|^this|.|;s|--|/|g'` && \
+ dir=`expr "$$dst" : '\(.*\)/'` && \
+ mkdir -p blt/$$dir && \
+ case "$$boilerplate" in \
+ *--) ;; \
+ *) cp $$boilerplate blt/$$dst ;; \
+ esac || exit; \
+ done || exit
+
+# If you need build-tailored templates, build them into blt/
+# directory yourself here.
+custom:
+ : no custom templates yet
+
clean:
+ rm -rf blt
-install:
- $(INSTALL) -d -m755 $(dest)$(templatedir)/hooks/
- $(foreach s,$(wildcard hooks--*),\
- $(INSTALL) -m644 $s \
- $(dest)$(templatedir)/hooks/$(patsubst hooks--%,%,$s);)
- $(INSTALL) -d -m755 $(dest)$(templatedir)/info
- $(INSTALL) -d -m755 $(dest)$(templatedir)/branches
+install: all
+ $(INSTALL) -d -m755 $(dest)$(template_dir)
+ tar Ccf blt - . | tar Cxf $(dest)$(template_dir) -
--- /dev/null
+: this is just to ensure the directory exists.
--- /dev/null
+# git-ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
--- /dev/null
+Unnamed repository; edit this file to name it for gitweb.