- # Commit the page. Returns 'undef' on success and a version of the page
- # with conflict markers on failure.
-
- my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
-
- # Compute if the "revision" of $file changed.
- my $changed = darcs_rev($file) ne $rcstoken;
-
- # Yes, the following is a bit convoluted.
- if ($changed) {
- # TODO. Invent a better, non-conflicting name.
- rename("$config{srcdir}/$file", "$config{srcdir}/$file.save") or
- error("failed to rename $file to $file.save: $!");
-
- # Roll the repository back to $rcstoken.
-
- # TODO. Can we be sure that no changes are lost? I think that
- # we can, if we make sure that the 'darcs push' below will always
- # succeed.
-
- # We need to revert everything as 'darcs obliterate' might choke
- # otherwise.
- # TODO: 'yes | ...' needed? Doesn't seem so.
- silentsystem($darcs, "revert", "--repodir", $config{srcdir}, "--all") and
- error("'darcs revert' failed");
- # Remove all patches starting at $rcstoken.
- my $child = open(DARCS_OBLITERATE, "|-");
- if (! $child) {
- open(STDOUT, ">/dev/null");
- exec($darcs, "obliterate", "--repodir", $config{srcdir},
- "--match", "hash " . $rcstoken) and
- error("'darcs obliterate' failed");
- }
- while (print DARCS_OBLITERATE "y") {
- ;
- }
- close(DARCS_OBLITERATE);
- # Restore the $rcstoken one.
- silentsystem($darcs, "pull", "--quiet", "--repodir", $config{srcdir},
- "--match", "hash " . $rcstoken, "--all") and
- error("'darcs pull' failed");
-
- # We're back at $rcstoken. Re-install the modified file.
- rename("$config{srcdir}/$file.save", "$config{srcdir}/$file") or
- error("failed to rename $file.save to $file: $!");
- }
-
- # Record the changes.
- my $author;
- if (defined $user) {
- $author = "$user\@web";
- } elsif (defined $ipaddr) {
- $author = "$ipaddr\@web";
- } else {
- $author = "anon\@web";
- }
- if (!defined $message || !length($message)) {
- $message = "empty message";
- }
- silentsystem($darcs, 'record', '--repodir', $config{srcdir}, '--all',
- '-m', $message, '--author', $author, $file) and
- error("'darcs record' failed");
-
- # Update the repository by pulling from the default repository, which is
- # master repository.
- silentsystem($darcs, "pull", "--quiet", "--repodir", $config{srcdir},
- "--all") and error("'darcs pull' failed");
-
- # If this updating yields any conflicts, we'll record them now to resolve
- # them. If nothing is recorded, there are no conflicts.
- $rcstoken = darcs_rev($file);
- # TODO: Use only the first line here, i.e. only the patch name?
- writefile("$file.log", $config{srcdir}, 'resolve conflicts: ' . $message);
- silentsystem($darcs, 'record', '--repodir', $config{srcdir}, '--all',
- '-m', 'resolve conflicts: ' . $message, '--author', $author, $file) and
- error("'darcs record' failed");
- my $conflicts = darcs_rev($file) ne $rcstoken;
- unlink("$config{srcdir}/$file.log") or
- error("failed to remove '$file.log'");
-
- # Push the changes to the main repository.
- silentsystem($darcs, 'push', '--quiet', '--repodir', $config{srcdir}, '--all')
- and error("'darcs push' failed");
- # TODO: darcs send?
-
- if ($conflicts) {
- my $document = readfile("$config{srcdir}/$file");
- # Try to leave everything in a consistent state.
- # TODO: 'yes | ...' needed? Doesn't seem so.
- silentsystem($darcs, "revert", "--repodir", $config{srcdir}, "--all") and
- warn("'darcs revert' failed");
- return $document;
- } else {
- return undef;
- }
+ # Commit the page. Returns 'undef' on success and a version of the page
+ # with conflict markers on failure.
+
+ my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
+
+ # Compute if the "revision" of $file changed.
+ my $changed = darcs_rev($file) ne $rcstoken;
+
+ # Yes, the following is a bit convoluted.
+ if ($changed) {
+ # TODO. Invent a better, non-conflicting name.
+ rename("$config{srcdir}/$file", "$config{srcdir}/$file.save") or
+ error("failed to rename $file to $file.save: $!");
+
+ # Roll the repository back to $rcstoken.
+
+ # TODO. Can we be sure that no changes are lost? I think that
+ # we can, if we make sure that the 'darcs push' below will always
+ # succeed.
+
+ # We need to revert everything as 'darcs obliterate' might choke
+ # otherwise.
+ # TODO: 'yes | ...' needed? Doesn't seem so.
+ silentsystem('darcs', "revert", "--repodir", $config{srcdir}, "--all") and
+ error("'darcs revert' failed");
+ # Remove all patches starting at $rcstoken.
+ my $child = open(DARCS_OBLITERATE, "|-");
+ if (! $child) {
+ open(STDOUT, ">/dev/null");
+ exec('darcs', "obliterate", "--repodir", $config{srcdir},
+ "--match", "hash " . $rcstoken) and
+ error("'darcs obliterate' failed");
+ }
+ while (print DARCS_OBLITERATE "y") {
+ ;
+ }
+ close(DARCS_OBLITERATE);
+ # Restore the $rcstoken one.
+ silentsystem('darcs', "pull", "--quiet", "--repodir", $config{srcdir},
+ "--match", "hash " . $rcstoken, "--all") and
+ error("'darcs pull' failed");
+
+ # We're back at $rcstoken. Re-install the modified file.
+ rename("$config{srcdir}/$file.save", "$config{srcdir}/$file") or
+ error("failed to rename $file.save to $file: $!");
+ }
+
+ # Record the changes.
+ my $author;
+ if (defined $user) {
+ $author = "$user\@web";
+ } elsif (defined $ipaddr) {
+ $author = "$ipaddr\@web";
+ } else {
+ $author = "anon\@web";
+ }
+ if (!defined $message || !length($message)) {
+ $message = "empty message";
+ }
+ silentsystem('darcs', 'record', '--repodir', $config{srcdir}, '--all',
+ '-m', $message, '--author', $author, $file) and
+ error("'darcs record' failed");
+
+ # Update the repository by pulling from the default repository, which is
+ # master repository.
+ silentsystem('darcs', "pull", "--quiet", "--repodir", $config{srcdir},
+ "--all") and error("'darcs pull' failed");
+
+ # If this updating yields any conflicts, we'll record them now to resolve
+ # them. If nothing is recorded, there are no conflicts.
+ $rcstoken = darcs_rev($file);
+ # TODO: Use only the first line here, i.e. only the patch name?
+ writefile("$file.log", $config{srcdir}, 'resolve conflicts: ' . $message);
+ silentsystem('darcs', 'record', '--repodir', $config{srcdir}, '--all',
+ '-m', 'resolve conflicts: ' . $message, '--author', $author, $file) and
+ error("'darcs record' failed");
+ my $conflicts = darcs_rev($file) ne $rcstoken;
+ unlink("$config{srcdir}/$file.log") or
+ error("failed to remove '$file.log'");
+
+ # Push the changes to the main repository.
+ silentsystem('darcs', 'push', '--quiet', '--repodir', $config{srcdir}, '--all')
+ and error("'darcs push' failed");
+ # TODO: darcs send?
+
+ if ($conflicts) {
+ my $document = readfile("$config{srcdir}/$file");
+ # Try to leave everything in a consistent state.
+ # TODO: 'yes | ...' needed? Doesn't seem so.
+ silentsystem('darcs', "revert", "--repodir", $config{srcdir}, "--all") and
+ warn("'darcs revert' failed");
+ return $document;
+ } else {
+ return undef;
+ }