second try at merging and conflicts support
parent
9b769c751a
commit
ae66554115
68
ikiwiki
68
ikiwiki
|
@ -461,18 +461,43 @@ sub rcs_update () { #{{{
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
sub rcs_commit ($$) { #{{{
|
sub rcs_prepedit ($) { #{{{
|
||||||
|
# Prepares to edit a file under revision control. Returns a token
|
||||||
|
# that must be passed into rcs_commit when the file is ready
|
||||||
|
# for committing.
|
||||||
|
# The file is relative to the srcdir.
|
||||||
|
my $file=shift;
|
||||||
|
|
||||||
|
if (-d "$config{srcdir}/.svn") {
|
||||||
|
# For subversion, return the revision of the file when
|
||||||
|
# editing begins.
|
||||||
|
my $rev=svn_info("Revision", "$config{srcdir}/$file");
|
||||||
|
return defined $rev ? $rev : "";
|
||||||
|
}
|
||||||
|
} #}}}
|
||||||
|
|
||||||
|
sub rcs_commit ($$$) { #{{{
|
||||||
# Tries to commit the page; returns undef on _success_ and
|
# Tries to commit the page; returns undef on _success_ and
|
||||||
# a version of the page with the rcs's conflict markers on failure.
|
# a version of the page with the rcs's conflict markers on failure.
|
||||||
# The file is relative to the srcdir.
|
# The file is relative to the srcdir.
|
||||||
my $file=shift;
|
my $file=shift;
|
||||||
my $message=shift;
|
my $message=shift;
|
||||||
|
my $rcstoken=shift;
|
||||||
|
|
||||||
if (-d "$config{srcdir}/.svn") {
|
if (-d "$config{srcdir}/.svn") {
|
||||||
# svn up to let svn merge in other changes
|
# Check to see if the page has been changed by someone
|
||||||
if (system("svn", "update", "-quiet", "$config{srcdir}/$file") != 0) {
|
# else since rcs_prepedit was called.
|
||||||
warn("svn update failed\n");
|
my $oldrev=int($rcstoken);
|
||||||
|
my $rev=svn_info("Revision", "$config{srcdir}/$file");
|
||||||
|
if ($rev != $oldrev) {
|
||||||
|
# Merge their changes into the file that we've
|
||||||
|
# changed.
|
||||||
|
if (system("svn", "merge", "--quiet", "-r$oldrev:$rev",
|
||||||
|
"$config{srcdir}/$file") != 0) {
|
||||||
|
warn("svn merge -r$oldrev:$rev failed\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (system("svn", "commit", "--quiet", "-m",
|
if (system("svn", "commit", "--quiet", "-m",
|
||||||
possibly_foolish_untaint($message),
|
possibly_foolish_untaint($message),
|
||||||
"$config{srcdir}/$file") != 0) {
|
"$config{srcdir}/$file") != 0) {
|
||||||
|
@ -504,6 +529,15 @@ sub rcs_add ($) { #{{{
|
||||||
}
|
}
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
||||||
|
sub svn_info ($$) { #{{{
|
||||||
|
my $file=shift;
|
||||||
|
my $field=shift;
|
||||||
|
|
||||||
|
my $info=`LANG=C svn info $file`;
|
||||||
|
my ($ret)=$info=~/^$field: (.*)$/m;
|
||||||
|
return $ret;
|
||||||
|
} #}}}
|
||||||
|
|
||||||
sub rcs_recentchanges ($) { #{{{
|
sub rcs_recentchanges ($) { #{{{
|
||||||
my $num=shift;
|
my $num=shift;
|
||||||
my @ret;
|
my @ret;
|
||||||
|
@ -513,8 +547,7 @@ sub rcs_recentchanges ($) { #{{{
|
||||||
eval q{use Time::Duration};
|
eval q{use Time::Duration};
|
||||||
|
|
||||||
if (-d "$config{srcdir}/.svn") {
|
if (-d "$config{srcdir}/.svn") {
|
||||||
my $info=`LANG=C svn info $config{srcdir}`;
|
my $svn_url=svn_info("URL", $config{srcdir});
|
||||||
my ($svn_url)=$info=~/^URL: (.*)$/m;
|
|
||||||
|
|
||||||
# FIXME: currently assumes that the wiki is somewhere
|
# FIXME: currently assumes that the wiki is somewhere
|
||||||
# under trunk in svn, doesn't support other layouts.
|
# under trunk in svn, doesn't support other layouts.
|
||||||
|
@ -1018,7 +1051,7 @@ sub cgi_editpage ($$) { #{{{
|
||||||
|
|
||||||
eval q{use CGI::FormBuilder};
|
eval q{use CGI::FormBuilder};
|
||||||
my $form = CGI::FormBuilder->new(
|
my $form = CGI::FormBuilder->new(
|
||||||
fields => [qw(do from page content comments)],
|
fields => [qw(do rcsinfo from page content comments)],
|
||||||
header => 1,
|
header => 1,
|
||||||
method => 'POST',
|
method => 'POST',
|
||||||
validate => {
|
validate => {
|
||||||
|
@ -1040,12 +1073,23 @@ sub cgi_editpage ($$) { #{{{
|
||||||
}
|
}
|
||||||
$page=lc($page);
|
$page=lc($page);
|
||||||
|
|
||||||
|
my $file=$page.$config{default_pageext};
|
||||||
|
my $newfile=1;
|
||||||
|
if (exists $pagesources{lc($page)}) {
|
||||||
|
$file=$pagesources{lc($page)};
|
||||||
|
$newfile=0;
|
||||||
|
}
|
||||||
|
|
||||||
$form->field(name => "do", type => 'hidden');
|
$form->field(name => "do", type => 'hidden');
|
||||||
$form->field(name => "from", type => 'hidden');
|
$form->field(name => "from", type => 'hidden');
|
||||||
$form->field(name => "page", value => "$page", force => 1);
|
$form->field(name => "page", value => "$page", force => 1);
|
||||||
$form->field(name => "comments", type => "text", size => 80);
|
$form->field(name => "comments", type => "text", size => 80);
|
||||||
$form->field(name => "content", type => "textarea", rows => 20,
|
$form->field(name => "content", type => "textarea", rows => 20,
|
||||||
cols => 80);
|
cols => 80);
|
||||||
|
if (! $form->submitted) {
|
||||||
|
$form->field(name => "rcsinfo", type => 'hidden',
|
||||||
|
value => rcs_prepedit($file), force => 1);
|
||||||
|
}
|
||||||
|
|
||||||
if ($form->submitted eq "Cancel") {
|
if ($form->submitted eq "Cancel") {
|
||||||
print $q->redirect("$config{url}/".htmlpage($page));
|
print $q->redirect("$config{url}/".htmlpage($page));
|
||||||
|
@ -1120,13 +1164,6 @@ sub cgi_editpage ($$) { #{{{
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# save page
|
# save page
|
||||||
my $file=$page.$config{default_pageext};
|
|
||||||
my $newfile=1;
|
|
||||||
if (exists $pagesources{lc($page)}) {
|
|
||||||
$file=$pagesources{lc($page)};
|
|
||||||
$newfile=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $content=$form->field('content');
|
my $content=$form->field('content');
|
||||||
$content=~s/\r\n/\n/g;
|
$content=~s/\r\n/\n/g;
|
||||||
$content=~s/\r/\n/g;
|
$content=~s/\r/\n/g;
|
||||||
|
@ -1152,7 +1189,8 @@ sub cgi_editpage ($$) { #{{{
|
||||||
unlockwiki();
|
unlockwiki();
|
||||||
# presumably the commit will trigger an update
|
# presumably the commit will trigger an update
|
||||||
# of the wiki
|
# of the wiki
|
||||||
my $conflict=rcs_commit($file, $message);
|
my $conflict=rcs_commit($file, $message,
|
||||||
|
$form->field("rcsinfo"));
|
||||||
|
|
||||||
if (defined $conflict) {
|
if (defined $conflict) {
|
||||||
$form->tmpl_param("page_conflict", 1);
|
$form->tmpl_param("page_conflict", 1);
|
||||||
|
|
Loading…
Reference in New Issue