[RFC/PATCH 2/5] glossary: introduce glossary lookup command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When using a localised git, there are many reasons why a correspondence
between English and localised git terms is needed:
- connect localised messages with English ones (porcelain vs. plumbing)
- connect localised messages with English man pages or online docs
- help out someone in a different locale

Introduce a `git glossary' command that leverages the existing infrastructure
in three possible ways:
- `git glossary' lists all glossary terms along with their translation
- `git glossary foo' matches `foo' in the glossary (both English and
  localisation; partial matches shown)
- `git glossary -a foo' matches `foo' in the git message catalogue
  (English, exact match only).

Signed-off-by: Michael J Gruber <git@xxxxxxxxxxxxxxxxxxxx>
---
Some bike-shedding expected regarding the interface...
Once I've learned how to test l10n stuff, this will be amended.

 .gitignore         |   1 +
 Makefile           |   1 +
 builtin.h          |   1 +
 builtin/glossary.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 command-list.txt   |   1 +
 git.c              |   1 +
 6 files changed, 109 insertions(+)
 create mode 100644 builtin/glossary.c

diff --git a/.gitignore b/.gitignore
index fb4ebaa..ff627a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -64,6 +64,7 @@
 /git-fsck-objects
 /git-gc
 /git-get-tar-commit-id
+/git-glossary
 /git-grep
 /git-hash-object
 /git-help
diff --git a/Makefile b/Makefile
index ae74fdf..8fc9de2 100644
--- a/Makefile
+++ b/Makefile
@@ -824,6 +824,7 @@ BUILTIN_OBJS += builtin/for-each-ref.o
 BUILTIN_OBJS += builtin/fsck.o
 BUILTIN_OBJS += builtin/gc.o
 BUILTIN_OBJS += builtin/get-tar-commit-id.o
+BUILTIN_OBJS += builtin/glossary.o
 BUILTIN_OBJS += builtin/grep.o
 BUILTIN_OBJS += builtin/hash-object.o
 BUILTIN_OBJS += builtin/help.o
diff --git a/builtin.h b/builtin.h
index b87df70..dcaf220 100644
--- a/builtin.h
+++ b/builtin.h
@@ -68,6 +68,7 @@ extern int cmd_format_patch(int argc, const char **argv, const char *prefix);
 extern int cmd_fsck(int argc, const char **argv, const char *prefix);
 extern int cmd_gc(int argc, const char **argv, const char *prefix);
 extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
+extern int cmd_glossary(int argc, const char **argv, const char *prefix);
 extern int cmd_grep(int argc, const char **argv, const char *prefix);
 extern int cmd_hash_object(int argc, const char **argv, const char *prefix);
 extern int cmd_help(int argc, const char **argv, const char *prefix);
diff --git a/builtin/glossary.c b/builtin/glossary.c
new file mode 100644
index 0000000..4ad8c51
--- /dev/null
+++ b/builtin/glossary.c
@@ -0,0 +1,104 @@
+/*
+ * Builtin help command
+ */
+#include "cache.h"
+#include "builtin.h"
+#include "exec_cmd.h"
+#include "parse-options.h"
+#include "run-command.h"
+#include "column.h"
+#include "glossary.h"
+
+
+static int match_all = 0;
+static unsigned int colopts;
+static struct option builtin_glossary_options[] = {
+	OPT_BOOL('a', "all", &match_all, N_("match all English git messages")),
+	OPT_END(),
+};
+
+static const char * const builtin_glossary_usage[] = {
+	N_("git glossary [-a|--all] [term]..."),
+	NULL
+};
+
+
+/*
+static int git_glossary_config(const char *var, const char *value, void *cb)
+{
+	if (starts_with(var, "column."))
+		return git_column_config(var, value, "help", &colopts);
+
+	return git_default_config(var, value, cb);
+}
+*/
+
+static void emit_one(const char *one, const char* two, int pad)
+{
+	printf("   %s   ", one);
+	for (; pad; pad--)
+		putchar(' ');
+	puts(two);
+}
+
+static void lookup_all(int n, const char **terms)
+{
+	int i;
+	for (i = 0; i < n; i++)
+		emit_one(terms[i], _(terms[i]), 0);
+}
+
+static void lookup_glossary(int n, const char **terms)
+{
+	int i, j;
+	for (i = 0; i < ARRAY_SIZE(glossary); i++) {
+		for (j = 0; j < n; j++) {
+			if (strstr(glossary[i], terms[j]) || strstr(_(glossary[i]), terms[j])) {
+				emit_one(glossary[i], _(glossary[i]), 0);
+				break;
+			}
+		}
+	}
+}
+
+static void list_glossary()
+{
+	int i, longest = 0;
+
+	for (i = 0; i < ARRAY_SIZE(glossary); i++) {
+		if (longest < strlen(glossary[i]))
+			longest = strlen(glossary[i]);
+	}
+
+	for (i = 0; i < ARRAY_SIZE(glossary); i++)
+		emit_one(glossary[i], _(glossary[i]), longest - strlen(glossary[i]));
+}
+
+int cmd_glossary(int argc, const char **argv, const char *prefix)
+{
+	int nongit;
+
+	argc = parse_options(argc, argv, prefix, builtin_glossary_options,
+			builtin_glossary_usage, 0);
+
+	if (match_all && !argc) {
+		printf(_("usage: %s%s"), _(builtin_glossary_usage[0]), "\n\n");
+		exit(1);
+	}
+
+
+/*
+	setup_git_directory_gently(&nongit);
+	git_config(git_help_config, NULL);
+*/
+	if (!argc) {
+		list_glossary();
+		exit(0);
+	}
+	if (match_all)
+		lookup_all(argc, argv);
+	else
+		lookup_glossary(argc, argv);
+
+	return 0;
+}
diff --git a/command-list.txt b/command-list.txt
index f1eae08..d26517d 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -51,6 +51,7 @@ git-format-patch                        mainporcelain
 git-fsck	                        ancillaryinterrogators
 git-gc                                  mainporcelain
 git-get-tar-commit-id                   ancillaryinterrogators
+git-glossary				ancillaryinterrogators
 git-grep                                mainporcelain common
 git-gui                                 mainporcelain
 git-hash-object                         plumbingmanipulators
diff --git a/git.c b/git.c
index 82d7a1c..e2adfbe 100644
--- a/git.c
+++ b/git.c
@@ -411,6 +411,7 @@ static struct cmd_struct commands[] = {
 	{ "fsck-objects", cmd_fsck, RUN_SETUP },
 	{ "gc", cmd_gc, RUN_SETUP },
 	{ "get-tar-commit-id", cmd_get_tar_commit_id },
+	{ "glossary", cmd_glossary },
 	{ "grep", cmd_grep, RUN_SETUP_GENTLY },
 	{ "hash-object", cmd_hash_object },
 	{ "help", cmd_help },
-- 
2.2.0.345.g7041aac

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]