Re: [PATCH] help: include list of aliases in git-help --all

2014-02-25 Thread Junio C Hamano
Joel Nothman joel.noth...@gmail.com writes:

 Git help --all had listed all git commands, but no configured aliases.
 This includes aliases as a separate listing, after commands in the main
 git directory and other $PATH directories.

... and why is this a good thing?


 Signed-off-by: Joel Nothman joel.nothman at gmail.com
 ---
  Documentation/git-help.txt |  4 +--
  builtin/help.c |  7 ++---
  help.c | 64 
 +++---
  help.h |  7 -
  4 files changed, 61 insertions(+), 21 deletions(-)

 diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt
 index b21e9d7..c9fe791 100644
 --- a/Documentation/git-help.txt
 +++ b/Documentation/git-help.txt
 @@ -40,8 +40,8 @@ OPTIONS
  ---
  -a::
  --all::
 - Prints all the available commands on the standard output. This
 - option overrides any given command or guide name.
 + Prints all the available commands and aliases on the standard output.
 + This option overrides any given command or guide name.
  
  -g::
  --guides::
 diff --git a/builtin/help.c b/builtin/help.c
 index 1fdefeb..d1dfecd 100644
 --- a/builtin/help.c
 +++ b/builtin/help.c
 @@ -38,7 +38,7 @@ static int show_guides = 0;
  static unsigned int colopts;
  static enum help_format help_format = HELP_FORMAT_NONE;
  static struct option builtin_help_options[] = {
 - OPT_BOOL('a', all, show_all, N_(print all available commands)),
 + OPT_BOOL('a', all, show_all, N_(print all available commands and 
 aliases)),
   OPT_BOOL('g', guides, show_guides, N_(print list of useful 
 guides)),
   OPT_SET_INT('m', man, help_format, N_(show man page), 
 HELP_FORMAT_MAN),
   OPT_SET_INT('w', web, help_format, N_(show manual in web browser),
 @@ -453,6 +453,7 @@ int cmd_help(int argc, const char **argv, const char 
 *prefix)
   int nongit;
   const char *alias;
   enum help_format parsed_help_format;
 + struct cmdnames alias_cmds;
  
   argc = parse_options(argc, argv, prefix, builtin_help_options,
   builtin_help_usage, 0);
 @@ -461,8 +462,8 @@ int cmd_help(int argc, const char **argv, const char 
 *prefix)
   if (show_all) {
   git_config(git_help_config, NULL);
   printf(_(usage: %s%s), _(git_usage_string), \n\n);
 - load_command_list(git-, main_cmds, other_cmds);
 - list_commands(colopts, main_cmds, other_cmds);
 + load_commands_and_aliases(git-, main_cmds, other_cmds, 
 alias_cmds);
 + list_commands(colopts, main_cmds, other_cmds, alias_cmds);
   }
  
   if (show_guides)
 diff --git a/help.c b/help.c
 index df7d16d..3c14af4 100644
 --- a/help.c
 +++ b/help.c
 @@ -86,7 +86,7 @@ static void pretty_print_string_list(struct cmdnames *cmds,
   int i;
  
   for (i = 0; i  cmds-cnt; i++)
 - string_list_append(list, cmds-names[i]-name);
 + string_list_append(list, cmds-names[i]-name);
   /*
* always enable column display, we only consult column.*
* about layout strategy and stuff
 @@ -202,8 +202,48 @@ void load_command_list(const char *prefix,
   exclude_cmds(other_cmds, main_cmds);
  }
  
 +static struct cmdnames aliases;
 +
 +static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
 +{
 + int i;
 + ALLOC_GROW(cmds-names, cmds-cnt + old-cnt, cmds-alloc);
 +
 + for (i = 0; i  old-cnt; i++)
 + cmds-names[cmds-cnt++] = old-names[i];
 + free(old-names);
 + old-cnt = 0;
 + old-names = NULL;
 +}
 +
 +static int load_aliases_cb(const char *var, const char *value, void *cb)
 +{
 + if (starts_with(var, alias.))
 + add_cmdname(aliases, var + 6, strlen(var + 6));
 + return 0;
 +}
 +
 +void load_commands_and_aliases(const char *prefix,
 + struct cmdnames *main_cmds,
 + struct cmdnames *other_cmds,
 + struct cmdnames *alias_cmds)
 +{
 + load_command_list(prefix, main_cmds, other_cmds);
 +
 + /* reuses global aliases from unknown command functionality */
 + git_config(load_aliases_cb, NULL);
 +
 + add_cmd_list(alias_cmds, aliases);
 + qsort(alias_cmds-names, alias_cmds-cnt,
 +   sizeof(*alias_cmds-names), cmdname_compare);
 + uniq(alias_cmds);
 + exclude_cmds(alias_cmds, main_cmds);
 + exclude_cmds(alias_cmds, other_cmds);
 +}
 +
  void list_commands(unsigned int colopts,
 -struct cmdnames *main_cmds, struct cmdnames *other_cmds)
 +struct cmdnames *main_cmds, struct cmdnames *other_cmds,
 +struct cmdnames *alias_cmds)
  {
   if (main_cmds-cnt) {
   const char *exec_path = git_exec_path();
 @@ -219,6 +259,13 @@ void list_commands(unsigned int colopts,
   pretty_print_string_list(other_cmds, colopts);
   putchar('\n');
   }
 +
 + if (alias_cmds-cnt) {
 + printf_ln(_(aliases 

Re: [PATCH] help: include list of aliases in git-help --all

2014-02-25 Thread Joel Nothman
On 26 February 2014 06:15, Junio C Hamano gits...@pobox.com wrote:
 Joel Nothman joel.noth...@gmail.com writes:

 Git help --all had listed all git commands, but no configured aliases.
 This includes aliases as a separate listing, after commands in the main
 git directory and other $PATH directories.

 ... and why is this a good thing?

A fair question: I had considered it a conspicuous absence from the
list of commands in git help. After all, aliases are treated like
commands for a few purposes: they are executed as commands, they are
listed as possible command spelling corrections, and they are valid
arguments to git help. They are also like commands in that it is
possible to forget their name, or whether they are defined on a
particular workstation, and to hence want a listing. A user may also
not recall whether they had implemented a particular shortcut as an
alias or as a script (one may initially implement a script, and
realise an alias is sufficient; one may at first implement an alias
and realise it is insufficient, and that a script is needed).

In short, for many of the purposes in which one would seek git help
-a, there is no reason to *exclude* aliases from a list of commands
executed likewise.


 Signed-off-by: Joel Nothman joel.nothman at gmail.com
 ---
  Documentation/git-help.txt |  4 +--
  builtin/help.c |  7 ++---
  help.c | 64 
 +++---
  help.h |  7 -
  4 files changed, 61 insertions(+), 21 deletions(-)

 diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt
 index b21e9d7..c9fe791 100644
 --- a/Documentation/git-help.txt
 +++ b/Documentation/git-help.txt
 @@ -40,8 +40,8 @@ OPTIONS
  ---
  -a::
  --all::
 - Prints all the available commands on the standard output. This
 - option overrides any given command or guide name.
 + Prints all the available commands and aliases on the standard output.
 + This option overrides any given command or guide name.

  -g::
  --guides::
 diff --git a/builtin/help.c b/builtin/help.c
 index 1fdefeb..d1dfecd 100644
 --- a/builtin/help.c
 +++ b/builtin/help.c
 @@ -38,7 +38,7 @@ static int show_guides = 0;
  static unsigned int colopts;
  static enum help_format help_format = HELP_FORMAT_NONE;
  static struct option builtin_help_options[] = {
 - OPT_BOOL('a', all, show_all, N_(print all available commands)),
 + OPT_BOOL('a', all, show_all, N_(print all available commands and 
 aliases)),
   OPT_BOOL('g', guides, show_guides, N_(print list of useful 
 guides)),
   OPT_SET_INT('m', man, help_format, N_(show man page), 
 HELP_FORMAT_MAN),
   OPT_SET_INT('w', web, help_format, N_(show manual in web browser),
 @@ -453,6 +453,7 @@ int cmd_help(int argc, const char **argv, const char 
 *prefix)
   int nongit;
   const char *alias;
   enum help_format parsed_help_format;
 + struct cmdnames alias_cmds;

   argc = parse_options(argc, argv, prefix, builtin_help_options,
   builtin_help_usage, 0);
 @@ -461,8 +462,8 @@ int cmd_help(int argc, const char **argv, const char 
 *prefix)
   if (show_all) {
   git_config(git_help_config, NULL);
   printf(_(usage: %s%s), _(git_usage_string), \n\n);
 - load_command_list(git-, main_cmds, other_cmds);
 - list_commands(colopts, main_cmds, other_cmds);
 + load_commands_and_aliases(git-, main_cmds, other_cmds, 
 alias_cmds);
 + list_commands(colopts, main_cmds, other_cmds, alias_cmds);
   }

   if (show_guides)
 diff --git a/help.c b/help.c
 index df7d16d..3c14af4 100644
 --- a/help.c
 +++ b/help.c
 @@ -86,7 +86,7 @@ static void pretty_print_string_list(struct cmdnames *cmds,
   int i;

   for (i = 0; i  cmds-cnt; i++)
 - string_list_append(list, cmds-names[i]-name);
 + string_list_append(list, cmds-names[i]-name);
   /*
* always enable column display, we only consult column.*
* about layout strategy and stuff
 @@ -202,8 +202,48 @@ void load_command_list(const char *prefix,
   exclude_cmds(other_cmds, main_cmds);
  }

 +static struct cmdnames aliases;
 +
 +static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
 +{
 + int i;
 + ALLOC_GROW(cmds-names, cmds-cnt + old-cnt, cmds-alloc);
 +
 + for (i = 0; i  old-cnt; i++)
 + cmds-names[cmds-cnt++] = old-names[i];
 + free(old-names);
 + old-cnt = 0;
 + old-names = NULL;
 +}
 +
 +static int load_aliases_cb(const char *var, const char *value, void *cb)
 +{
 + if (starts_with(var, alias.))
 + add_cmdname(aliases, var + 6, strlen(var + 6));
 + return 0;
 +}
 +
 +void load_commands_and_aliases(const char *prefix,
 + struct cmdnames *main_cmds,
 + struct cmdnames *other_cmds,
 + struct cmdnames *alias_cmds)
 +{
 + load_command_list(prefix, main_cmds, other_cmds);
 +
 

Re: [PATCH] help: include list of aliases in git-help --all

2014-02-25 Thread Junio C Hamano
Joel Nothman joel.noth...@gmail.com writes:

 arguments to git help. They are also like commands in that it is
 possible to forget their name, or whether they are defined on a
 particular workstation, and to hence want a listing.

I did envision that it would be useful for the last case, but then
the users would be helped even more if they can get a list of ONLY
aliases, not buried in many standard commands they already know
about.

In other words, I was not fundamentally opposed to *a* way to get a
list that includes aliases, but I was not convinced if it is a good
idea to *change* the output, which people knew would consist of
commands but not aliases, to suddenly start including aliases.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] help: include list of aliases in git-help --all

2014-02-25 Thread Joel Nothman
On 26 February 2014 08:51, Junio C Hamano gits...@pobox.com wrote:
 Joel Nothman joel.noth...@gmail.com writes:

 arguments to git help. They are also like commands in that it is
 possible to forget their name, or whether they are defined on a
 particular workstation, and to hence want a listing.

 I did envision that it would be useful for the last case, but then
 the users would be helped even more if they can get a list of ONLY
 aliases, not buried in many standard commands they already know
 about.

The list is partitioned. It is partitioned already between
git-installed commands and others on the path. This patch adds a third
partition when required. So they *do* see only aliases... after all
the commands.

Note also that any command on the path will override an alias with the
same name. So in order to list (effective) aliases, you need to
calculate the list of commands as well. If someone defines an alias
overridden by a command, git help -a now makes that apparent by
excluding the alias and including the command above it, while `git
config --get-regexp ^alias` does not.

 In other words, I was not fundamentally opposed to *a* way to get a
 list that includes aliases, but I was not convinced if it is a good
 idea to *change* the output, which people knew would consist of
 commands but not aliases, to suddenly start including aliases.

I don't think this will concern most users for whom aliases are
non-existent, and hence no section will be shown.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] help: include list of aliases in git-help --all

2014-02-25 Thread Philip Oakley

From: Joel Nothman joel.noth...@gmail.com

On 26 February 2014 06:15, Junio C Hamano gits...@pobox.com wrote:

Joel Nothman joel.noth...@gmail.com writes:

Git help --all had listed all git commands, but no configured 
aliases.
This includes aliases as a separate listing, after commands in the 
main

git directory and other $PATH directories.


... and why is this a good thing?


A fair question: I had considered it a conspicuous absence from the
list of commands in git help.


Surely one alternative would be to add an --alias or --aliases option to 
the help command so the user can chose which ones s/he desires to be 
helped about.


At least that's the way I did it with the --guides option.


 After all, aliases are treated like
commands for a few purposes: they are executed as commands, they are
listed as possible command spelling corrections, and they are valid
arguments to git help. They are also like commands in that it is
possible to forget their name, or whether they are defined on a
particular workstation, and to hence want a listing. A user may also
not recall whether they had implemented a particular shortcut as an
alias or as a script (one may initially implement a script, and
realise an alias is sufficient; one may at first implement an alias
and realise it is insufficient, and that a script is needed).

In short, for many of the purposes in which one would seek git help
-a, there is no reason to *exclude* aliases from a list of commands
executed likewise.



Signed-off-by: Joel Nothman joel.nothman at gmail.com
---
 Documentation/git-help.txt |  4 +--
 builtin/help.c |  7 ++---
 help.c | 64 
+++---

 help.h |  7 -
 4 files changed, 61 insertions(+), 21 deletions(-)

diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt
index b21e9d7..c9fe791 100644
--- a/Documentation/git-help.txt
+++ b/Documentation/git-help.txt
@@ -40,8 +40,8 @@ OPTIONS
 ---
 -a::
 --all::
- Prints all the available commands on the standard output. This
- option overrides any given command or guide name.
+ Prints all the available commands and aliases on the standard 
output.

+ This option overrides any given command or guide name.

 -g::
 --guides::
diff --git a/builtin/help.c b/builtin/help.c
index 1fdefeb..d1dfecd 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -38,7 +38,7 @@ static int show_guides = 0;
 static unsigned int colopts;
 static enum help_format help_format = HELP_FORMAT_NONE;
 static struct option builtin_help_options[] = {
- OPT_BOOL('a', all, show_all, N_(print all available 
commands)),
+ OPT_BOOL('a', all, show_all, N_(print all available 
commands and aliases)),
  OPT_BOOL('g', guides, show_guides, N_(print list of useful 
guides)),
  OPT_SET_INT('m', man, help_format, N_(show man page), 
HELP_FORMAT_MAN),
  OPT_SET_INT('w', web, help_format, N_(show manual in web 
browser),
@@ -453,6 +453,7 @@ int cmd_help(int argc, const char **argv, const 
char *prefix)

  int nongit;
  const char *alias;
  enum help_format parsed_help_format;
+ struct cmdnames alias_cmds;

  argc = parse_options(argc, argv, prefix, builtin_help_options,
  builtin_help_usage, 0);
@@ -461,8 +462,8 @@ int cmd_help(int argc, const char **argv, const 
char *prefix)

  if (show_all) {
  git_config(git_help_config, NULL);
  printf(_(usage: %s%s), _(git_usage_string), \n\n);
- load_command_list(git-, main_cmds, other_cmds);
- list_commands(colopts, main_cmds, other_cmds);
+ load_commands_and_aliases(git-, main_cmds, 
other_cmds, alias_cmds);
+ list_commands(colopts, main_cmds, other_cmds, 
alias_cmds);

  }

  if (show_guides)
diff --git a/help.c b/help.c
index df7d16d..3c14af4 100644
--- a/help.c
+++ b/help.c
@@ -86,7 +86,7 @@ static void pretty_print_string_list(struct 
cmdnames *cmds,

  int i;

  for (i = 0; i  cmds-cnt; i++)
- string_list_append(list, cmds-names[i]-name);
+ string_list_append(list, cmds-names[i]-name);
  /*
   * always enable column display, we only consult column.*
   * about layout strategy and stuff
@@ -202,8 +202,48 @@ void load_command_list(const char *prefix,
  exclude_cmds(other_cmds, main_cmds);
 }

+static struct cmdnames aliases;
+
+static void add_cmd_list(struct cmdnames *cmds, struct cmdnames 
*old)

+{
+ int i;
+ ALLOC_GROW(cmds-names, cmds-cnt + old-cnt, cmds-alloc);
+
+ for (i = 0; i  old-cnt; i++)
+ cmds-names[cmds-cnt++] = old-names[i];
+ free(old-names);
+ old-cnt = 0;
+ old-names = NULL;
+}
+
+static int load_aliases_cb(const char *var, const char *value, void 
*cb)

+{
+ if (starts_with(var, alias.))
+ add_cmdname(aliases, var + 6, strlen(var + 6));
+ return 0;
+}
+
+void load_commands_and_aliases(const char *prefix,
+  

Re: [PATCH] help: include list of aliases in git-help --all

2014-02-25 Thread Junio C Hamano
Joel Nothman joel.noth...@gmail.com writes:

 Git help --all had listed all git commands, but no configured aliases.
 This includes aliases as a separate listing, after commands in the main
 git directory and other $PATH directories.

 Signed-off-by: Joel Nothman joel.nothman at gmail.com
 ---

Thanks.

 diff --git a/help.c b/help.c
 index df7d16d..3c14af4 100644
 --- a/help.c
 +++ b/help.c
 @@ -86,7 +86,7 @@ static void pretty_print_string_list(struct cmdnames *cmds,
   int i;
  
   for (i = 0; i  cmds-cnt; i++)
 - string_list_append(list, cmds-names[i]-name);
 + string_list_append(list, cmds-names[i]-name);

Why?

 @@ -202,8 +202,48 @@ void load_command_list(const char *prefix,
   exclude_cmds(other_cmds, main_cmds);
  }
  
 +static struct cmdnames aliases;

Instead of using a static global variable, perhaps make this an
on-stack variable in load_commands_and_aliases() that is passed as a
callback parameter to load_aliases_cb() thru git_config()?

 +static int load_aliases_cb(const char *var, const char *value, void *cb)
 +{

That is, cb here is the second parameter you gave to git_config().

  void list_commands(unsigned int colopts,
 -struct cmdnames *main_cmds, struct cmdnames *other_cmds)
 +struct cmdnames *main_cmds, struct cmdnames *other_cmds,
 +struct cmdnames *alias_cmds)
  {
   if (main_cmds-cnt) {
   const char *exec_path = git_exec_path();
 @@ -219,6 +259,13 @@ void list_commands(unsigned int colopts,
   pretty_print_string_list(other_cmds, colopts);
   putchar('\n');
   }
 +
 + if (alias_cmds-cnt) {
 + printf_ln(_(aliases defined in git configuration));

This will not break the use of git help -a in our completion
script, because it ignores anything that does not begin with two SP
followed by alphanumerics.

It may however break scripts that read from help -a done by other
people that may remove the lines in the output that are known to
them as not names of commands (i.e. available git commands...  and
git commands avaliable elsewhere...)---they haven't seen this new
string and would not know that this line must be skipped.

Other than that, looks reasonably cleanly done.  We'd need a test to
cover this so that other people will not break it in future patches.


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