12
12
#include "object-store.h"
13
13
#include "strvec.h"
14
14
#include "commit-reach.h"
15
+ #include "progress.h"
15
16
16
17
static const char * const builtin_remote_usage [] = {
17
18
"git remote [-v | --verbose]" ,
18
19
N_ ("git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>" ),
19
- N_ ("git remote rename <old> <new>" ),
20
+ N_ ("git remote rename [--[no-]progress] <old> <new>" ),
20
21
N_ ("git remote remove <name>" ),
21
22
N_ ("git remote set-head <name> (-a | --auto | -d | --delete | <branch>)" ),
22
23
N_ ("git remote [-v | --verbose] show [-n] <name>" ),
@@ -36,7 +37,7 @@ static const char * const builtin_remote_add_usage[] = {
36
37
};
37
38
38
39
static const char * const builtin_remote_rename_usage [] = {
39
- N_ ("git remote rename <old> <new>" ),
40
+ N_ ("git remote rename [--[no-]progress] <old> <new>" ),
40
41
NULL
41
42
};
42
43
@@ -571,6 +572,7 @@ struct rename_info {
571
572
const char * old_name ;
572
573
const char * new_name ;
573
574
struct string_list * remote_branches ;
575
+ uint32_t symrefs_nr ;
574
576
};
575
577
576
578
static int read_remote_branches (const char * refname ,
@@ -587,10 +589,12 @@ static int read_remote_branches(const char *refname,
587
589
item = string_list_append (rename -> remote_branches , refname );
588
590
symref = resolve_ref_unsafe (refname , RESOLVE_REF_READING ,
589
591
NULL , & flag );
590
- if (symref && (flag & REF_ISSYMREF ))
592
+ if (symref && (flag & REF_ISSYMREF )) {
591
593
item -> util = xstrdup (symref );
592
- else
594
+ rename -> symrefs_nr ++ ;
595
+ } else {
593
596
item -> util = NULL ;
597
+ }
594
598
}
595
599
strbuf_release (& buf );
596
600
@@ -674,22 +678,29 @@ static void handle_push_default(const char* old_name, const char* new_name)
674
678
675
679
static int mv (int argc , const char * * argv )
676
680
{
681
+ int show_progress = isatty (2 );
677
682
struct option options [] = {
683
+ OPT_BOOL (0 , "progress" , & show_progress , N_ ("force progress reporting" )),
678
684
OPT_END ()
679
685
};
680
686
struct remote * oldremote , * newremote ;
681
687
struct strbuf buf = STRBUF_INIT , buf2 = STRBUF_INIT , buf3 = STRBUF_INIT ,
682
688
old_remote_context = STRBUF_INIT ;
683
689
struct string_list remote_branches = STRING_LIST_INIT_DUP ;
684
690
struct rename_info rename ;
685
- int i , refspec_updated = 0 ;
691
+ int i , refs_renamed_nr = 0 , refspec_updated = 0 ;
692
+ struct progress * progress = NULL ;
693
+
694
+ argc = parse_options (argc , argv , NULL , options ,
695
+ builtin_remote_rename_usage , 0 );
686
696
687
- if (argc != 3 )
697
+ if (argc != 2 )
688
698
usage_with_options (builtin_remote_rename_usage , options );
689
699
690
- rename .old_name = argv [1 ];
691
- rename .new_name = argv [2 ];
700
+ rename .old_name = argv [0 ];
701
+ rename .new_name = argv [1 ];
692
702
rename .remote_branches = & remote_branches ;
703
+ rename .symrefs_nr = 0 ;
693
704
694
705
oldremote = remote_get (rename .old_name );
695
706
if (!remote_is_configured (oldremote , 1 )) {
@@ -764,6 +775,14 @@ static int mv(int argc, const char **argv)
764
775
* the new symrefs.
765
776
*/
766
777
for_each_ref (read_remote_branches , & rename );
778
+ if (show_progress ) {
779
+ /*
780
+ * Count symrefs twice, since "renaming" them is done by
781
+ * deleting and recreating them in two separate passes.
782
+ */
783
+ progress = start_progress (_ ("Renaming remote references" ),
784
+ rename .remote_branches -> nr + rename .symrefs_nr );
785
+ }
767
786
for (i = 0 ; i < remote_branches .nr ; i ++ ) {
768
787
struct string_list_item * item = remote_branches .items + i ;
769
788
struct strbuf referent = STRBUF_INIT ;
@@ -775,6 +794,7 @@ static int mv(int argc, const char **argv)
775
794
die (_ ("deleting '%s' failed" ), item -> string );
776
795
777
796
strbuf_release (& referent );
797
+ display_progress (progress , ++ refs_renamed_nr );
778
798
}
779
799
for (i = 0 ; i < remote_branches .nr ; i ++ ) {
780
800
struct string_list_item * item = remote_branches .items + i ;
@@ -790,6 +810,7 @@ static int mv(int argc, const char **argv)
790
810
item -> string , buf .buf );
791
811
if (rename_ref (item -> string , buf .buf , buf2 .buf ))
792
812
die (_ ("renaming '%s' failed" ), item -> string );
813
+ display_progress (progress , ++ refs_renamed_nr );
793
814
}
794
815
for (i = 0 ; i < remote_branches .nr ; i ++ ) {
795
816
struct string_list_item * item = remote_branches .items + i ;
@@ -809,7 +830,9 @@ static int mv(int argc, const char **argv)
809
830
item -> string , buf .buf );
810
831
if (create_symref (buf .buf , buf2 .buf , buf3 .buf ))
811
832
die (_ ("creating '%s' failed" ), buf .buf );
833
+ display_progress (progress , ++ refs_renamed_nr );
812
834
}
835
+ stop_progress (& progress );
813
836
string_list_clear (& remote_branches , 1 );
814
837
815
838
handle_push_default (rename .old_name , rename .new_name );
0 commit comments