365
return (*argv) - orig_argv;
366
}
367
368
-static int handle_alias(struct strvec *args)
368
+static int handle_alias(struct strvec *args, struct string_list *expanded_aliases)
369
{
370
int envchanged = 0, ret = 0, saved_errno = errno;
371
int count, option_count;
376
alias_command = args->v[0];
377
alias_string = alias_lookup(alias_command);
378
if (alias_string) {
379
+ struct string_list_item *seen;
380
+
381
if (args->nr == 2 && !strcmp(args->v[1], "-h"))
382
fprintf_ln(stderr, _("'%s' is aliased to '%s'"),
383
alias_command, alias_string);
425
if (!strcmp(alias_command, new_argv[0]))
426
die(_("recursive alias: %s"), alias_command);
427
428
+ string_list_append(expanded_aliases, alias_command);
429
+ seen = unsorted_string_list_lookup(expanded_aliases,
430
+ new_argv[0]);
431
+
432
+ if (seen) {
433
+ struct strbuf sb = STRBUF_INIT;
434
+ for (size_t i = 0; i < expanded_aliases->nr; i++) {
435
+ struct string_list_item *item = &expanded_aliases->items[i];
436
+
437
+ strbuf_addf(&sb, "\n %s", item->string);
438
+ if (item == seen)
439
+ strbuf_addstr(&sb, " <==");
440
+ else if (i == expanded_aliases->nr - 1)
441
+ strbuf_addstr(&sb, " ==>");
442
+ }
443
+ die(_("alias loop detected: expansion of '%s' does"
444
+ " not terminate:%s"), expanded_aliases->items[0].string, sb.buf);
445
+ }
446
+
447
trace_argv_printf(new_argv,
448
"trace: alias expansion: %s =>",
449
alias_command);
827
static int run_argv(struct strvec *args)
828
{
829
int done_alias = 0;
809
- struct string_list cmd_list = STRING_LIST_INIT_DUP;
810
- struct string_list_item *seen;
830
+ struct string_list expanded_aliases = STRING_LIST_INIT_DUP;
831
832
while (1) {
833
/*
879
/* .. then try the external ones */
880
execv_dashed_external(args->v);
881
862
- seen = unsorted_string_list_lookup(&cmd_list, args->v[0]);
863
- if (seen) {
864
- struct strbuf sb = STRBUF_INIT;
865
- for (size_t i = 0; i < cmd_list.nr; i++) {
866
- struct string_list_item *item = &cmd_list.items[i];
867
-
868
- strbuf_addf(&sb, "\n %s", item->string);
869
- if (item == seen)
870
- strbuf_addstr(&sb, " <==");
871
- else if (i == cmd_list.nr - 1)
872
- strbuf_addstr(&sb, " ==>");
873
- }
874
- die(_("alias loop detected: expansion of '%s' does"
875
- " not terminate:%s"), cmd_list.items[0].string, sb.buf);
876
- }
877
-
878
- string_list_append(&cmd_list, args->v[0]);
879
-
882
/*
883
* It could be an alias -- this works around the insanity
884
* of overriding "git log" with "git show" by having
885
* alias.log = show
886
*/
885
- if (!handle_alias(args))
887
+ if (!handle_alias(args, &expanded_aliases))
888
break;
889
done_alias = 1;
890
}
891
890
- string_list_clear(&cmd_list, 0);
892
+ string_list_clear(&expanded_aliases, 0);
893
894
return done_alias;
895
}