home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk1.iso / altsrc / articles / 10862 < prev    next >
Lisp/Scheme  |  1994-07-12  |  6KB  |  195 lines

  1. Newsgroups: alt.sources
  2. Path: wupost!sdd.hp.com!spool.mu.edu!howland.reston.ans.net!swrinde!news.dell.com!tadpole.com!uunet!news.iij.ad.jp!wnoc-tyo-news!aist-nara!newspost.aist-nara.ac.jp!youki-k
  3. From: youki-k@is.aist-nara.ac.jp (Youki Kadobayashi)
  4. Subject: gnu2rcs: convert gnu-style version control to RCS
  5. Message-ID: <YOUKI-K.94Jul12215044@alpha201.is.aist-nara.ac.jp>
  6. Sender: news@newspost.aist-nara.ac.jp (USENET News System)
  7. Nntp-Posting-Host: alpha201.aist-nara.ac.jp
  8. Organization: Nara Institute of Science and Technology, Japan
  9. Date: Tue, 12 Jul 1994 12:50:43 GMT
  10. Lines: 183
  11.  
  12. If you have some large source code trees, and if you frequently obtain
  13. patches from other net folks then you might find this script useful.
  14. I regularly use it to keep my BSD source tree latest, while keeping
  15. all changes logged.
  16.  
  17. ----------------
  18. This script may be useful after patching large source tree, e.g., /sys.
  19. It enables quasi-automatic version deposit in conjunction with an
  20. environment variable VERSION_CONTROL set to 'numbered', which tells
  21. GNU version of patch to make backups with numbered suffix such as
  22. ".~1~", ".~2~" ...
  23.  
  24. I regularly use this script in the following scenario:
  25. 1. apply patch to /sys
  26. 2. repeat 1. several times
  27. 3. run "gnu2rcs -v /sys" to get every changes logged into RCS
  28.  
  29.     // Youki Kadobayashi <youki-k@is.aist-nara.ac.jp>
  30.     // Graduate School of Information Science
  31.     // Nara Institute of Science and Technology, Japan
  32.  
  33. #!/bin/sh
  34. # This is a shell archive (produced by shar 3.50)
  35. # To extract the files from this archive, save it to a file, remove
  36. # everything above the "!/bin/sh" line above, and type "sh file_name".
  37. #
  38. # made 07/12/1994 12:44 UTC by youki-k@dec221
  39. # Source directory /auto/home/is/youki-k/work/rcshack
  40. #
  41. # existing files will NOT be overwritten unless -c is specified
  42. #
  43. # This shar contains:
  44. # length  mode       name
  45. # ------ ---------- ------------------------------------------
  46. #   3411 -rw-r--r-- gnu2rcs.pl
  47. #
  48. # ============= gnu2rcs.pl ==============
  49. if test -f 'gnu2rcs.pl' -a X"$1" != X"-c"; then
  50.     echo 'x - skipping gnu2rcs.pl (File already exists)'
  51. else
  52. echo 'x - extracting gnu2rcs.pl (Text)'
  53. sed 's/^X//' << 'SHAR_EOF' > 'gnu2rcs.pl' &&
  54. #!/usr/local/bin/perl
  55. #
  56. $usg = "gnu2rcs: convert gnu-style version control to RCS
  57. gnu2rcs [-lnpv] [-m message] directory...
  58. X    -l    only checkin the oldest version (with .~1~ suffix)
  59. X    -m    message for RCS checkin
  60. X    -n    don't execute; just print commands instead
  61. X    -p    preserve numbered backup files
  62. X    -v    verbose
  63. X
  64. do 'setenv VERSION_CONTROL numbered' to use in conjunction with GNU patch.
  65. ";
  66. # Author: Youki Kadobayashi <youki@wide.ad.jp>
  67. # $Header: /auto/home/is/youki-k/work/rcshack/RCS/gnu2rcs.pl,v 1.13 1994/07/03 19:57:11 youki-k Exp youki-k $
  68. #
  69. # This script may be useful after patching large source tree, e.g., /sys.
  70. # It enables quasi-automatic version deposit in conjunction with an
  71. # environment variable VERSION_CONTROL set to 'numbered', which tells
  72. # GNU version of patch to make backups with numbered suffix such as
  73. # ".~1~", ".~2~" ...
  74. #
  75. # I regularly use this script in the following scenario:
  76. # 1. apply patch to /sys
  77. # 2. repeat 1. several times
  78. # 3. run "gnu2rcs -v /sys" to get every changes logged into RCS
  79. #
  80. # It should also work with GNU emacs with (setq version-control t).
  81. # I haven't tried it yet, so I don't know how it's useful.
  82. # Maybe you can run this script periodically, say under cron, which
  83. # is effectively a poor man's 3DFS...
  84. #
  85. require "find.pl";
  86. require "getopts.pl";
  87. do Getopts('lm:npv');
  88. X
  89. if ($#ARGV < $[) {
  90. X    die $usg;
  91. }
  92. X
  93. $message = $opt_m ? $opt_m : "checked in by gnu2rcs";
  94. $| = 1;
  95. # Traverse desired filesystems
  96. foreach $dir (@ARGV) {
  97. X    &find($dir);
  98. }
  99. X
  100. # fake call to wanted and do the possibly remaining job.
  101. $name = $_ = '/';
  102. &wanted;
  103. X
  104. Xexit 0;
  105. X
  106. sub wanted {
  107. X    local ($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_);
  108. X    local ($e, $path, $version, $i, $v, $pwd);
  109. X    next if (-l $_);
  110. X    if (-d $_) {
  111. X    next if ($name =~ m|/RCS|);
  112. X    foreach $path (keys %v_from) {
  113. X        print "processing $path..." if $opt_v;
  114. X        &rename2($path, "$path.~new~");
  115. X        if ($opt_l) {
  116. X        print "$v_from{$path}..\n" if $opt_v;
  117. X        $version = "${path}.~${v_from{$path}}~";
  118. X        &rename2($version, $path);
  119. X        $e = &deposit($path);
  120. X        &rename2($path, $version) if $opt_p || $e;
  121. X        } else {
  122. X        for ($i = $v_from{$path}; $i <= $v_to{$path}; ++$i) {
  123. X            print "$i.." if $opt_v;
  124. X            $version = "${path}.~${i}~";
  125. X            &rename2($version, $path);
  126. X            $e = &deposit($path);
  127. X            &rename2($path, $version) if $opt_p || $e;
  128. X        }
  129. X        print "done\n" if $opt_v;
  130. X        }
  131. X        &rename2("$path.~new~", $path);
  132. X        &deposit($path);
  133. X    }
  134. X    undef %v_from;
  135. X    undef %v_to;
  136. X    }
  137. X    elsif (-f $_) {
  138. X    next if ($dir =~ m|/RCS|);
  139. X    if (/.~(\d+)~$/) {
  140. X        $v = $1;
  141. X        if (-f $`) {
  142. X        chop($pwd = `pwd`);
  143. X        $path = "$pwd/$`";
  144. X        print "found $name\n" if $opt_v;
  145. X        if (!defined($v_from{$path}) || $v < $v_from{$path}) {
  146. X            $v_from{$path} = $v;
  147. X        }
  148. X        if (!defined($v_to{$path}) || $v > $v_to{$path}) {
  149. X            $v_to{$path} = $v;
  150. X        }
  151. X        if (! -d "$pwd/RCS") {
  152. X            $opt_n ? print "mkdir $pwd/RCS\n" : 
  153. X            mkdir("RCS", 0775) || die "mkdir RCS: $!";
  154. X        }
  155. X        }
  156. X    }
  157. X    }
  158. }
  159. X
  160. sub rename2 {
  161. X    local ($from, $to) = @_;
  162. X    if ($opt_n) {
  163. X    print "mv $from $to\n";
  164. X    } else {
  165. X    rename ($from, $to) || warn "rename $from: $!";
  166. X    }
  167. }
  168. X
  169. sub deposit {
  170. X    local ($path) = @_;
  171. X    local ($e);
  172. X
  173. X    if ($opt_n) {
  174. X    print "ci -u -t/dev/null -m'$message' $path\n";
  175. X    print "co -l $path\n";
  176. X    return;
  177. X    }
  178. X
  179. X    $e = system "ci -q -u -t/dev/null -m'$message' $path";
  180. X    $e /= 256;  return $e if $e;
  181. X    $e = system "co -q -l $path";
  182. X    $e /= 256;
  183. }
  184. SHAR_EOF
  185. chmod 0644 gnu2rcs.pl ||
  186. echo 'restore of gnu2rcs.pl failed'
  187. Wc_c="`wc -c < 'gnu2rcs.pl'`"
  188. test 3411 -eq "$Wc_c" ||
  189.     echo 'gnu2rcs.pl: original size 3411, current size' "$Wc_c"
  190. fi
  191. exit 0
  192. --
  193.     // $BLgNS(B $BM:4p(B <youki-k@is.aist-nara.ac.jp>
  194.     // $BBg:eBg3X4pAC9)3XIt>pJs9)3X2J(B / $BF`NI@hC<2J3X5;=QBg3X1!Bg3X(B
  195.