Add a patch tag
[ikiwiki.git] / doc / bugs / bzr_2.0_breaks_bzr_plugin.mdwn
1 Version 2.0 of bzr seems to break the bzr plugin.
2
3 I traced this to the bzr_log method in the plugin, and patching that seems to fix it. The plugin just needs to parse the input little bit differently.
4 --liw
5
6 > Patch applied, [[done]] (but, it would be good if it could be tested with
7 > an older bzr, and it's a pity bzr's human-targeted log has to be parsed,
8 > I assume there is no machine-targeted version?) --[[Joey]] 
9
10     From fb897114124e627fd3acf5af8e784c9a77419a81 Mon Sep 17 00:00:00 2001
11     From: Lars Wirzenius <liw@liw.fi>
12     Date: Sun, 4 Apr 2010 21:05:07 +1200
13     Subject: [PATCH] Fix bzr plugin to work with bzr 2.0.
14
15     The output of "bzr log" seems to have changed a bit, so we change the
16     parsing accordingly. This has not been tested with earlier versions of
17     bzr.
18
19     Several problems seemed to occur, all in the bzr_log subroutine:
20
21     1. The @infos list would contain an empty hash, which would confuse the
22        rest of the program.
23     2. This was because bzr_log would push an empty anonymous hash to the
24        list whenever it thought a new record would start.
25     3. However, a new record marker (now?) also happens at th end of bzr log
26        output.
27     4. Now we collect the record to a hash that gets pushed to the list only
28        if it is not empty.
29     5. Also, sometimes bzr log outputs "revno: 1234 [merge]", so we catch only
30        the revision number.
31     6. Finally, there may be non-headers at the of the output, so we ignore
32        those.
33     ---
34      IkiWiki/Plugin/bzr.pm |   23 ++++++++++++++++-------
35      1 files changed, 16 insertions(+), 7 deletions(-)
36
37     diff --git a/IkiWiki/Plugin/bzr.pm b/IkiWiki/Plugin/bzr.pm
38     index 1ffdc23..e813331 100644
39     --- a/IkiWiki/Plugin/bzr.pm
40     +++ b/IkiWiki/Plugin/bzr.pm
41     @@ -73,28 +73,37 @@ sub bzr_log ($) {
42         my @infos = ();
43         my $key = undef;
44      
45     +    my $hash = {};
46         while (<$out>) {
47                 my $line = $_;
48                 my ($value);
49                 if ($line =~ /^message:/) {
50                         $key = "message";
51     -                   $infos[$#infos]{$key} = "";
52     +                   $$hash{$key} = "";
53                 }
54                 elsif ($line =~ /^(modified|added|renamed|renamed and modified|removed):/) {
55                         $key = "files";
56     -                   unless (defined($infos[$#infos]{$key})) { $infos[$#infos]{$key} = ""; }
57     +                   unless (defined($$hash{$key})) { $$hash{$key} = ""; }
58                 }
59                 elsif (defined($key) and $line =~ /^  (.*)/) {
60     -                   $infos[$#infos]{$key} .= "$1\n";
61     +                   $$hash{$key} .= "$1\n";
62                 }
63                 elsif ($line eq "------------------------------------------------------------\n") {
64     +               if (keys %$hash) {
65     +                       push (@infos, $hash);
66     +               }
67     +                   $hash = {};
68                         $key = undef;
69     -                   push (@infos, {});
70                 }
71     -           else {
72     +           elsif ($line =~ /: /) {
73                         chomp $line;
74     -                           ($key, $value) = split /: +/, $line, 2;
75     -                   $infos[$#infos]{$key} = $value;
76     +                   if ($line =~ /^revno: (\d+)/) {
77     +                       $key = "revno";
78     +                       $value = $1;
79     +                   } else {
80     +                           ($key, $value) = split /: +/, $line, 2;
81     +                   }
82     +                   $$hash{$key} = $value;
83                 } 
84         }
85         close $out;
86     -- 
87     1.7.0