Redo the templates generation and installation.

Per discussion with people interested in binary packaging,
change the default template location from /etc/git-core to
/usr/share/git-core hierarchy.  If a user wants to run git
before installing for whatever reason, in addition to adding
$src to the PATH environment variable, git-init-db can be run
with --template=$src/templates/blt/ parameter.

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano 2005-08-06 12:50:14 -07:00
parent f5b7495609
commit d3af621b14
7 changed files with 77 additions and 34 deletions

View file

@ -39,8 +39,7 @@ CFLAGS+=$(COPTS) -Wall $(DEFINES)
prefix=$(HOME)
bindir=$(prefix)/bin
etcdir=$(prefix)/etc
etcgitdir=$(etcdir)/git-core
template_dir=$(prefix)/share/git-core/templates/
# dest=
CC?=gcc
@ -147,7 +146,6 @@ endif
endif
CFLAGS += '-DSHA1_HEADER=$(SHA1_HEADER)'
CFLAGS += '-DDEFAULT_GIT_TEMPLATE_ENVIRONMENT="$(etcgitdir)/templates"'
@ -155,6 +153,8 @@ CFLAGS += '-DDEFAULT_GIT_TEMPLATE_ENVIRONMENT="$(etcgitdir)/templates"'
all: $(PROG)
all:
$(MAKE) -C templates
.PRECIOUS: %.o
git-%: %.o $(LIB_FILE)
@ -168,6 +168,9 @@ git-ssh-push: rsh.o
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

View file

@ -128,10 +128,6 @@ extern unsigned int active_nr, active_alloc, active_cache_changed;
#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);

View file

@ -5,6 +5,10 @@
*/
#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) {
@ -127,36 +131,37 @@ static void copy_templates_1(char *path, int baselen,
}
}
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];
@ -189,10 +194,12 @@ static void create_default_files(const char *git_dir)
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.
@ -203,9 +210,19 @@ int main(int argc, char **argv)
{
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
*/
@ -215,7 +232,7 @@ int main(int argc, char **argv)
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.

View file

@ -1,19 +1,38 @@
# 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:
clean:
all: boilerplates custom
find 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
# 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: all
$(INSTALL) -d -m755 $(dest)$(template_dir)
tar Ccf blt - . | tar Cxf $(dest)$(template_dir) -

1
templates/branches-- Normal file
View file

@ -0,0 +1 @@
: this is just to ensure the directory exists.

6
templates/info--exclude Normal file
View file

@ -0,0 +1,6 @@
# 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]
# *~

View file

@ -0,0 +1 @@
Unnamed repository; edit this file to name it for gitweb.