[PATCH] Soft aliases: add "less" and minimal documentation
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Dec 5, 2007, 11:37 UTC
- Message-ID
- <Pine.LNX.4.64.0712051131120.27959@racer.site>
- In-Reply-To
- <7vzlwps8zf.fsf@gitster.siamese.dyndns.org>
Now you can use "git less HEAD" to view the raw HEAD commit object. It is really a soft alias (i.e. it can be overridden by any user-specified alias) to "-p cat-file -p".
This commit refactors the code a bit, to make adding new soft aliases much easier.
It also adds a few lines in git.txt, so that users actually have a chance to find out about soft aliases.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> ---
On Wed, 5 Dec 2007, Junio C Hamano wrote:
> * jk/builtin-alias (Fri Nov 30 11:22:58 2007 -0500) 1 commit > + Support builtin aliases > > Cute hack. I'd like to have "git less" here.
How about this?
BTW now it should be easy to add soft aliases for "update", "up", "checkin" and "ci".
Documentation/git.txt | 9 +++++++++ git.c | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/Documentation/git.txt b/Documentation/git.txt index c4e4d24..d29dfdc 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -248,6 +248,15 @@ users typically do not use them directly. include::cmds-purehelpers.txt[] +Soft aliases +~~~~~~~~~~~~ + +There are a few hard-coded aliases which can be overridden by explicit +aliases (see gitlink:git-config[1]). These include "view" for viewing +the repository graphically, and "less" to show an object from the +database using the pager. + + Configuration Mechanism ----------------------- diff --git a/git.c b/git.c index 92cc49b..3c82f80 100644 --- a/git.c +++ b/git.c @@ -148,10 +148,19 @@ static int split_cmdline(char *cmdline, const char ***argv) return count; } +static struct { + const char *alias, *command; +} builtin_aliases[] = { + { "view", "!gitk" }, + { "less", "-p cat-file -p" }, +}; + static char *builtin_alias(const char *cmd) { - if (!strcmp(cmd, "view")) - return xstrdup("!gitk"); + int i; + for (i = 0; i < ARRAY_SIZE(builtin_aliases); i++) + if (!strcmp(cmd, builtin_aliases[i].alias)) + return xstrdup(builtin_aliases[i].command); return NULL; }
-- 1.5.3.7.2139.g2a5a3