[PATCH] Add git-var a tool for reading interesting git variables.
authorEric W. Biederman <ebiederm@xmission.com>
Fri, 15 Jul 2005 00:55:09 +0000 (18:55 -0600)
committerLinus Torvalds <torvalds@g5.osdl.org>
Fri, 15 Jul 2005 17:00:35 +0000 (10:00 -0700)
Sharing code between shell scripts and C is a challenge. The program
git-var allows us to have a set of named values that a shell script can
interrogate and a normal C program can simply call the functions that
compute them. Allowing sharing when computing plain test values.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Documentation/git-var.txt [new file with mode: 0644]
Documentation/git.txt
Makefile
var.c [new file with mode: 0644]
diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt
new file mode 100644 (file)
index 0000000..5a27d44
--- /dev/null
@@ -0,0 +1,60 @@
+git-var(1)
+==================
+v0.1, July 2005
+
+NAME
+----
+git-var - Print the git users identity
+
+
+SYNOPSIS
+--------
+git-var [ -l | <variable> ]
+
+DESCRIPTION
+-----------
+Prints a git logical variable.
+
+-l causes the logical variables to be listed.
+
+EXAMPLE
+--------
+$git-var GIT_AUTHOR_IDENT
+
+Eric W. Biederman <ebiederm@lnxi.com> 1121223278 -0600
+
+
+VARIABLES
+----------
+GIT_AUTHOR_IDENT
+    The author of a piece of code.
+
+GIT_COMMITTER_IDENT
+    The person who put a piece of code into git.
+
+Diagnostics
+-----------
+You don't exist. Go away!::
+    The passwd(5) gecos field couldn't be read
+Your parents must have hated you!::
+    The password(5) gecos field is longer than a giant static buffer.
+Your sysadmin must hate you!::
+    The password(5) name field is longer than a giant static buffer.
+
+See Also
+--------
+link:git-commit-tree.html[git-commit-tree]
+link:git-tag-script.html[git-tag-script]
+
+Author
+------
+Written by Eric Biederman <ebiederm@xmission.com>
+
+Documentation
+--------------
+Documentation by Eric Biederman and the git-list <git@vger.kernel.org>.
+
+GIT
+---
+Part of the link:git.html[git] suite
+
index 9e34146e3dd3fba410c20dc3d0e7f8f8ae04c4b1..916a0b7f0829b6a11ac09c0228912e436b58fc40 100644 (file)
@@ -111,6 +111,9 @@ link:git-tar-tree.html[git-tar-tree]::
 link:git-unpack-file.html[git-unpack-file]::
        Creates a temporary file with a blob's contents
 
+link:git-var.html[git-var]::
+       Displays a git logical variable
+
 link:git-verify-pack.html[git-verify-pack]::
        Validates packed GIT archive files
 
index 21dd582255aca8793e230ffae0e4b6f321fc6ea5..4bc3665f2d1970cbbdfeece53e7346bd79b8536c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ PROG=   git-update-cache git-diff-files git-init-db git-write-tree \
        git-diff-stages git-rev-parse git-patch-id git-pack-objects \
        git-unpack-objects git-verify-pack git-receive-pack git-send-pack \
        git-prune-packed git-fetch-pack git-upload-pack git-clone-pack \
-       git-show-index git-daemon
+       git-show-index git-daemon git-var
 
 all: $(PROG)
 
@@ -148,6 +148,7 @@ git-receive-pack: receive-pack.c
 git-send-pack: send-pack.c
 git-prune-packed: prune-packed.c
 git-fetch-pack: fetch-pack.c
+git-var: var.c
 
 git-http-pull: LIBS += -lcurl
 git-rev-list: LIBS += -lssl
diff --git a/var.c b/var.c
new file mode 100644 (file)
index 0000000..488ec51
--- /dev/null
+++ b/var.c
@@ -0,0 +1,65 @@
+/*
+ * GIT - The information manager from hell
+ *
+ * Copyright (C) Eric Biederman, 2005
+ */
+#include "cache.h"
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+static char *var_usage = "git-var [-l | <variable>]";
+
+struct git_var {
+       const char *name;
+       char *(*read)(void);
+};
+static struct git_var git_vars[] = {
+       { "GIT_COMMITTER_IDENT", git_committer_info },
+       { "GIT_AUTHOR_IDENT",   git_author_info },
+       { "", NULL },
+};
+
+static void list_vars(void)
+{
+       struct git_var *ptr;
+       for(ptr = git_vars; ptr->read; ptr++) {
+               printf("%s=%s\n", ptr->name, ptr->read());
+       }
+}
+
+static const char *read_var(const char *var)
+{
+       struct git_var *ptr;
+       const char *val;
+       val = NULL;
+       for(ptr = git_vars; ptr->read; ptr++) {
+               if (strcmp(var, ptr->name) == 0) {
+                       val = ptr->read();
+                       break;
+               }
+       }
+       return val;
+}
+
+int main(int argc, char **argv)
+{
+       const char *val;
+       if (argc != 2) {
+               usage(var_usage);
+       }
+       setup_ident();
+       val = NULL;
+
+       if (strcmp(argv[1], "-l") == 0) {
+               list_vars();
+               return 0;
+       }
+       val = read_var(argv[1]);
+       if (!val)
+               usage(var_usage);
+       
+       printf("%s\n", val);
+       
+       return 0;
+}