summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@gmx.de>2022-01-20 19:17:17 +0100
committerOswald Buddenhagen <oswald.buddenhagen@gmx.de>2022-01-21 15:04:25 +0000
commit3317d635ff9c968cff095e9b882da2b323f9a6c6 (patch)
tree7d7dfc8e701009b6ecde2b965a7e731c543ff7b8
parent5c862e8557c05b8ff6560bd47b982b7841c7fd0c (diff)
downloadqtrepotools-3317d635ff9c968cff095e9b882da2b323f9a6c6.tar.gz
gpick: fix --move/--copy/--hide with no local commits
_source_map_prepare() was never called when no local commits are present, as analyze_local_branch() exits early in this case. unfortunately, this skipped the preparation of remote ids and 'new' as well. fix by factoring out source_map_validate() and calling it right after the local branch was determined. i opted against calling it at the top of analyze_local_branch(), as it seemed too cryptic, so instead gpick & gpush have their own calls. Change-Id: Ib8ec9997a127b2e639532b700e0f5f67de1bcdd9 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rwxr-xr-xbin/git-gpick1
-rwxr-xr-xbin/git-gpush1
-rw-r--r--bin/git_gpush.pm64
3 files changed, 38 insertions, 28 deletions
diff --git a/bin/git-gpick b/bin/git-gpick
index b964820..9f66565 100755
--- a/bin/git-gpick
+++ b/bin/git-gpick
@@ -367,6 +367,7 @@ sub determine_local_branch()
setup_remotes($local_branch // 'HEAD');
set_gerrit_config($remote);
+ source_map_validate();
}
# Get the list of local commits (which can be replaced).
diff --git a/bin/git-gpush b/bin/git-gpush
index 8fd7d67..667011c 100755
--- a/bin/git-gpush
+++ b/bin/git-gpush
@@ -711,6 +711,7 @@ sub determine_local_branch($)
}
setup_remotes($source);
set_gerrit_config($remote);
+ source_map_validate();
}
# Determine the target branch for the given series.
diff --git a/bin/git_gpush.pm b/bin/git_gpush.pm
index 9a8ff9b..bc0d708 100644
--- a/bin/git_gpush.pm
+++ b/bin/git_gpush.pm
@@ -1226,7 +1226,8 @@ our $local_tip;
# Mapping of Change-Ids to commits on the local branch.
our %changeid2local; # { change-id => SHA1 }
-sub _source_map_prepare();
+sub source_map_validate();
+sub _source_map_prepare_local();
sub source_map_assign($$);
sub source_map_traverse();
sub _source_map_finish_initial();
@@ -1267,11 +1268,11 @@ sub analyze_local_branch($)
$local_base = $$commits[0]{parents}[0];
# This needs to happen early, for parse_local_rev(), which
- # _source_map_prepare() calls.
+ # _source_map_prepare_local() calls.
$changeid2local{$$_{changeid}} = $$_{id} foreach (@$commits);
# ... then map them to Change objects ...
- _source_map_prepare();
+ _source_map_prepare_local();
while (1) {
foreach my $commit (@$commits) {
source_map_assign($commit, undef);
@@ -1731,10 +1732,8 @@ sub parse_source_option($$\@)
return 1;
}
-# Do final sanity checking on the source branch tracking related commands,
-# expand the supplied ranges into series of commits, and create a reverse
-# mapping of commits to command objects.
-sub _source_map_prepare()
+# Do final sanity checking on the source branch tracking related commands.
+sub source_map_validate()
{
my $br = $local_branch // "-";
foreach my $option (@sm_options) {
@@ -1749,27 +1748,7 @@ sub _source_map_prepare()
}
my $raw_tip = $$option{tip};
- if (defined($raw_tip)) {
- my $commits;
- my $tip = parse_local_rev($raw_tip, SPEC_TIP);
- my $raw_base = $$option{base};
- if (defined($raw_base)) {
- my $base = parse_local_rev($raw_base, SPEC_BASE);
- $commits = get_commits_base($base, $tip, $raw_base, $raw_tip);
- } else {
- my $count = $$option{count};
- $commits = get_commits_count($tip, $count, $raw_tip);
- }
- foreach my $commit (@$commits) {
- my $sha1 = $$commit{id};
- my $old_option = $sm_option_by_id{$sha1};
- wfail("Range $$option{orig} intersects $$old_option{orig} (at $sha1).\n")
- if ($old_option);
- $sm_option_by_id{$sha1} = $option;
- }
- $$option{commits} = $commits;
- next;
- }
+ next if (defined($raw_tip));
wfail("Only one of --move, --copy, and --hide may be specified with 'new'.\n")
if (defined($sm_option_new));
@@ -1777,6 +1756,35 @@ sub _source_map_prepare()
}
}
+# Expand the supplied ranges into series of commits, and create a reverse
+# mapping of commits to command objects.
+sub _source_map_prepare_local()
+{
+ foreach my $option (@sm_options) {
+ my $raw_tip = $$option{tip};
+ next if (!defined($raw_tip));
+
+ my $commits;
+ my $tip = parse_local_rev($raw_tip, SPEC_TIP);
+ my $raw_base = $$option{base};
+ if (defined($raw_base)) {
+ my $base = parse_local_rev($raw_base, SPEC_BASE);
+ $commits = get_commits_base($base, $tip, $raw_base, $raw_tip);
+ } else {
+ my $count = $$option{count};
+ $commits = get_commits_count($tip, $count, $raw_tip);
+ }
+ foreach my $commit (@$commits) {
+ my $sha1 = $$commit{id};
+ my $old_option = $sm_option_by_id{$sha1};
+ wfail("Range $$option{orig} intersects $$old_option{orig} (at $sha1).\n")
+ if ($old_option);
+ $sm_option_by_id{$sha1} = $option;
+ }
+ $$option{commits} = $commits;
+ }
+}
+
# Schedule the removal a single Change object from the state database.
sub _obliterate_change($$)
{