From b6607e7e796f5b58d64211c022d3e1af6159bdaa Mon Sep 17 00:00:00 2001 From: Dominik Vogt Date: Thu, 27 Dec 2007 11:11:28 +0100 Subject: [PATCH] Add system-wide configuration file and new config file environment vars Introduced envvars TIGRC_USER and TIGRC_SYSTEM to control which config file is used. The default user specific config file can be overridden with TIGRC_USER. Before loading the user config file, tig now looks for a system wide config file ($(sysconfdir)/tirgc by default). This can be overridden with the environment variable TIGRC_SYSTEM. Also corrected a small mistake in the Makefile. Instead of setting CFLAGS for '-D...' compiler options, use CPPFLAGS. [ The original code from Dominik was changed so that tig always reads the system-wide configuration file. The documentation was improved so the configured sysconfdir is used in the generated documentation. -- jonas ] Signed-off-by: Jonas Fonseca --- Makefile | 6 ++++-- config.make.in | 1 + manual.txt | 15 +++++++++++++++ tig.1.txt | 10 ++++++++++ tig.c | 46 ++++++++++++++++++++++++++++++++-------------- 5 files changed, 62 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 6cc4e42..c2d6b60 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ all: prefix ?= $(HOME) bindir ?= $(prefix)/bin datarootdir ?= $(prefix)/share +sysconfdir ?= $(prefix)/etc docdir ?= $(datarootdir)/doc mandir ?= $(datarootdir)/man # DESTDIR= @@ -47,11 +48,12 @@ else TARNAME = tig-$(RPM_VERSION) endif -override CFLAGS += '-DTIG_VERSION="$(VERSION)"' +override CPPFLAGS += '-DTIG_VERSION="$(VERSION)"' +override CPPFLAGS += '-DSYSCONFDIR="$(sysconfdir)"' AUTORECONF ?= autoreconf ASCIIDOC ?= asciidoc -ASCIIDOC_FLAGS = -aversion=$(VERSION) +ASCIIDOC_FLAGS = -aversion=$(VERSION) -asysconfdir=$(sysconfdir) XMLTO ?= xmlto DOCBOOK2PDF ?= docbook2pdf diff --git a/config.make.in b/config.make.in index 3af2ea9..3962050 100644 --- a/config.make.in +++ b/config.make.in @@ -4,6 +4,7 @@ bindir = @bindir@ mandir = @mandir@ docdir = @docdir@ datarootdir = @datarootdir@ +sysconfdir = @sysconfdir@ CC = @CC@ CFLAGS = @CFLAGS@ diff --git a/manual.txt b/manual.txt index 1bafd1b..efdb079 100644 --- a/manual.txt +++ b/manual.txt @@ -65,6 +65,21 @@ Environment Variables Several options related to the interface with git can be configured via environment options. +[[configuration-files]] +Configuration Files +~~~~~~~~~~~~~~~~~~~ + +Upon startup, tig first reads the system wide configuration file +(`{sysconfdir}/tigrc` by default) and then proceeds to read the user's +configuration file (`~/.tigrc` by default). The paths to either of these files +can be overridden through the following environment variables: + +TIGRC_USER:: + Path of the user configuration file. + +TIGRC_SYSTEM:: + Path of the system wide configuration file. + [[repo-refs]] Repository References ~~~~~~~~~~~~~~~~~~~~~ diff --git a/tig.1.txt b/tig.1.txt index 30508ea..7b1c779 100644 --- a/tig.1.txt +++ b/tig.1.txt @@ -119,6 +119,13 @@ ENVIRONMENT VARIABLES In addition to environment variables used by git (e.g. GIT_DIR), tig defines the following: +TIGRC_USER:: + Path of the user configuration file (defaults to `~/.tigrc`). + +TIGRC_SYSTEM:: + Path of the system wide configuration file (defaults to + `{sysconfdir}/tigrc`). + TIG_LS_REMOTE:: Set command for retrieving all repository references. The command should output data in the same format as git-ls-remote(1). @@ -153,6 +160,9 @@ FILES '~/.tigrc':: User configuration file. See gitlink:tigrc[5] for examples. +'{sysconfdir}/tigrc':: + System wide configuration file. + '$GIT_DIR/config':: Repository config file. Read on start-up with the help of git-config(1). diff --git a/tig.c b/tig.c index c614690..c44409e 100644 --- a/tig.c +++ b/tig.c @@ -1271,29 +1271,47 @@ read_option(char *opt, size_t optlen, char *value, size_t valuelen) return OK; } -static int -load_options(void) +static void +load_option_file(const char *path) { - char *home = getenv("HOME"); - char buf[SIZEOF_STR]; FILE *file; + /* It's ok that the file doesn't exist. */ + file = fopen(path, "r"); + if (!file) + return; + config_lineno = 0; config_errors = FALSE; - add_builtin_run_requests(); + if (read_properties(file, " \t", read_option) == ERR || + config_errors == TRUE) + fprintf(stderr, "Errors while loading %s.\n", path); +} - if (!home || !string_format(buf, "%s/.tigrc", home)) - return ERR; +static int +load_options(void) +{ + char *home = getenv("HOME"); + char *tigrc_user = getenv("TIGRC_USER"); + char *tigrc_system = getenv("TIGRC_SYSTEM"); + char buf[SIZEOF_STR]; - /* It's ok that the file doesn't exist. */ - file = fopen(buf, "r"); - if (!file) - return OK; + add_builtin_run_requests(); - if (read_properties(file, " \t", read_option) == ERR || - config_errors == TRUE) - fprintf(stderr, "Errors while loading %s.\n", buf); + if (!tigrc_system) { + if (!string_format(buf, "%s/tigrc", SYSCONFDIR)) + return ERR; + tigrc_system = buf; + } + load_option_file(tigrc_system); + + if (!tigrc_user) { + if (!home || !string_format(buf, "%s/.tigrc", home)) + return ERR; + tigrc_user = buf; + } + load_option_file(tigrc_user); return OK; } -- 2.11.0