@@ -177,24 +177,24 @@ static int handle_alias(int *argcp, const char ***argv)
177
177
alias_string = alias_lookup (alias_command );
178
178
if (alias_string ) {
179
179
if (alias_string [0 ] == '!' ) {
180
+ const char * * alias_argv ;
181
+ int argc = * argcp , i ;
182
+
180
183
commit_pager_choice ();
181
- if (* argcp > 1 ) {
182
- struct strbuf buf ;
183
-
184
- strbuf_init (& buf , PATH_MAX );
185
- strbuf_addstr (& buf , alias_string );
186
- sq_quote_argv (& buf , (* argv ) + 1 , PATH_MAX );
187
- free (alias_string );
188
- alias_string = buf .buf ;
189
- }
190
- trace_printf ("trace: alias to shell cmd: %s => %s\n" ,
191
- alias_command , alias_string + 1 );
192
- ret = system (alias_string + 1 );
193
- if (ret >= 0 && WIFEXITED (ret ) &&
194
- WEXITSTATUS (ret ) != 127 )
195
- exit (WEXITSTATUS (ret ));
196
- die ("Failed to run '%s' when expanding alias '%s'" ,
197
- alias_string + 1 , alias_command );
184
+
185
+ /* build alias_argv */
186
+ alias_argv = xmalloc (sizeof (* alias_argv ) * (argc + 1 ));
187
+ alias_argv [0 ] = alias_string + 1 ;
188
+ for (i = 1 ; i < argc ; ++ i )
189
+ alias_argv [i ] = (* argv )[i ];
190
+ alias_argv [argc ] = NULL ;
191
+
192
+ ret = run_command_v_opt (alias_argv , RUN_USING_SHELL );
193
+ if (ret >= 0 ) /* normal exit */
194
+ exit (ret );
195
+
196
+ die_errno ("While expanding alias '%s': '%s'" ,
197
+ alias_command , alias_string + 1 );
198
198
}
199
199
count = split_cmdline (alias_string , & new_argv );
200
200
if (count < 0 )
0 commit comments