@@ -14,7 +14,7 @@ static const char fetch_usage[] = "git-fetch [-a | --append] [--upload-pack <upl
1414
1515static int append , force , tags , no_tags , update_head_ok , verbose , quiet ;
1616static const char * depth ;
17- static char * default_rla = NULL ;
17+ static struct strbuf default_rla = STRBUF_INIT ;
1818static struct transport * transport ;
1919
2020static void unlock_pack (void )
@@ -142,7 +142,7 @@ static int s_update_ref(const char *action,
142142 static struct ref_lock * lock ;
143143
144144 if (!rla )
145- rla = default_rla ;
145+ rla = default_rla . buf ;
146146 snprintf (msg , sizeof (msg ), "%s: %s" , rla , action );
147147 lock = lock_any_ref_for_update (ref -> name ,
148148 check_old ? ref -> old_sha1 : NULL , 0 );
@@ -543,16 +543,19 @@ static void set_option(const char *name, const char *value)
543543int cmd_fetch (int argc , const char * * argv , const char * prefix )
544544{
545545 struct remote * remote ;
546- int i , j , rla_offset ;
546+ int i ;
547547 static const char * * refs = NULL ;
548548 int ref_nr = 0 ;
549- int cmd_len = 0 ;
550549 const char * upload_pack = NULL ;
551550 int keep = 0 ;
552551
552+ /* Record the command line for the reflog */
553+ strbuf_addstr (& default_rla , "fetch" );
554+ for (i = 1 ; i < argc ; i ++ )
555+ strbuf_addf (& default_rla , " %s" , argv [i ]);
556+
553557 for (i = 1 ; i < argc ; i ++ ) {
554558 const char * arg = argv [i ];
555- cmd_len += strlen (arg );
556559
557560 if (arg [0 ] != '-' )
558561 break ;
@@ -613,17 +616,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
613616 usage (fetch_usage );
614617 }
615618
616- for (j = i ; j < argc ; j ++ )
617- cmd_len += strlen (argv [j ]);
618-
619- default_rla = xmalloc (cmd_len + 5 + argc + 1 );
620- sprintf (default_rla , "fetch" );
621- rla_offset = strlen (default_rla );
622- for (j = 1 ; j < argc ; j ++ ) {
623- sprintf (default_rla + rla_offset , " %s" , argv [j ]);
624- rla_offset += strlen (argv [j ]) + 1 ;
625- }
626-
627619 if (i == argc )
628620 remote = remote_get (NULL );
629621 else
0 commit comments