[Python-Dev] cvs for dummies

Greg Ward gward@mems-exchange.org
Mon, 15 May 2000 09:30:54 -0400


--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=us-ascii

On 13 May 2000, Fredrik Lundh said:
> what's the best way to make sure that a "cvs update" really brings
> everything up to date, even if you've accidentally changed some-
> thing in your local workspace?

Try the attached script -- it's basically the same as Greg Stein's "cvs
status | grep Local", but beefed-up and overkilled.

Example:

  $ cvstatus -l
  .cvsignore                     Up-to-date        2000-05-02 14:31:04
  Makefile.in                    Locally Modified  2000-05-12 12:25:39
  README                         Up-to-date        2000-05-12 12:34:42
  acconfig.h                     Up-to-date        2000-05-12 12:25:40
  config.h.in                    Up-to-date        2000-05-12 12:25:40
  configure                      Up-to-date        2000-05-12 12:25:40
  configure.in                   Up-to-date        2000-05-12 12:25:40
  install-sh                     Up-to-date        1998-08-13 12:08:45

...so yeah, it generates a lot of output when run on a large working
tree, eg. Python's.  But not as much as "cvs status" on its own.  ;-)

        Greg

PS. I just noticed it uses the "#!/usr/bin/env" hack with a command-line
option for the interpreter, which doesn't work on Linux.  ;-(  You may
have to hack the shebang line to make it work.

-- 
Greg Ward - software developer                gward@mems-exchange.org
MEMS Exchange / CNRI                           voice: +1-703-262-5376
Reston, Virginia, USA                            fax: +1-703-262-5367

--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=cvstatus

#!/usr/bin/env perl -w

#
# cvstatus
#
# runs "cvs status" (with optional file arguments), filtering out
# uninteresting stuff and putting in the last-modification time
# of each file.
#
# Usage: cvstatus [files]
#
# GPW 1999/02/17
#
# $Id: cvstatus,v 1.4 2000/04/14 14:56:14 gward Exp $
#

use strict;
use POSIX 'strftime';

my @files = @ARGV;

# Open a pipe to a forked child process
my $pid = open (CVS, "-|");
die "couldn't open pipe: $!\n" unless defined $pid;

# In the child -- run "cvs status" (with optional list of files
# from command line)
unless ($pid)
{
   open (STDERR, ">&STDOUT");           # merge stderr with stdout
   exec 'cvs', 'status', @files;
   die "couldn't exec cvs: $!\n";
}

# In the parent -- read "cvs status" output from the child
else
{
   my $dir = '';
   while (<CVS>)
   {
      my ($filename, $status, $mtime);
      if (/Examining (.*)/)
      {
         $dir = $1;
         if (! -d $dir)
         {
            warn "huh? no directory called $dir!";
            $dir = '';
         }
         elsif ($dir eq '.')
            { $dir = ''; }
         else
            { $dir .= '/' unless $dir =~ m|/$|; }
      }
      elsif (($filename, $status) = /^File: \s* (\S+) \s* Status: \s* (.*)/x)
      {
         $filename = $dir . $filename;
         if ($mtime = (stat $filename)[9])
         {
            $mtime = strftime ("%Y-%m-%d %H:%M:%S", localtime $mtime);
            printf "%-30.30s %-17s %s\n", $filename, $status, $mtime;
         }
         else
         {
            #warn "couldn't stat $filename: $!\n";
            printf "%-30.30s %-17s ???\n", $filename, $status;
         }
      }
   }

   close (CVS);
   warn "cvs failed\n" unless $? == 0;
}

--KsGdsel6WgEHnImy--