1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
|
# Go find perl if we are running this as a shell script.
eval 'exec perl -Ssw $0 "$@"'
if 0;
# Mimic the BSD tool, sccs, for RCS.
# $Id$
#
# Note - this reflects a lot of my personal taste. I'll try and list the
# important differences here:
#
# A bunch of unused commands are not implemented. It is easy to add them,
# mail me if you want me to add something. Please include a spec of what
# you want the command to do. Mail lm@engr.sgi.com.
#
# I look at RCS file internals and know about certain fields as of revision
# 5.x.
#
# This interface does not require a list of files/directories for most
# commands; the implied list is *,v and/or RCS/*,v. Destructive commands,
# such as clean -f, unedit, unget, do *not* have an implied list. In
# other words,
# rccs diffs is the same as rccs diffs RCS
# but
# rccs unedit is not the same as rccs unedit RCS
#
# If you add (potentially) destructive commands, please check for
# them in main() and make sure that the autoexpand does not happen.
#
# TODO:
# Make it so that you can pass a list of files/dirs via stdin.
#
# It might be nice to have all the "system" args printed out in
# verbose and/or learn mode. Depends on whether you want people
# to learn RCS or not.
&init;
&main;
sub init
{
$0 =~ s|.*/||;
# Add commands here so that -w shuts up.
$lint = 0;
&clean() && &create() && &example() && &get() && &edit() &&
&unedit() && &unget() && &diffs() && &delta() && &help() &&
&prs() && &prt() && &deledit() && &delget() && &enter() &&
&info() && &ci() && &co() && &fix() && &print()
if $lint;
}
sub help
{
if ($#_ == -1) {
&usage;
}
# Handle all the aliases.
if ($_[0] eq "unedit" || $_[0] eq "unget") {
&help("clean");
} elsif ($_[0] eq "clean") {
}
warn "Extended help on @_ not available yet.\n";
}
sub usage
{
print <<EOF;
usage: $0 [$0 opts] command [args] [file and/or directory list]
$0 options are:
-debug for debugging of $0 itself
-verbose for more information about what $0 is doing
More information may be had by saying "$0 help subcommand".
Most commands take "-s" to mean do the work silently.
Command Effect
------- ------
clean - remove unedited (ro) working files
-e remove unmodified edited (rw) & unedited (ro) files
-f (force) remove modified working files as well
create - add a set of files to RCS control and get (co) the working files
-g do not do the get (co) of the working files
-y<msg> use <msg> as the description message (aka -d<msg>)
delta - check in a revision
-y<msg> use <msg> as the log message (aka -d<msg>)
-s
diffs - diff the working file against the RCS file
fix - redit the last revision
get - get the working file[s] (possibly for editing)
history - print history of the files
print - print the history and the latest contents
Alias Real command Effect
----- ------------ ------
ci - delta check in a revision
co - get check out a revision
enter - create -g initialize a file without a get afterward
unedit - clean -f remove working file even if modified
unget - clean -f remove working file even if modified
edit - get -e check out the file for editing
prs - history print change log history
prt - history print change log history
An implied list of *,v and/or RCS/*,v is implied for most commands.
The exceptions are commands that are potentially destructive, such as
unedit.
EOF
exit 0;
}
sub main
{
local($cmd);
local(@args);
local(@comma_v);
$cmd = "oops";
$cmd = shift(@ARGV) if $#ARGV > -1;
&help(@ARGV) if $cmd eq "help" || $cmd eq "oops";
$dir_specified = $file_specified = 0;
foreach $_ (@ARGV) {
# If it is an option, just pass it through.
if (/^-/) {
push(@args, $_);
}
# If they specified an RCS directory, explode it into ,v files.
elsif (-d $_) {
$dir_specified = 1;
warn "Exploding $_\n" if $debug;
push(@args, grep(/,v$/, &filelist($_)));
push(@args, grep(/,v$/, &filelist("$_/RCS")));
}
# If it is a file, make it be the ,v file.
else {
if (!/,v$/) {
# XXX - what if both ./xxx,v and ./RCS/xxx,v?
if (-f "$_,v") {
$_ .= ",v";
} else {
if (m|/|) {
m|(.*)/(.*)|;
$f = "$1/RCS/$2,v";
} else {
$f = "RCS/$_,v";
}
if (-f $f) {
$_ = $f;
}
}
}
if (-f $_) {
$file_specified = 1;
warn "Adding $_\n" if $debug;
push(@args, $_);
} else {
warn "$0: skipping $_, no RCS file.\n";
}
}
}
# Figure out if it is a potentially destructive command. These
# commands do not automagically expand *,v and RCS/*,v.
$destructive = ($cmd eq "clean" && $args[0] eq "-f") ||
$cmd eq "unedit" || $cmd eq "unget";
# If they didn't specify a file or a directory, generate a list
# of all ./*,v and ./RCS/*,v files.
unless ($destructive || $dir_specified || $file_specified) {
warn "Exploding . && ./RCS\n" if $debug;
push(@args, grep(/,v$/, &filelist(".")));
push(@args, grep(/,v$/, &filelist("RCS")));
}
unless ($cmd =~ /^create$/) {
@comma_v = grep(/,v$/, @args);
if ($#comma_v == -1) {
($s = "$cmd @ARGV") =~ s/\s+$//;
die "$0 $s: No RCS files specified.\n";
}
}
# Exit codes:
# 0 - it worked
# 1 - unspecified error
# 2 - command unknown
$exit = 2;
warn "Trying &$cmd(@args)\n" if $debug;
eval(&$cmd(@args));
if ($exit == 2) {
warn "Possible unknown/unimplemented command: $cmd\n";
&usage;
} else {
exit $exit;
}
}
# Read the directory and return a list of files.
# XXX - isn't there a builtin that does this?
sub filelist
{
local(@entries) = ();
local($ent);
opendir(DFD, $_[0]) || return ();
foreach $ent (readdir(DFD)) {
$ent = "$_[0]/$ent";
next unless -f $ent;
push(@entries, $ent);
}
warn "filelist($_[0]): @entries\n" if $debug;
@entries;
}
# Take a list of ,v files and return a list of associated working files.
sub working
{
local(@working, $working) = ();
foreach $comma_v (@_) {
# Strip the ,v.
# Strip the RCS specification.
($working = $comma_v) =~ s|,v$||;
$working =~ s|RCS/||;
push(@working, $working);
}
@working;
}
# Same as "clean -f" - throw away all changes
sub unedit { &clean("-f", @_); }
sub unget { &clean("-f", @_); }
# Get rid of everything that isn't edited and has an associated RCS file.
# -e remove edited files that have not been changed.
# -f remove files that are edited with changes (CAREFUL!)
# This implies the -e opt.
# -d<m> Check in files that have been modified. If no message, prompt
# on each file. This implies -e.
# -y<m> Like -d for people that are used to SCCS.
# -m<m> Like -d for people that are used to RCS.
#
# Note: this does not use rcsclean; I don't know when that showed up. And
# the 5.x release of RCS I have does not install it.
sub clean
{
local(@working);
local($e_opt, $f_opt, $d_opt, $s_opt) = (0,0,0,0);
local($msg);
local(@checkins) = ();
while ($_[0] =~ /^-/) {
if ($_[0] eq "-s") {
$s_opt = 1;
shift(@_);
} elsif ($_[0] eq "-e") {
$e_opt = 1;
shift(@_);
} elsif ($_[0] eq "-f") {
$f_opt = $e_opt = 1;
shift(@_);
} elsif ($_[0] =~ /^-[dym]/) {
$d_opt = $e_opt = 1;
if ($_[0] =~ /^-[dym]$/) {
$msg = $_[0];
} else {
($msg = $_[0]) =~ s/-[ydm]//;
$msg = "-m'" . $msg . "'";
}
shift(@_);
} else {
die "$0 clean: unknown option: $_[0]\n";
}
}
@working = &working(@_);
for ($i = 0; $i <= $#_; ++$i) {
# No working file?
if (!-f $working[$i]) {
warn "No working file $working[$i] for $_[$i]\n"
if $debug;
next;
}
# Read only? Unlink.
if (!-w $working[$i]) {
warn "rm $working[$i]\n" unless $s_opt;
# Make sure there is an RCS file
if (-f $_[$i]) {
# XXX - what if ro and edited?
unlink($working[$i]) unless $n;
} else {
warn "clean: no RCS file for $working[$i]\n";
}
next;
}
# If they just want to know about it, tell them.
if ($e_opt == 0) {
open(RCS, $_[$i]);
while ($r = <RCS>) {
last if $r =~ /locks/;
}
@locks = ();
while ($r = <RCS>) {
# XXX - I use "comment" a delimiter.
last if $r =~ /comment/;
$r =~ s/^\s+//;
chop($r);
push(@locks, $r);
}
close(RCS);
if ($#locks > -1) {
warn "$working[$i]: being edited: @locks\n";
} else {
warn "$working[$i]: " .
"writeable but not edited?!?\n";
}
next;
}
# See if there have actually been any changes.
# Notice that this is cmp(1) in about 10 lines of perl!
open(RCS, "co -q -p -kkvl $_[$i] |");
open(WORK, $working[$i]);
$diff = 0;
while ($r = <RCS>) {
unless (($w = <WORK>) && ($r eq $w)) {
$diff = 1;
last;
}
}
if ($w = <WORK>) {
$diff = 1;
}
close(RCS); close(WORK);
if ($diff) {
if ($f_opt) {
warn "Clean modified $working[$i]\n"
unless $s_opt;
unless ($n) {
unlink($working[$i]);
system "rcs -q -u $_[$i]";
}
} elsif ($d_opt) {
push(@checkins, $_[$i]);
} else {
warn "Can't clean modified $working[$i]\n";
}
next;
} else {
warn "rm $working[$i]\n" unless $s_opt;
unless ($n) {
unlink($working[$i]);
system "rcs -q -u $_[$i]";
}
}
}
# Handle files that needed deltas.
if ($#checkins > -1) {
warn "ci -q $msg @checkins\n" if $verbose;
system "ci -q $msg @checkins";
}
$exit = 0;
}
# Create - initialize the RCS file
# -y<c> - use <c> as the description message for all files.
# -d<c> - use <c> as the description message for all files.
# -g - don't do the get
#
# Differs from sccs in that it does not preserve the original
# files (I never found that very useful).
sub create
{
local($arg, $noget, $description, $cmd) = ("", "", "");
foreach $arg (@_) {
# Options...
if ($arg =~ /^-[yd]/) {
($description = $arg) =~ s/^-[yd]//;
$arg = "";
warn "Desc: $description\n" if $debug;
next;
}
if ($arg eq "-g") {
$noget = "yes";
$arg = "";
next;
}
next if ($arg =~ /^-/);
# If no RCS subdir, make one.
if ($arg =~ m|/|) { # full path
($dir = $arg) =~ s|/[^/]+$||;
mkdir("$dir/RCS", 0775);
} else { # in $CWD
mkdir("RCS", 0775);
}
}
$exit = 0;
if ($description ne "") {
$cmd = "ci -t-'$description' @_";
} else {
$cmd = "ci @_";
}
warn "$cmd\n" if $verbose;
system "$cmd";
system "co @_" unless $noget;
}
# Like create without the get.
sub enter { &create("-g", @_); }
# Edit - get the working file editable
sub edit { &get("-e", @_); }
# co - normal RCS
sub co { &get(@_); }
# Get - get the working file
# -e Retrieve a version for editing.
# Same as co -l.
# -p Print the file to stdout.
# -k Suppress expansion of ID keywords.
# Like co -kk.
# -s Suppress all output.
#
# Note that all other options are passed to co(1).
sub get
{
local($arg, $working, $f, $p);
$f = $p = 0;
foreach $arg (@_) {
# Options...
$arg = "-l" if ($arg eq "-e");
$arg = "-kk" if ($arg eq "-k");
$arg = "-q" if ($arg eq "-s");
$f = 1 if ($arg eq "-f");
$p = 1 if ($arg eq "-p"); # XXX - what if -sp?
next if $arg =~ /^-/ || $p;
# Check for writable files and skip them unless someone asked
# for co's -f option.
($working = $arg) =~ s|,v$||;
$working =~ s|RCS/||;
if ((-w $working) && $f == 0) {
warn "ERROR [$arg]: writable `$working' exists.\n";
$arg = "";
}
}
@files = grep(/,v/, @_);
if ($#files == -1) {
warn "$0 $cmd: no files to get. @_\n";
$exit = 1;
} else {
system "co @_";
$exit = 0;
}
}
# Aliases for history.
sub prt { &history(@_); }
sub prs { &history(@_); }
# History - change history sub command
sub history
{
local(@history);
open(RL, "rlog @_|");
# Read the whole history
while ($r = <RL>) {
# Read the history for one file.
if ($r !~ /^[=]+$/) {
push(@history, $r);
next;
}
&print_history(@history);
@history = ();
}
close(RL);
print "+-----------------------------------\n";
$exit = 0;
}
sub print_history
{
for ($i = 0; $i <= $#_; ++$i) {
# Get the one time stuff
if ($_[$i] =~ /^RCS file:/) {
$_[$i] =~ s/RCS file:\s*//;
chop($_[$i]);
print "+------ $_[$i] -------\n|\n";
}
# Get the history
if ($_[$i] =~ /^----------------------------/) {
local($rev, $date, $author, $lines) = ("", "", "", "");
$i++;
die "Bad format\n" unless $_[$i] =~ /revision/;
$_[$i] =~ s/revision\s+//;
chop($_[$i]);
$rev = $_[$i];
$i++;
die "Bad format\n" unless $_[$i] =~ /date/;
@parts = split(/[\s\n;]+/, $_[$i]);
for ($j = 0; $j <= $#parts; $j++) {
if ($parts[$j] =~ /date/) {
$j++;
$date = "$parts[$j] ";
$j++;
$date .= "$parts[$j]";
}
if ($parts[$j] =~ /author/) {
$j++;
$author = $parts[$j];
}
if ($parts[$j] =~ /lines/) {
$j++;
$lines = "$parts[$j] ";
$j++;
$lines .= "$parts[$j]";
}
}
print "| $rev $date $author $lines\n";
while ($_[++$i] &&
$_[$i] !~ /^----------------------------/) {
print "| $_[$i]"; ### unless $rev =~ /^1\.1$/;
}
print "|\n";
$i--;
}
}
}
# Show changes between working file and RCS file
#
# -C -> -c for compat with sccs (not sure if this is needed...).
sub diffs
{
local(@working);
local($diff) = "diff";
local($rev) = "";
while ($_[0] =~ /^-/) {
if ($_[0] eq "-C") {
$diff .= " -c";
shift(@_);
} elsif ($_[0] =~ /^-r/) {
$rev = $_[0];
shift(@_);
} elsif ($_[0] eq "-sdiff") {
# XXX - screen size
$diff = "sdiff -w80";
shift(@_);
} else {
$diff .= " $_[0]";
shift(@_);
}
}
@working = &working(@_);
for ($i = 0; $i <= $#_; ++$i) {
# No working file?
if (!-f $working[$i]) {
warn "No working file $working[$i] for $_[$i]\n"
if $debug;
next;
}
# Read only? Skip.
next unless (-w $working[$i]);
# Show the changes
print "\n------ $working[$i]$rev ------\n";
fflush(stdout);
# XXX - flush stdout.
if ($diff =~ /^sdiff/) {
system "co -q -p -kkvl $rev $_[$i] > /tmp/sdiff.$$" .
"&& $diff /tmp/sdiff.$$ $working[$i]";
# XXX - interrupts?
unlink("/tmp/sdiff.$$");
} else {
system "co -q -p -kkvl $rev $_[$i] |" .
" $diff - $working[$i]";
}
}
$exit = 0;
}
# delta - check in the files
sub delta
{
local($description) = ("");
local($i, @working);
@working = &working(@_);
for ($i = 0; $i <= $#_; ++$i) {
# Options...
if ($_[$i] =~ /^-[yd]/) {
($description = $_[$i]) =~ s/^-[yd]/-m/;
$description = "'" . $description . "'";
$_[$i] = "";
next;
}
$_[$i] = "-q" if $_[$i] eq "-s";
$_[$i] = "" unless -f $working[$i];
}
$exit = 0;
warn "ci $description @_\n" if $verbose;
system "ci $description @_";
}
# Allow RCS interface ci
sub ci
{
&delta(@_);
}
# delget
sub delget
{
&delta(@_);
&get(@_); # If there was a description, delta nuked it...
}
# deledit
sub deledit
{
&delta(@_);
&get("-e", @_); # If there was a description, delta nuked it...
}
# info - who is editing what
sub info
{
local(@working);
@working = &working(@_);
for ($i = 0; $i <= $#_; $i++) {
open(RCS, $_[$i]);
while ($r = <RCS>) {
last if $r =~ /locks/;
}
@locks = ();
while ($r = <RCS>) {
# XXX - I use "comment" a delimter.
last if $r =~ /comment/;
$r =~ s/^\s+//;
chop($r);
push(@locks, $r);
}
close(RCS);
if ($#locks > -1) {
warn "$working[$i]: being edited: @locks\n";
}
}
$exit = 0;
}
# Fix - fix the last change to a file
sub fix
{
foreach $f (@_) {
next unless -f $f;
open(F, $f); while (<F>) { last if /head\s\d/; } close(F);
unless ($_ && /head/) {
warn "$0 $cmd: No head node found in $f\n";
next;
}
s/head\s+//; chop; chop; $rev = $_;
($working = $f) =~ s/,v//;
$working =~ s|RCS/||;
system "co -q $f && rcs -o$rev $f && rcs -l $f && chmod +w $working";
}
$exit = 0;
}
# print - print the history and the latest revision of the file
sub print
{
local($file);
foreach $file (@_) {
&history($file);
&get("-s", "-p", $file);
}
$exit = 0;
}
# Example - example sub command
# -Q change this option to -q just to show how.
sub example
{
local($arg, $working);
foreach $arg (@_) {
# Options...
$arg = "-Q" if ($arg eq "-q");
}
warn "rlog @_\n" if $verbose;
system "rlog @_";
$exit = 0;
}
RCS bghtml html-list man2html
|