From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] Introduce git version --list-features for porcelain use
Date: Thu, 21 Jun 2007 00:59:03 -0400 [thread overview]
Message-ID: <20070621045903.GA14047@spearce.org> (raw)
As a porcelain author I'm finding it difficult to keep track of
what features I can use in git-gui. Newer versions of Git have
newer capabilities but they don't always immediately get newer
version numbers that I can easily test for.
This is a simple plumbing option that lets a porcelain ask the
plumbing for its capabilities, at which point the porcelain can
work around anything missing, or recommend to the user that they
upgrade their plumbing layer.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
Because 'maint' does not support `git-blame -w` I can't apply your
recent (and insanely good idea) 'git-gui: use "blame -w -C -C" for
"where did it come from, originally?"' without something like the
following, so I know that `git blame -w -C -C` will be accepted
by the underlying plumbing. ;-)
help.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
t/t0000-basic.sh | 16 +++++++++++
2 files changed, 91 insertions(+), 2 deletions(-)
diff --git a/help.c b/help.c
index 1cd33ec..9f24a0f 100644
--- a/help.c
+++ b/help.c
@@ -9,6 +9,11 @@
#include "common-cmds.h"
#include <sys/ioctl.h>
+static const char *supported_features[] = {
+ "blame-ignore-whitespace",
+ "list-features",
+};
+
/* most GUI terminals set COLUMNS (although some don't export it) */
static int term_columns(void)
{
@@ -190,10 +195,78 @@ void help_unknown_cmd(const char *cmd)
exit(1);
}
+static int is_feature_name_sane(const char *a)
+{
+ if (!*a || *a == '-')
+ return 0;
+ for (; *a; a++) {
+ if (! ((*a >= 'a' && *a <= 'z')
+ || (*a >= '0' && *a <= '9')
+ || *a == '-'))
+ return 0;
+ }
+ return 1;
+}
+
+static int cmp_feature(const void *a_, const void *b_)
+{
+ const char *a = *((const char **)a_);
+ const char *b = *((const char **)b_);
+ return strcmp(a, b);
+}
+
+static void list_features()
+{
+ unsigned cnt = ARRAY_SIZE(supported_features);
+ unsigned i;
+
+ qsort(supported_features, cnt,
+ sizeof(supported_features[0]), cmp_feature);
+ for (i = 0; i < cnt; i++) {
+ const char *f = supported_features[i];
+ if (!is_feature_name_sane(f))
+ die("feature name \"%s\" is bogus", f);
+ printf("%s\n", f);
+ }
+}
+
+static int supports_feature(const char *the_feature)
+{
+ unsigned cnt = ARRAY_SIZE(supported_features);
+ unsigned i;
+
+ for (i = 0; i < cnt; i++) {
+ if (!strcmp(supported_features[i], the_feature))
+ return 0;
+ }
+ return 1;
+}
+
+static const char version_usage[] =
+"git-version [(--list-features | --supports-feature=<name>*)]";
+
int cmd_version(int argc, const char **argv, const char *prefix)
{
- printf("git version %s\n", git_version_string);
- return 0;
+ int i, ret = 0, list = 0, test = 0;
+
+ for (i = 1; i < argc; i++) {
+ const char *arg = argv[i];
+ if (!strcmp(arg, "--list-features"))
+ list = 1;
+ else if (!prefixcmp(arg, "--supports-feature=")) {
+ test = 1;
+ ret |= supports_feature(arg + 19);
+ } else
+ usage(version_usage);
+ }
+
+ if (list && test)
+ die("cannot use both --list-features and --supports-feature");
+ if (list)
+ list_features();
+ if (!list && !test)
+ printf("git version %s\n", git_version_string);
+ return ret;
}
int cmd_help(int argc, const char **argv, const char *prefix)
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 8bfe832..9fc5824 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -31,6 +31,22 @@ fi
. ./test-lib.sh
################################################################
+# git version
+
+test_expect_success \
+ 'git version is functional' \
+ 'git version'
+test_expect_success \
+ 'git version --list-features' \
+ 'git version --list-features'
+test_expect_success \
+ 'feature "list-features" is supported' \
+ 'git version --supports-feature=list-features'
+test_expect_failure \
+ 'feature "THISNEVERWILLBEAGITFEATURE" is not supported' \
+ 'git version --supports-feature=THISNEVERWILLBEAGITFEATURE'
+
+################################################################
# git-init has been done in an empty repository.
# make sure it is empty.
--
1.5.2.2.1050.g51a8b
next reply other threads:[~2007-06-21 4:59 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-21 4:59 Shawn O. Pearce [this message]
2007-06-21 5:47 ` [PATCH] Introduce git version --list-features for porcelain use Junio C Hamano
2007-06-21 6:10 ` Shawn O. Pearce
2007-06-21 7:02 ` Junio C Hamano
2007-06-21 9:00 ` [PATCH] Make list of features auto-managed Junio C Hamano
2007-06-21 9:18 ` Junio C Hamano
2007-06-21 15:55 ` Nicolas Pitre
2007-06-21 19:32 ` Junio C Hamano
2007-06-22 3:25 ` Shawn O. Pearce
2007-06-22 3:58 ` Junio C Hamano
2007-06-22 4:07 ` Nicolas Pitre
2007-06-22 4:33 ` Shawn O. Pearce
2007-06-22 5:15 ` Nicolas Pitre
2007-06-22 9:59 ` Josef Weidendorfer
2007-06-22 14:03 ` Catalin Marinas
2007-06-21 11:58 ` [PATCH] Introduce git version --list-features for porcelain use Johannes Schindelin
-- strict thread matches above, loose matches on Subject: below --
2007-05-30 12:34 [PATCH] Introduce git-supported-features " Johannes Schindelin
2007-05-31 0:20 ` [PATCH] Introduce git version --list-features " Shawn O. Pearce
2007-05-31 0:25 ` Johannes Schindelin
2007-05-31 6:50 ` Alex Riesen
2007-05-31 13:30 ` Shawn O. Pearce
2007-05-31 23:46 ` Junio C Hamano
2007-06-01 3:09 ` Shawn O. Pearce
2007-06-01 3:57 ` Junio C Hamano
2007-06-01 4:14 ` Shawn O. Pearce
2007-06-01 7:13 ` Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070621045903.GA14047@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.