On Fri, Jan 17, 2014 at 03:42:32PM -0800, Junio C Hamano wrote:

> Junio C Hamano <gits...@pobox.com> writes:
> 
> > Perhaps we can start it like this.  Then pager.c can iterate over
> > the PAGER_ENV string, parse out LESS=, LV=, etc., and do its thing.
> >
> > We would also need to muck with git-sh-setup.sh but that file is
> > already preprocessed in the Makefile, so we should be able to do
> > something similar to "# @@BROKEN_PATH_FIX@@" there.
> 
> And here is such an attempt.  There may be some missing dependencies
> that need to be covered with a mechanism like GIT-BUILD-OPTIONS,
> though.

Perhaps instead of just dumping it into a macro, we could actually parse
it at compile time into C code, and store the result as a header file.
Then that header file becomes the proper dependency, and this run-time
error:

> +     while (*pager_env) {
> +             struct strbuf buf = STRBUF_INIT;
> +             const char *cp = strchrnul(pager_env, '=');
> +
> +             if (!*cp)
> +                     die("malformed build-time PAGER_ENV");

would become a compile-time error. We could do the same for the shell
code, too.

I'm thinking something like:

diff --git a/Makefile b/Makefile
index b4af1e2..3a8d15e 100644
--- a/Makefile
+++ b/Makefile
@@ -2182,6 +2182,16 @@ GIT-LDFLAGS: FORCE
                echo "$$FLAGS" >GIT-LDFLAGS; \
             fi
 
+GIT-PAGER-ENV:
+       @PAGER_ENV='$(PAGER_ENV)'; \
+       if test x"$$PAGER_ENV" != x"`cat GIT-PAGER-ENV 2>/dev/null`"; then \
+               echo "$$PAGER_ENV" >GIT-PAGER-ENV; \
+       fi
+
+pager-env.h: GIT-PAGER-ENV mkcarray
+       $(SHELL_PATH) mkcarray pager_env <$< >$@+
+       mv $@+ $@
+
 # We need to apply sq twice, once to protect from the shell
 # that runs GIT-BUILD-OPTIONS, and then again to protect it
 # and the first level quoting from the shell that runs "echo".
diff --git a/mkcarray b/mkcarray
index e69de29..5962440 100644
--- a/mkcarray
+++ b/mkcarray
@@ -0,0 +1,21 @@
+name=$1; shift
+guard=$(echo "$name" | tr a-z A-Z)
+
+cat <<-EOF
+#ifndef ${guard}_H
+#define ${guard}_H
+
+static const char *${name} = {
+EOF
+
+for i in $(cat); do
+       # XXX c-quote the values?
+       printf '\t"%s",\n' "$i"
+done
+
+cat <<EOF
+       NULL
+};
+
+#endif /* ${guard}_H */
+EOF
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to