chiark / gitweb /
git-debrebase: WIP before reorgs?
[dgit.git] / git-debrebase
1 #!/usr/bin/perl -w
2 # git-debrebase
3 # Script helping make fast-forwarding histories while still rebasing
4 # upstream deltas when working on Debian packaging
5 #
6 # Copyright (C)2017 Ian Jackson
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 use strict;
22 use Memoize;
23
24 use Debian::Dgit;
25
26 sub cfg ($) {
27     my ($k) = @_;
28     $/ = "\0";
29     my @cmd = qw(git config -z);
30     push @cmd, qw(--get-all) if wantarray;
31     push @cmd, $k;
32     my $out = cmdoutput @cmd;
33     return split /\0/, $out;
34 }
35
36 memoize('cfg');
37
38 # usage
39 #  git debrebase launder
40
41 sub get_commit ($) {
42     my ($objid) = @_;
43     my ($type,$data) = git_cat_file $objid;
44     die unless $type eq 'commit';
45     $data =~ m/(?<=\n)\n/;
46     return ($`,$');
47 }
48
49 memoize('get_commit');
50
51 sub DDEB () { return 0x1; }
52 sub DUPS () { return 0x2; }
53 sub DPAT () { return 0x4; }
54
55 sub launder () {
56     # go through commits backwards
57     # we generate two lists of commits to apply
58     my (@deb_cl, @ups_cl);
59     my $cur = git_rev_parse('HEAD');
60     for (;;) {
61         my ($h,$m) = get_commit $cur;
62         my ($t) = $h =~ m/^tree (\w+)$/m;  defined $t or die $cur;
63         my (@p) = $h =~ m/^parent (\w+)$/m;
64         my (@d) = map { get_differs $t, $_ } @p;
65         if (@p == 1) {
66             my ($d) = $d[0];
67             if ($d == DPAT) {
68                 # changes on debian/patches, discard it
69                 $cur = $p[0];
70                 next;
71             }
72             if ($d & DPAT) {
73             
74 }   
75
76 if ($ARGV[0] eq 'launder') {
77     launder();
78 }
79
80 use Data::Dumper;
81 print Dumper(cfg('wombat.foo.bar'));
82