add rcs_commit_staged and rcs_rename

Implemented for git and svn so far.

Note that rcs_commit_staged does assume that the rcs has the ability to
"stage" multiple changes for a later commit. Support for this varies, but
all we really care about is staging removals and renames, which, AFAIK, all
modern rcs's support.
master
Joey Hess 2008-07-22 16:14:33 -04:00
parent cf9620074a
commit cbddb5a4b8
10 changed files with 153 additions and 18 deletions

View File

@ -171,11 +171,10 @@ sub sessioncgi ($$) { #{{{
if ($config{rcs}) {
IkiWiki::disable_commit_hook();
foreach my $file (@files) {
my $token=IkiWiki::rcs_prepedit($file);
IkiWiki::rcs_remove($file);
IkiWiki::rcs_commit($file, gettext("removed"),
$token, $session->param("name"), $ENV{REMOTE_ADDR});
}
IkiWiki::rcs_commit_staged(gettext("removed"),
$session->param("name"), $ENV{REMOTE_ADDR});
IkiWiki::enable_commit_hook();
IkiWiki::rcs_update();
}

View File

@ -66,7 +66,9 @@ sub check_canrename ($$$$$$$) { #{{{
# Must be editable.
IkiWiki::check_canedit($dest, $q, $session);
if ($attachment) {
IkiWiki::Plugin::attachment::check_canattach($session, $dest, $destfile);
# Note that $srcfile is used here, not $destfile,
# because it wants the current file, to check it.
IkiWiki::Plugin::attachment::check_canattach($session, $dest, $srcfile);
}
}
} #}}}
@ -210,15 +212,16 @@ sub sessioncgi ($$) { #{{{
check_canrename($src, $srcfile, $dest, $destfile,
$q, $session, $q->param("attachment"));
# Ensures that the dest directory exists and is ok.
IkIWiki::prep_writefile($destfile, $config{srcdir});
# Do rename, and update the wiki.
require IkiWiki::Render;
if ($config{rcs}) {
IkiWiki::disable_commit_hook();
my $token=IkiWiki::rcs_prepedit($srcfile);
IkiWiki::rcs_rename($srcfile, $destfile);
# TODO commit destfile too
IkiWiki::rcs_commit($srcfile, gettext("rename $srcfile to $destfile"),
$token, $session->param("name"), $ENV{REMOTE_ADDR});
IkiWiki::rcs_commit_staged(gettext("rename $srcfile to $destfile"),
$session->param("name"), $ENV{REMOTE_ADDR});
IkiWiki::enable_commit_hook();
IkiWiki::rcs_update();
}

View File

@ -24,6 +24,14 @@ sub rcs_commit ($$$;$$) {
# Tries to commit the page; returns undef on _success_ and
# a version of the page with the rcs's conflict markers on failure.
# The file is relative to the srcdir.
my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
return undef # success
}
sub rcs_commit_staged ($$$) {
# Commits all staged changes. Changes can be staged using rcs_add,
# rcs_remove, and rcs_rename.
my ($message, $user, $ipaddr)=@_;
return undef # success
}
@ -31,12 +39,25 @@ sub rcs_add ($) {
# Add a file. The filename is relative to the root of the srcdir.
# Note that this should not check the new file in, it should only
# prepare for it to be checked in when rcs_commit is called.
# Note that the file may be in a new subdir that is not yet added
# to version control; the subdir can be added if so.
}
sub rcs_remove ($) {
# Remove a file. The filename is relative to the root of the srcdir.
# Note that this should not check the removal in, it should only
# prepare for it to be checked in when rcs_commit is called.
# Note that the new file may be in a new subdir that is not yet added
# to version control; the subdir can be added if so.
}
sub rcs_rename ($$) {
# Rename a file. The filenames are relative to the root of the srcdir.
# Note that this should not commit the rename, it should only
# prepare it for when rcs_commit is called.
# The new filename may be in a new subdir, that is not yet added to
# version control. If so, the subdir will exist already, and should
# be added.
}
sub rcs_recentchanges ($) {

View File

@ -80,6 +80,14 @@ sub rcs_commit ($$$;$$) { #{{{
return undef; # success
} #}}}
sub rcs_commit_staged ($$$) {
# Commits all staged changes. Changes can be staged using rcs_add,
# rcs_remove, and rcs_rename.
my ($message, $user, $ipaddr)=@_;
error("rcs_commit_staged not implemented for bzr"); # TODO
}
sub rcs_add ($) { # {{{
my ($file) = @_;
@ -95,6 +103,12 @@ sub rcs_remove ($) { # {{{
error("rcs_remove not implemented for bzr"); # TODO
} #}}}
sub rcs_rename ($$) { # {{{
my ($src, $dest) = @_;
error("rcs_rename not implemented for bzr"); # TODO
} #}}}
sub rcs_recentchanges ($) { #{{{
my ($num) = @_;

View File

@ -318,7 +318,16 @@ sub rcs_commit ($$$;$$) { #{{{
my $conflict = _merge_past($prev, $file, $dummy_commit_msg);
return $conflict if defined $conflict;
}
rcs_add($file);
return rcs_commit_staged($message, $user, $ipaddr);
} #}}}
sub rcs_commit_staged ($$$) {
# Commits all staged changes. Changes can be staged using rcs_add,
# rcs_remove, and rcs_rename.
my ($message, $user, $ipaddr)=@_;
# Set the commit author and email to the web committer.
my %env=%ENV;
if (defined $user || defined $ipaddr) {
@ -330,7 +339,8 @@ sub rcs_commit ($$$;$$) { #{{{
# git commit returns non-zero if file has not been really changed.
# so we should ignore its exit status (hence run_or_non).
$message = possibly_foolish_untaint($message);
if (run_or_non('git', 'commit', '--cleanup=verbatim', '-q', '-m', $message, '-i', $file)) {
if (run_or_non('git', 'commit', '--cleanup=verbatim',
'-q', '-m', $message)) {
if (length $config{gitorigin_branch}) {
run_or_cry('git', 'push', $config{gitorigin_branch});
}
@ -338,7 +348,7 @@ sub rcs_commit ($$$;$$) { #{{{
%ENV=%env;
return undef; # success
} #}}}
}
sub rcs_add ($) { # {{{
# Add file to archive.
@ -356,6 +366,12 @@ sub rcs_remove ($) { # {{{
run_or_cry('git', 'rm', '-f', $file);
} #}}}
sub rcs_rename ($$) { # {{{
my ($src, $dest) = @_;
run_or_cry('git', 'mv', '-f', $src, $dest);
} #}}}
sub rcs_recentchanges ($) { #{{{
# List of recent changes.

View File

@ -92,6 +92,14 @@ sub rcs_commit ($$$;$$) { #{{{
return undef; # success
} #}}}
sub rcs_commit_staged ($$$) {
# Commits all staged changes. Changes can be staged using rcs_add,
# rcs_remove, and rcs_rename.
my ($message, $user, $ipaddr)=@_;
error("rcs_commit_staged not implemented for mercurial"); # TODO
}
sub rcs_add ($) { # {{{
my ($file) = @_;
@ -107,6 +115,12 @@ sub rcs_remove ($) { # {{{
error("rcs_remove not implemented for mercurial"); # TODO
} #}}}
sub rcs_rename ($$) { # {{{
my ($src, $dest) = @_;
error("rcs_rename not implemented for mercurial"); # TODO
} #}}}
sub rcs_recentchanges ($) { #{{{
my ($num) = @_;

View File

@ -359,6 +359,14 @@ sub rcs_commit ($$$;$$) { #{{{
return undef # success
} #}}}
sub rcs_commit_staged ($$$) {
# Commits all staged changes. Changes can be staged using rcs_add,
# rcs_remove, and rcs_rename.
my ($message, $user, $ipaddr)=@_;
error("rcs_commit_staged not implemented for monotone"); # TODO
}
sub rcs_add ($) { #{{{
my $file=shift;
@ -376,6 +384,12 @@ sub rcs_remove ($) { # {{{
error("rcs_remove not implemented for monotone"); # TODO
} #}}}
sub rcs_rename ($$) { # {{{
my ($src, $dest) = @_;
error("rcs_rename not implemented for monotone"); # TODO
} #}}}
sub rcs_recentchanges ($) { #{{{
my $num=shift;
my @ret;

View File

@ -117,6 +117,28 @@ sub rcs_commit ($$$;$$) { #{{{
return undef # success
} #}}}
sub rcs_commit_staged ($$$) {
# Commits all staged changes. Changes can be staged using rcs_add,
# rcs_remove, and rcs_rename.
my ($message, $user, $ipaddr)=@_;
if (defined $user) {
$message="web commit by $user".(length $message ? ": $message" : "");
}
elsif (defined $ipaddr) {
$message="web commit from $ipaddr".(length $message ? ": $message" : "");
}
if (system("svn", "commit", "--quiet",
"--encoding", "UTF-8", "-m",
possibly_foolish_untaint($message),
$config{srcdir}) != 0) {
warn("svn commit failed\n");
return 1; # failure
}
return undef # success
}
sub rcs_add ($) { #{{{
# filename is relative to the root of the srcdir
my $file=shift;
@ -139,18 +161,35 @@ sub rcs_remove ($) { #{{{
my $file=shift;
if (-d "$config{srcdir}/.svn") {
my $parent=dirname($file);
while (! -d "$config{srcdir}/$parent/.svn") {
$file=$parent;
$parent=dirname($file);
}
if (system("svn", "rm", "--force", "--quiet", "$config{srcdir}/$file") != 0) {
warn("svn rm failed\n");
}
}
} #}}}
sub rcs_rename ($$) { #{{{
# filenames relative to the root of the srcdir
my ($src, $dest)=@_;
if (-d "$config{srcdir}/.svn") {
# Add parent directory for $dest
my $parent=dirname($dest);
if (! -d "$config{srcdir}/$parent/.svn") {
while (! -d "$config{srcdir}/$parent/.svn") {
$parent=dirname($dest);
}
if (system("svn", "add", "--quiet", "$config{srcdir}/$parent") != 0) {
warn("svn add $parent failed\n");
}
}
if (system("svn", "mv", "--force", "--quiet",
"$config{srcdir}/$src", "$config{srcdir}/$dest") != 0) {
warn("svn rename failed\n");
}
}
} #}}}
sub rcs_recentchanges ($) { #{{{
my $num=shift;
my @ret;

View File

@ -78,6 +78,14 @@ sub rcs_commit ($$$;$$) { #{{{
return undef # success
} #}}}
sub rcs_commit_staged ($$$) {
# Commits all staged changes. Changes can be staged using rcs_add,
# rcs_remove, and rcs_rename.
my ($message, $user, $ipaddr)=@_;
error("rcs_commit_staged not implemented for tla"); # TODO
}
sub rcs_add ($) { #{{{
my $file=shift;
@ -94,6 +102,12 @@ sub rcs_remove ($) { # {{{
error("rcs_remove not implemented for tla"); # TODO
} #}}}
sub rcs_rename ($$) { # {{{a
my ($src, $dest) = @_;
error("rcs_rename not implemented for tla"); # TODO
} #}}}
sub rcs_recentchanges ($) {
my $num=shift;
my @ret;

3
debian/changelog vendored
View File

@ -2,12 +2,13 @@ ikiwiki (2.55) UNRELEASED; urgency=low
* remove: New plugin that adds the ability to remove pages via the web.
(Sponsored by The TOVA Company.)
* All rcs backends need to implement rcs_remove, rcs_commitstaged,
and rcs_rename. (Done for svn, git).
* rename: New plugin that adds the ability to rename pages via the web.
(Sponsored by The TOVA Company.) (This one's for you, Kyle.)
* prefix_directives enabled in doc wiki, all preprocessor directives
converted. (Simon McVittie)
* editpage: Don't show attachments link when attachments are disabled.
* All rcs backends need to implement rcs_remove. (Done for svn, git).
* tag: Allow tagbase to be overridden by starting a tag with "./" or "/".
(Simon McVittie)
* Really fix bug with links to pages with names containing colons.