diff options
Diffstat (limited to 'help.c')
-rw-r--r-- | help.c | 83 |
1 files changed, 39 insertions, 44 deletions
@@ -1,6 +1,7 @@ #include "cache.h" #include "builtin.h" #include "exec_cmd.h" +#include "run-command.h" #include "levenshtein.h" #include "help.h" #include "common-cmds.h" @@ -11,11 +12,9 @@ void add_cmdname(struct cmdnames *cmds, const char *name, int len) { - struct cmdname *ent = xmalloc(sizeof(*ent) + len + 1); - + struct cmdname *ent; + FLEX_ALLOC_MEM(ent, name, name, len); ent->len = len; - memcpy(ent->name, name, len); - ent->name[len] = 0; ALLOC_GROW(cmds->names, cmds->cnt + 1, cmds->alloc); cmds->names[cmds->cnt++] = ent; @@ -98,33 +97,6 @@ static void pretty_print_cmdnames(struct cmdnames *cmds, unsigned int colopts) string_list_clear(&list, 0); } -static int is_executable(const char *name) -{ - struct stat st; - - if (stat(name, &st) || /* stat, not lstat */ - !S_ISREG(st.st_mode)) - return 0; - -#if defined(GIT_WINDOWS_NATIVE) -{ /* cannot trust the executable bit, peek into the file instead */ - char buf[3] = { 0 }; - int n; - int fd = open(name, O_RDONLY); - st.st_mode &= ~S_IXUSR; - if (fd >= 0) { - n = read(fd, buf, 2); - if (n == 2) - /* DOS executables start with "MZ" */ - if (!strcmp(buf, "#!") || !strcmp(buf, "MZ")) - st.st_mode |= S_IXUSR; - close(fd); - } -} -#endif - return st.st_mode & S_IXUSR; -} - static void list_commands_in_dir(struct cmdnames *cmds, const char *path, const char *prefix) @@ -172,8 +144,7 @@ void load_command_list(const char *prefix, if (exec_path) { list_commands_in_dir(main_cmds, exec_path, prefix); - qsort(main_cmds->names, main_cmds->cnt, - sizeof(*main_cmds->names), cmdname_compare); + QSORT(main_cmds->names, main_cmds->cnt, cmdname_compare); uniq(main_cmds); } @@ -192,8 +163,7 @@ void load_command_list(const char *prefix, } free(paths); - qsort(other_cmds->names, other_cmds->cnt, - sizeof(*other_cmds->names), cmdname_compare); + QSORT(other_cmds->names, other_cmds->cnt, cmdname_compare); uniq(other_cmds); } exclude_cmds(other_cmds, main_cmds); @@ -218,17 +188,38 @@ void list_commands(unsigned int colopts, } } +static int cmd_group_cmp(const void *elem1, const void *elem2) +{ + const struct cmdname_help *e1 = elem1; + const struct cmdname_help *e2 = elem2; + + if (e1->group < e2->group) + return -1; + if (e1->group > e2->group) + return 1; + return strcmp(e1->name, e2->name); +} + void list_common_cmds_help(void) { int i, longest = 0; + int current_grp = -1; for (i = 0; i < ARRAY_SIZE(common_cmds); i++) { if (longest < strlen(common_cmds[i].name)) longest = strlen(common_cmds[i].name); } - puts(_("The most commonly used git commands are:")); + QSORT(common_cmds, ARRAY_SIZE(common_cmds), cmd_group_cmp); + + puts(_("These are common Git commands used in various situations:")); + for (i = 0; i < ARRAY_SIZE(common_cmds); i++) { + if (common_cmds[i].group != current_grp) { + printf("\n%s\n", _(common_cmd_groups[common_cmds[i].group])); + current_grp = common_cmds[i].group; + } + printf(" %s ", common_cmds[i].name); mput_char(' ', longest - strlen(common_cmds[i].name)); puts(_(common_cmds[i].help)); @@ -304,8 +295,7 @@ const char *help_unknown_cmd(const char *cmd) add_cmd_list(&main_cmds, &aliases); add_cmd_list(&main_cmds, &other_cmds); - qsort(main_cmds.names, main_cmds.cnt, - sizeof(*main_cmds.names), cmdname_compare); + QSORT(main_cmds.names, main_cmds.cnt, cmdname_compare); uniq(&main_cmds); /* This abuses cmdname->len for levenshtein distance */ @@ -339,8 +329,7 @@ const char *help_unknown_cmd(const char *cmd) levenshtein(cmd, candidate, 0, 2, 1, 3) + 1; } - qsort(main_cmds.names, main_cmds.cnt, - sizeof(*main_cmds.names), levenshtein_compare); + QSORT(main_cmds.names, main_cmds.cnt, levenshtein_compare); if (!main_cmds.cnt) die(_("Uh oh. Your system reports no Git commands at all.")); @@ -372,7 +361,7 @@ const char *help_unknown_cmd(const char *cmd) if (autocorrect > 0) { fprintf_ln(stderr, _("in %0.1f seconds automatically..."), (float)autocorrect/10.0); - poll(NULL, 0, autocorrect * 100); + sleep_millisec(autocorrect * 100); } return assumed; } @@ -381,8 +370,8 @@ const char *help_unknown_cmd(const char *cmd) if (SIMILAR_ENOUGH(best_similarity)) { fprintf_ln(stderr, - Q_("\nDid you mean this?", - "\nDid you mean one of these?", + Q_("\nThe most similar command is", + "\nThe most similar commands are", n)); for (i = 0; i < n; i++) @@ -399,6 +388,12 @@ int cmd_version(int argc, const char **argv, const char *prefix) * with external projects that rely on the output of "git version". */ printf("git version %s\n", git_version_string); + while (*++argv) { + if (!strcmp(*argv, "--build-options")) { + printf("sizeof-long: %d\n", (int)sizeof(long)); + /* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */ + } + } return 0; } @@ -407,7 +402,7 @@ struct similar_ref_cb { struct string_list *similar_refs; }; -static int append_similar_ref(const char *refname, const unsigned char *sha1, +static int append_similar_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data); |