]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Rcs/bazaar.pm
commit only the changed file
[ikiwiki.git] / IkiWiki / Rcs / bazaar.pm
index 21821586be011453383d583813dfd52bee2b5e5b..528767099dfe6c39a7e2f86a4598a04a4b64730b 100644 (file)
@@ -8,54 +8,42 @@ use open qw{:utf8 :std};
 
 package IkiWiki;
 
-sub bazaar_log($) {
+sub bazaar_log ($) { #{{{
        my $out = shift;
-       my @infos;
+       my @infos = ();
+       my $key = undef;
 
        while (<$out>) {
                my $line = $_;
-               my ($key, $value);
-
-               if (/^description:/) {
-                       $key = "description";
-                       $value = "";
-
-                       # slurp everything as the description text 
-                       # until the next changeset
-                       while (<$out>) {
-                               if (/^changeset: /) {
-                                       $line = $_;
-                                       last;
-                               }
-
-                               $value .= $_;
-                       }
-
-                       local $/ = "";
-                       chomp $value;
-                       $infos[$#infos]{$key} = $value;
+               my ($value);
+               if ($line =~ /^message:/) {
+                       $key = "message";
+                       $infos[$#infos]{$key} = "";
                }
-
-               chomp $line;
-               ($key, $value) = split /: +/, $line, 2;
-
-               if ($key eq "changeset") {
-                       push @infos, {};
-
-                       # remove the revision index, which is strictly 
-                       # local to the repository
-                       $value =~ s/^\d+://;
+               elsif ($line =~ /^(modified|added|renamed|renamed and modified|removed):/) {
+                       $key = "files";
+                       unless (defined($infos[$#infos]{$key})) { $infos[$#infos]{$key} = ""; }
                }
-
-               $infos[$#infos]{$key} = $value;
+               elsif (defined($key) and $line =~ /^  (.*)/) {
+                       $infos[$#infos]{$key} .= $1;
+               }
+               elsif ($line eq "------------------------------------------------------------\n") {
+                       $key = undef;
+                       push (@infos, {});
+               }
+               else {
+                       chomp $line;
+                               ($key, $value) = split /: +/, $line, 2;
+                       $infos[$#infos]{$key} = $value;
+               } 
        }
        close $out;
 
        return @infos;
-}
+} #}}}
 
 sub rcs_update () { #{{{
-       my @cmdline = ("bzr", "$config{srcdir}", "update");
+       my @cmdline = ("bzr", $config{srcdir}, "update");
        if (system(@cmdline) != 0) {
                warn "'@cmdline' failed: $!";
        }
@@ -83,8 +71,8 @@ sub rcs_commit ($$$;$$) { #{{{
                $message = "no message given";
        }
 
-       my @cmdline = ("bzr", "commit", 
-                      "-m", $message, "--author", $user, $config{srcdir});
+       my @cmdline = ("bzr", "commit", "-m", $message, "--author", $user,
+                      $config{srcdir}."/".$file);
        if (system(@cmdline) != 0) {
                warn "'@cmdline' failed: $!";
        }
@@ -118,14 +106,14 @@ sub rcs_recentchanges ($) { #{{{
                my @pages = ();
                my @message = ();
         
-               foreach my $msgline (split(/\n/, $info->{description})) {
+               foreach my $msgline (split(/\n/, $info->{message})) {
                        push @message, { line => $msgline };
                }
 
-               foreach my $file (split / /,$info->{files}) {
+               foreach my $file (split(/\n/, $info->{files})) {
                        my $diffurl = $config{'diffurl'};
                        $diffurl =~ s/\[\[file\]\]/$file/go;
-                       $diffurl =~ s/\[\[r2\]\]/$info->{changeset}/go;
+                       $diffurl =~ s/\[\[r2\]\]/$info->{revno}/go;
 
                        push @pages, {
                                page => pagename($file),
@@ -133,15 +121,16 @@ sub rcs_recentchanges ($) { #{{{
                        };
                }
 
-               my $user = $info->{"user"};
+               my $user = $info->{"committer"};
+               if (defined($info->{"author"})) { $user = $info->{"author"}; }
                $user =~ s/\s*<.*>\s*$//;
                $user =~ s/^\s*//;
 
                push @ret, {
-                       rev        => $info->{"changeset"},
+                       rev        => $info->{"revno"},
                        user       => $user,
                        committype => "bazaar",
-                       when       => time - str2time($info->{"date"}),
+                       when       => time - str2time($info->{"timestamp"}),
                        message    => [@message],
                        pages      => [@pages],
                };
@@ -150,16 +139,12 @@ sub rcs_recentchanges ($) { #{{{
        return @ret;
 } #}}}
 
-sub rcs_notify () { #{{{
-       # TODO
-} #}}}
-
 sub rcs_getctime ($) { #{{{
        my ($file) = @_;
 
        # XXX filename passes through the shell here, should try to avoid
        # that just in case
-       my @cmdline = ("bzr", "log", "-v", "--limit", '1', "$config{srcdir}/$file");
+       my @cmdline = ("bzr", "log", "--limit", '1', "$config{srcdir}/$file");
        open (my $out, "@cmdline |");
 
        my @log = bazaar_log($out);
@@ -171,7 +156,7 @@ sub rcs_getctime ($) { #{{{
        eval q{use Date::Parse};
        error($@) if $@;
        
-       my $ctime = str2time($log[0]->{"date"});
+       my $ctime = str2time($log[0]->{"timestamp"});
        return $ctime;
 } #}}}