Skip to content

Commit

Permalink
scripts: add partial update functionality to configuration upgrade sc…
Browse files Browse the repository at this point in the history
…ript

This matches the way this has been handled in the past.  This could
also help devices which were skipped due to abandoned plans to drop.

Signed-off-by: Elliott Mitchell <ehem+openwrt@m5p.com>
  • Loading branch information
ehem committed Apr 3, 2024
1 parent cd467e8 commit 9326020
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions scripts/kernel_upgrade.pl
Expand Up @@ -37,21 +37,36 @@ ()
return $_;
}

sub getlistmatch($$$)
sub getlistmatch($$@)
{
my ($commit, $from, $target)=@_;
my ($commit, $from, @target)=@_;
my $ret=[];

local $/="\0";
open(my $fd, '-| :raw :bytes', 'git', 'ls-tree', '-trz', '--full-tree',
'--name-only', $commit.':', '--', $target)||die("failed to read git tree");
'--name-only', $commit.':', '--', @target)||die("failed to read git tree");

while(<$fd>) {
chop($_);
push(@$ret, substr($_, 0, -length($from)))
if(index($_, $from, length($_)-length($from))>0);
}

check: foreach my $entr (@target) {
my ($lo, $hi)=(0, scalar(@$ret));
while($lo!=$hi) {
$_=substr($ret->[($lo+$hi)>>1], 0, length($entr)) cmp $entr;
if($_<0) {
$lo=(($lo+$hi)>>1)+1;
} elsif($_>0) {
$hi=($lo+$hi)>>1;
} else {
next check;
}
}
die("no files matching \"$from\" found in $entr");
}

@$ret=sort({length($b)-length($a)} @$ret);

return $ret;
Expand Down Expand Up @@ -211,8 +226,8 @@ ()
} # end of interface to git fast-import


die(<<"__USAGE__") if(@ARGV!=2);
Usage: $0 <old-version> <new-version>
die(<<"__USAGE__") if(@ARGV<2);
Usage: $0 <old-version> <new-version> [<board(s)...>]
Copies all kernel configuration files and patches from the old version
to the new version. Git history is preserved on the copies by using a
Expand All @@ -227,6 +242,12 @@ ()
Note, the two strings are non-optional, but completely free-form.
There are no limitations besides whether they can be used in a
file-name (\\0 is the only invalid character).
One or more boards can be specified to update a subset of boards. This
can include "generic", this can also include a subdirectory for a device.
The end merge commit /can/ be amended to remove files which should not
be included during an update.
__USAGE__

my $from=shift(@ARGV);
Expand All @@ -240,9 +261,13 @@ ()
die('git failed, likely not inside OpenWRT git repository?') unless($start||
($0=~m/^(.*)\// and chdir($1) and $start=gethead()));

my $list=getlistmatch('HEAD', $from, $target);

die("no files matching \"$from\" found") unless(@$list);
my $list;
unless(@ARGV) {
$list=getlistmatch('HEAD', $from, $target);
} else {
$_=$target.$_ foreach(@ARGV);
$list=getlistmatch('HEAD', $from, @ARGV);
}


my $git=GitImporter->new();
Expand Down

0 comments on commit 9326020

Please sign in to comment.