summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-08-06 19:50:14 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-08-06 20:49:26 (GMT)
commitd3af621b147bb90a31fdc3b55e07853f45deb658 (patch)
tree26d8d69dd5288b5f6f9756ba75549618d808627f
parentf5b749560980a30d7472183e3d6360baa5a1f0d5 (diff)
downloadgit-d3af621b147bb90a31fdc3b55e07853f45deb658.zip
git-d3af621b147bb90a31fdc3b55e07853f45deb658.tar.gz
git-d3af621b147bb90a31fdc3b55e07853f45deb658.tar.bz2
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>
-rw-r--r--Makefile9
-rw-r--r--cache.h4
-rw-r--r--init-db.c45
-rw-r--r--templates/Makefile43
-rw-r--r--templates/branches--1
-rw-r--r--templates/info--exclude6
-rw-r--r--templates/this--description1
7 files changed, 76 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index 425e9a4..072d426 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/cache.h b/cache.h
index 6dbc32a..957e2ca 100644
--- a/cache.h
+++ b/cache.h
@@ -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);
diff --git a/init-db.c b/init-db.c
index 3f53d6c..1fb3f7f 100644
--- a/init-db.c
+++ b/init-db.c
@@ -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.
diff --git a/templates/Makefile b/templates/Makefile
index 1243351..6b2a900 100644
--- a/templates/Makefile
+++ b/templates/Makefile
@@ -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:
+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) -
diff --git a/templates/branches-- b/templates/branches--
new file mode 100644
index 0000000..fae8870
--- /dev/null
+++ b/templates/branches--
@@ -0,0 +1 @@
+: this is just to ensure the directory exists.
diff --git a/templates/info--exclude b/templates/info--exclude
new file mode 100644
index 0000000..2c87b72
--- /dev/null
+++ b/templates/info--exclude
@@ -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]
+# *~
diff --git a/templates/this--description b/templates/this--description
new file mode 100644
index 0000000..c6f25e8
--- /dev/null
+++ b/templates/this--description
@@ -0,0 +1 @@
+Unnamed repository; edit this file to name it for gitweb.