[m-dev.] For review: Fixes for remote CVS
Warwick Harvey
wharvey at cs.monash.edu.au
Wed May 19 16:39:36 AEST 1999
Can somebody please review this proposed change? Perhaps both somebody
"local" and somebody else using CVS remotely? Please note I don't know
Perl, so if there are any ugly/naughty things I've done, please point them
out to me.
Note also that this change requires the program `xmessage' to be installed
on the machine being used as the CVS server in order to query remote users.
As far as I can tell it's not installed on any suitable Melbourne Uni
machine. However, it is part of X11's `contrib' package, so I'm sure it
would be straightforward to install on, say, hydra by grabbing the
appropriate Debian package. Alternatively, a simple X program could be
written (preferably in a widely available and portable scripting language)
to do essentially the same thing, and then it'd work on pretty much any
machine one wanted to use for the CVS server. (Unfortunately I have
negligible experience with all such languages.)
The modified check.pl script below has been tested in my own private
repository on mundook, and seems to work fine for both local and remote
users.
Warwick
Estimated hours taken: 10 (including much time examining CVS internals before
modification of CVS was discarded as an option)
Currently, modifying some files in Mercury's CVS repository (namely those
for which copyright messages are inappropriate) is effectively impossible if
one is using remote CVS. This is because the pre-commit check fails for
such files if the script cannot query the user, which it cannot if a
client/server mode is being used. As a result, if a remote user wishes to
commit such files, they must first transfer their working CVS directories to
a machine with local access to the repository and do the commit from there.
Needless to say, this is a right royal pain. :-)
In general, it appears this problem cannot be solved completely without
patching CVS itself. It seemed unviable to require patched versions of CVS
to be installed, particularly if this was required for both clients and
servers. As a result, this patch (which does not touch CVS at all) only
offers a partial solution. It works for the case where a valid DISPLAY
environment variable is set; this is true in particular for users using ssh
to connect to the server. In such a case the pre-commit check script
attempts to query the user by popping up an X dialog and requesting
confirmation.
CVSROOT/check.pl:
Attempt to use an X connection to query a remote user if reading
from the TTY would not work.
cvs diff: Diffing .
Index: check.pl
===================================================================
RCS file: /home/mercury1/repository/CVSROOT/check.pl,v
retrieving revision 1.9
diff -u -r1.9 check.pl
--- check.pl 1999/02/19 22:26:31 1.9
+++ check.pl 1999/05/19 05:43:36
@@ -3,6 +3,10 @@
# check.pl does a simple check of group-id of the files, and the group
# read bit. If all is okay, it succeeds, otherwise it fails.
+# It also checks files for copyright messages. If there are none, or if
+# they appear to be out-of-date, then the user is queried to determine
+# whether they wish to commit anyway.
+
#---------------------------------------------------------------------------
--#
# we want the files to have group mercury, which has group_id 62
@@ -19,6 +23,10 @@
#---------------------------------------------------------------------------
--#
+sub query_force;
+
+#---------------------------------------------------------------------------
--#
+
$retval = 0;
$force = 0;
@@ -107,20 +115,77 @@
if ($force) {
print "Forcing commit anyway.\n";
} else {
- if (open TTY, "/dev/tty") {
- print "Commit anyway? [n] ";
- if (<TTY> =~ /^y/i) {
- print "OK, if you insist!\n";
- } else {
- $retval = 1;
- }
+ if (query_force($arg)) {
+ print "OK, if you insist!\n\n";
} else {
- print "\nCan't read from your terminal.\n";
- print "You appear to be using remote cvs.\n";
- print "I guess you're screwed, then.\n";
+ print "Will not commit.\n\n";
$retval = 1;
}
}
}
}
exit($retval);
+
+sub query_force {
+ if (open TTY, "/dev/tty") {
+ print "Commit anyway? [n] ";
+ if (<TTY> =~ /^y/i) {
+ return 1;
+ } else {
+ return 0;
+ }
+ } else {
+ my $file = shift(@_);
+ my $result;
+ my $have_X_display = $ENV{DISPLAY} ne "";
+
+ if (! $already_remote) {
+ #
+ # If this is the first time through, we have a few
+ # extra things to do and say.
+ #
+
+ $already_remote = 1;
+
+ # We don't want the output to be (block) buffered
+ $| = 1;
+
+ print "\nCan't read from your terminal --- "
+ . "you appear to be using remote CVS.\n";
+
+ if ($have_X_display) {
+ print "Trying X connection to "
+ . "$ENV{DISPLAY}.\n\n";
+ } else {
+ print "You have no DISPLAY environment "
+ . "variable set so I don't know\n"
+ . "how to interact with you. "
+ . "Sorry.\n\n";
+ }
+ }
+
+ return 0 unless $have_X_display;
+
+ #
+ # Try interacting with the user via X. This probably only
+ # works when connecting via something such as ssh which
+ # redirects X connections back to their origin.
+ #
+
+ $result = system "xmessage", "-buttons", "yes:1,no:0",
+ "Problem with `$file'. Commit anyway?";
+ if ($result != 0xff00 && ($result & 0xff) == 0) {
+ return $result >> 8;
+ } else {
+ print "Error running `xmessage', sorry.\n";
+ print "(Result code = ", $result, ")\n";
+ return 0;
+ }
+ }
+
+ print "\nOops: check.pl: "
+ . "query_force reached end without returning a result\n";
+
+ return 0;
+}
+
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list