[PATCH v3 0/2] remote: show progress display when renaming
From: Taylor Blau <hidden>
Date: 2022-03-03 22:25:18
Here is a reroll of the patch we've been discussing to add progress
output when renaming remote-tracking references (as part of a `git
remote rename <old> <new>`).
This single patch is now two (and hence, has a cover letter!) because of
a slight change in approach which amounts to changing this behavior from
an opt-in
git remote -v rename <old> <new>
to something much more in line with our existing use of the
`--[no-]progress` option like:
git remote rename [--[no-]progress] <old> <new>
(where `--progress` is the default exactly when `isatty(2)` is true).
I think similar treatment could be applied to other `git remote`
sub-commands, but I'm reasonably happy starting with just `git remote
rename` and looking at the others later.
Taylor Blau (2):
builtin/remote.c: parse options in 'rename'
builtin/remote.c: show progress when renaming remote references
Documentation/git-remote.txt | 2 +-
builtin/remote.c | 39 ++++++++++++++++++++++++++++--------
t/t5505-remote.sh | 4 +++-
3 files changed, 35 insertions(+), 10 deletions(-)
Range-diff against v2:
-: ---------- > 1: b76da50b54 builtin/remote.c: parse options in 'rename'
1: dc63ec91ab ! 2: d5b0a4b710 builtin/remote.c: show progress when renaming remote references
@@ Documentation/git-remote.txt: SYNOPSIS
'git remote' [-v | --verbose]
'git remote add' [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <name> <URL>
-'git remote rename' <old> <new>
-+'git remote' [-v | --verbose] 'rename' <old> <new>
++'git remote rename' [--[no-]progress] <old> <new>
'git remote remove' <name>
'git remote set-head' <name> (-a | --auto | -d | --delete | <branch>)
'git remote set-branches' [--add] <name> <branch>...
@@ builtin/remote.c
"git remote [-v | --verbose]",
N_("git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>"),
- N_("git remote rename <old> <new>"),
-+ N_("git remote [-v | --verbose] rename <old> <new>"),
++ N_("git remote rename [--[no-]progress] <old> <new>"),
N_("git remote remove <name>"),
N_("git remote set-head <name> (-a | --auto | -d | --delete | <branch>)"),
N_("git remote [-v | --verbose] show [-n] <name>"),
+@@ builtin/remote.c: static const char * const builtin_remote_add_usage[] = {
+ };
+
+ static const char * const builtin_remote_rename_usage[] = {
+- N_("git remote rename <old> <new>"),
++ N_("git remote rename [--[no-]progress] <old> <new>"),
+ NULL
+ };
+
@@ builtin/remote.c: struct rename_info {
const char *old_name;
const char *new_name;
@@ builtin/remote.c: static int read_remote_branches(const char *refname,
}
strbuf_release(&buf);
+@@ builtin/remote.c: static void handle_push_default(const char* old_name, const char* new_name)
+
+ static int mv(int argc, const char **argv)
+ {
++ int show_progress = isatty(2);
+ struct option options[] = {
++ OPT_BOOL(0, "progress", &show_progress, N_("force progress reporting")),
+ OPT_END()
+ };
+ struct remote *oldremote, *newremote;
@@ builtin/remote.c: static int mv(int argc, const char **argv)
old_remote_context = STRBUF_INIT;
struct string_list remote_branches = STRING_LIST_INIT_DUP;
@@ builtin/remote.c: static int mv(int argc, const char **argv)
+ int i, refs_renamed_nr = 0, refspec_updated = 0;
+ struct progress *progress = NULL;
- if (argc != 3)
- usage_with_options(builtin_remote_rename_usage, options);
+ argc = parse_options(argc, argv, NULL, options,
+ builtin_remote_rename_usage, 0);
@@ builtin/remote.c: static int mv(int argc, const char **argv)
- rename.old_name = argv[1];
- rename.new_name = argv[2];
+ rename.old_name = argv[0];
+ rename.new_name = argv[1];
rename.remote_branches = &remote_branches;
+ rename.symrefs_nr = 0;
@@ builtin/remote.c: static int mv(int argc, const char **argv)
* the new symrefs.
*/
for_each_ref(read_remote_branches, &rename);
-+ if (verbose) {
++ if (show_progress) {
+ /*
+ * Count symrefs twice, since "renaming" them is done by
+ * deleting and recreating them in two separate passes.
@@ t/t5505-remote.sh: test_expect_success 'rename a remote' '
cd four &&
git config branch.main.pushRemote origin &&
- git remote rename origin upstream &&
-+ GIT_PROGRESS_DELAY=0 git remote -v rename origin upstream 2>err &&
++ GIT_TRACE2_EVENT=$(pwd)/trace \
++ git remote rename --progress origin upstream &&
++ test_region progress "Renaming remote references" trace &&
grep "pushRemote" .git/config &&
-+ grep "Renaming remote references: 100% (4/4), done" err &&
test -z "$(git for-each-ref refs/remotes/origin)" &&
test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
- test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
--
2.35.1.73.gccc5557600