#!/usr/bin/perl -w # git-debrebase # Script helping make fast-forwarding histories while still rebasing # upstream deltas when working on Debian packaging # # Copyright (C)2017 Ian Jackson # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . use strict; use Memoize; use Debian::Dgit; sub cfg ($) { my ($k) = @_; $/ = "\0"; my @cmd = qw(git config -z); push @cmd, qw(--get-all) if wantarray; push @cmd, $k; my $out = cmdoutput @cmd; return split /\0/, $out; } memoize('cfg'); # usage # git debrebase launder sub get_commit ($) { my ($objid) = @_; my ($type,$data) = git_cat_file $objid; die unless $type eq 'commit'; $data =~ m/(?<=\n)\n/; return ($`,$'); } memoize('get_commit'); sub DDEB () { return 0x1; } sub DUPS () { return 0x2; } sub DPAT () { return 0x4; } sub launder () { # go through commits backwards # we generate two lists of commits to apply my (@deb_cl, @ups_cl); my $cur = git_rev_parse('HEAD'); for (;;) { my ($h,$m) = get_commit $cur; my ($t) = $h =~ m/^tree (\w+)$/m; defined $t or die $cur; my (@p) = $h =~ m/^parent (\w+)$/m; my (@d) = map { get_differs $t, $_ } @p; if (@p == 1) { my ($d) = $d[0]; if ($d == DPAT) { # changes on debian/patches, discard it $cur = $p[0]; next; } if ($d & DPAT) { } if ($ARGV[0] eq 'launder') { launder(); } use Data::Dumper; print Dumper(cfg('wombat.foo.bar'));