Thread (24 messages) flat view 24 messages, 7 authors, 2016-06-15

Re: [PATCH v3] build: add default aliases

From: SZEDER Gábor <hidden>
Date: 2016-06-15 22:58:53

The subject line needs to be updated.

On Sat, Sep 21, 2013 at 02:20:21PM -0500, Felipe Contreras wrote:
For now simply add a few common aliases.

  co = checkout
  ci = commit
  rb = rebase
  st = status

Signed-off-by: Felipe Contreras <redacted>
---
[...]
quoted hunk ↗ jump to hunk
diff --git a/alias.c b/alias.c
index eb9f08b..d6bad69 100644
--- a/alias.c
+++ b/alias.c
@@ -14,11 +14,28 @@ static int alias_lookup_cb(const char *k, const char *v, void *cb)
 	return 0;
 }
 
+static struct {
+	const char *key;
+	const char *val;
+} default_aliases[] = {
+	{ "co", "checkout" },
+	{ "ci", "checkout" },
+	{ "rb", "rebase" },
+	{ "st", "status" },
+};
+
 char *alias_lookup(const char *alias)
 {
+	int i;
 	alias_key = alias;
 	alias_val = NULL;
 	git_config(alias_lookup_cb, NULL);
+	if (alias_val)
+		return alias_val;
+	for (i = 0; i < ARRAY_SIZE(default_aliases); i++) {
+		if (!strcmp(alias, default_aliases[i].key))
+			return xstrdup(default_aliases[i].val);
+	}
 	return alias_val;
 }
Aliases implemented this way don't work the same way as "normal"
aliases do:

  $ # which aliases do I have?
  $ ./bin-wrappers/git config --get-regexp "alias\..*"
  $ # no aliases at all
  $ # does completion work?
  $ ./bin-wrappers/git co ma<TAB>
  mailmap.c      mailmap.h      mailmap.o      match-trees.c  match-trees.o
  $ # no refs completion
  $ # let's see a real alias
  $ git config alias.co checkout
  $ ./bin-wrappers/git config --get-regexp "alias\..*"
  alias.co checkout
  $ ./bin-wrappers/git co ma<TAB>
  maint    master
  $ # as expected


Best,
Gábor
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help