]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Rcs/monotone.pm
a few thoughts on data: security
[ikiwiki.git] / IkiWiki / Rcs / monotone.pm
index be6b36c66e4816f67875d51caba86f49f3582bd3..c4a6d98644c5be7bac2ee606dea2a3e7cc5ba505 100644 (file)
@@ -239,14 +239,11 @@ sub rcs_commit ($$$;$$) { #{{{
 
                # Something has been committed, has this file changed?
                my ($out, $err);
-               #$automator->setOpts("-r", $oldrev, "-r", $rev);
-               #my ($out, $err) = $automator->call("content_diff", $file);
-               #debug("Problem committing $file") if ($err ne "");
-               # FIXME: use of $file in these backticks is not wise from a
-               # security POV. Probably safe, but should be avoided
-               # anyway.
-               my $diff = `mtn --root=$config{mtnrootdir} au content_diff -r $oldrev -r $rev $file`; # was just $out;
-
+               $automator->setOpts("r", $oldrev, "r", $rev);
+               ($out, $err) = $automator->call("content_diff", $file);
+               debug("Problem committing $file") if ($err ne "");
+               my $diff = $out;
+               
                if ($diff) {
                        # Commit a revision with just this file changed off
                        # the old revision.
@@ -314,8 +311,6 @@ sub rcs_commit ($$$;$$) { #{{{
                                                "Please use the non-web interface to resolve the conflicts.");
                                }
                                
-                               # suspend this revision because it has
-                               # conflict markers...
                                if (system("mtn", "--root=$config{mtnrootdir}",
                                           "update", "-r", $mergeResult) != 0) {
                                        debug("Unable to update to rev $mergeResult after conflict-enhanced merge on conflicted commit!");
@@ -347,10 +342,10 @@ sub rcs_commit ($$$;$$) { #{{{
                return $conflict;
        }
        if (defined($config{mtnsync}) && $config{mtnsync}) {
-               if (system("mtn", "--root=$config{mtnrootdir}", "sync",
+               if (system("mtn", "--root=$config{mtnrootdir}", "push",
                           "--quiet", "--ticker=none", "--key",
                           $config{mtnkey}) != 0) {
-                       debug("monotone sync failed");
+                       debug("monotone push failed");
                }
        }
 
@@ -363,7 +358,7 @@ sub rcs_add ($) { #{{{
        check_config();
 
        if (system("mtn", "--root=$config{mtnrootdir}", "add", "--quiet",
-                  "$config{srcdir}/$file") != 0) {
+                  $file) != 0) {
                error("Monotone add failed");
        }
 } #}}}
@@ -421,7 +416,7 @@ sub rcs_recentchanges ($) { #{{{
                                                $committype = "monotone";
                                        }
                                } elsif ($cert->{name} eq "date") {
-                                       $when = time - str2time($cert->{value}, 'UTC');
+                                       $when = str2time($cert->{value}, 'UTC');
                                } elsif ($cert->{name} eq "changelog") {
                                        my $messageText = $cert->{value};
                                        # split the changelog into multiple
@@ -436,10 +431,28 @@ sub rcs_recentchanges ($) { #{{{
                my @changed_files = get_changed_files($automator, $rev);
                my $file;
                
+               my ($out, $err) = $automator->call("parents", $rev);
+               my @parents = ($out =~ m/^($sha1_pattern)$/);
+               my $parent = $parents[0];
+
                foreach $file (@changed_files) {
-                       push @pages, {
-                               page => pagename($file),
-                       } if length $file;
+                       next unless length $file;
+                       
+                       if (defined $config{diffurl} and (@parents == 1)) {
+                               my $diffurl=$config{diffurl};
+                               $diffurl=~s/\[\[r1\]\]/$parent/g;
+                               $diffurl=~s/\[\[r2\]\]/$rev/g;
+                               $diffurl=~s/\[\[file\]\]/$file/g;
+                               push @pages, {
+                                       page => pagename($file),
+                                       diffurl => $diffurl,
+                               };
+                       }
+                       else {
+                               push @pages, {
+                                       page => pagename($file),
+                               }
+                       }
                }
                
                push @ret, {
@@ -457,54 +470,6 @@ sub rcs_recentchanges ($) { #{{{
        return @ret;
 } #}}}
 
-sub rcs_notify () { #{{{
-       debug("The monotone rcs_notify function is currently untested. Use at own risk!");
-       
-       if (! exists $ENV{REV}) {
-               error(gettext("REV is not set, not running from mtn post-commit hook, cannot send notifications"));
-       }
-       if ($ENV{REV} !~ m/($sha1_pattern)/) { # sha1 is untainted now
-               error(gettext("REV is not a valid revision identifier, cannot send notifications"));
-       }
-       my $rev = $1;
-       
-       check_config();
-
-       my $automator = Monotone->new();
-       $automator->open(undef, $config{mtnrootdir});
-
-       my $certs = [read_certs($automator, $rev)];
-       my $user;
-       my $message;
-       my $when;
-
-       foreach my $cert (@$certs) {
-               if ($cert->{signature} eq "ok" && $cert->{trust} eq "trusted") {
-                       if ($cert->{name} eq "author") {
-                               $user = $cert->{value};
-                       } elsif ($cert->{name} eq "date") {
-                               $when = $cert->{value};
-                       } elsif ($cert->{name} eq "changelog") {
-                               $message = $cert->{value};
-                       }
-               }
-       }
-               
-       my @changed_pages = get_changed_files($automator, $rev);
-       
-       $automator->close();
-       
-       require IkiWiki::UserInfo;
-       send_commit_mails(
-               sub {
-                       return $message;
-               },
-               sub {
-                       `mtn --root=$config{mtnrootdir} au content_diff -r $rev`;
-               },
-               $user, @changed_pages);
-} #}}}
-
 sub rcs_getctime ($) { #{{{
        my $file=shift;
 
@@ -609,4 +574,3 @@ __DATA__
                   return true
              end
        }
-EOF