Allow an alias to start with "-p"
Now, something like [alias] pd = -p diff works as expected. [jc: a follow-up fix from Jeff King folded in.] Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Jul 24, 2006 at 14:10 UTC
4ab243a944a6013d9e862adadd6fe6152c842401
1 file changed
+30
-6
git.c
+30
-6
@@ -35,6 +35,27 @@ static void prepend_to_path(const char *dir, int len)
35
setenv("PATH", path, 1);
36
}
37
38
+static int handle_options(const char*** argv, int* argc)
39
+{
40
+ int handled = 0;
41
+
42
+ while (*argc > 0) {
43
+ const char *cmd = (*argv)[0];
44
+ if (cmd[0] != '-')
45
+ break;
46
+
47
+ if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
48
+ setup_pager();
49
+ } else
50
+ die ("Unknown option: %s", cmd);
51
+
52
+ (*argv)++;
53
+ (*argc)--;
54
+ handled++;
55
+ }
56
+ return handled;
57
+}
58
+
59
static const char *alias_command;
60
static char *alias_string = NULL;
61
@@ -106,7 +127,7 @@ static int handle_alias(int *argcp, const char ***argv)
127
128
subdir = setup_git_directory_gently(&nongit);
129
if (!nongit) {
109
- int count;
130
+ int count, option_count;
131
const char** new_argv;
132
133
alias_command = (*argv)[0];
@@ -114,6 +135,10 @@ static int handle_alias(int *argcp, const char ***argv)
135
if (alias_string) {
136
137
count = split_cmdline(alias_string, &new_argv);
138
+ option_count = handle_options(&new_argv, &count);
139
+ memmove(new_argv - option_count, new_argv,
140
+ count * sizeof(char *));
141
+ new_argv -= option_count;
142
143
if (count < 1)
144
die("empty alias for %s", alias_command);
@@ -273,13 +298,12 @@ int main(int argc, const char **argv, char **envp)
298
299
/* Look for flags.. */
300
while (argc > 1) {
276
- cmd = *++argv;
301
+ argv++;
302
argc--;
303
279
- if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
280
- setup_pager();
281
- continue;
282
- }
304
+ handle_options(&argv, &argc);
305
+
306
+ cmd = *argv;
307
308
if (strncmp(cmd, "--", 2))
309
break;