summaryrefslogtreecommitdiff
path: root/ACE/bin/ChangeLogEditor/CVSFileLocator.pm
blob: 8e478509f01e70822a3cdd5a1e58602ad8945eb3 (plain)
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
package CVSFileLocator;

# ************************************************************
# Description   : Use CVS to determine the list of modified files.
# Author        : Chad Elliott
# Create Date   : 11/29/2005
# ************************************************************

# ************************************************************
# Pragmas
# ************************************************************

use strict;
use FileHandle;

use FileLocator;

use vars qw(@ISA);
@ISA = qw(FileLocator);

# ************************************************************
# Subroutine Section
# ************************************************************

sub locate {
  my($self)      = shift;
  my(@dirs)      = @_;
  my($fh)        = new FileHandle();
  my(@modified)  = ();
  my(@removed)   = ();
  my(@conflicts) = ();
  my(@unknown)   = ();
  my($error)     = undef;
  my($cvsroot)   = $self->obtainCVSROOT();
  my($err)       = $self->tmpnam('cle_cvs.err');

  if (open($fh, 'cvs -f -q ' . ($^O eq 'MSWin32' ? '-N ' : '') .
                (defined $cvsroot ? "-d $cvsroot " : '') .
                "-n update @dirs 2> $err |")) {
    while(<$fh>) {
      my($line) = $_;
      if ($line =~ /^[AM]\s+(.*)/) {
        push(@modified, $1);
      }
      elsif ($line =~ /^[R]\s+(.*)/) {
        push(@removed, $1);
      }
      elsif ($line =~ /^[C]\s+(.*)/) {
        push(@conflicts, $1);
      }
      elsif ($line =~ /^[\?]\s+(.*)/ && index($line, $err) == -1) {
        push(@unknown, $1);
      }
    }
    close($fh);

    $error = $self->process_errors($err);
  }
  else {
    $error = "Unable to run cvs with error redirection.";
  }

  return \@modified, \@removed, \@conflicts, \@unknown, $error;
}


sub obtainCVSROOT {
  my($self)  = shift;
  my($fh)    = new FileHandle();
  my($croot) = undef;

  if (open($fh, 'CVS/Root')) {
    while(<$fh>) {
      my($line) = $_;
      $line =~ s/\s+$//;
      if ($line =~ /^:pserver/ || $line =~ /^:ext/) {
        if (defined $ENV{CVSROOT} && $line eq $ENV{CVSROOT}) {
          last;
        }
        else {
          my($check) = $line;
          $check =~ s/:\w+\@/:\@/;
          $check =~ s/\.\w+\.\w+:/:/;
          my($clen) = length($check);
          foreach my $key (keys %ENV) {
            my($echeck) = $ENV{$key};
            $echeck =~ s/:\w+\@/:\@/;
            $echeck =~ s/\.\w+\.\w+:/:/;
            if ($check eq $echeck) {
              $croot = $ENV{$key};
              last;
            }
            else {
              my($len) = length($echeck);
              if ($len > 0 &&
                  substr($check, $clen - $len, $len) eq $echeck) {
                $croot = $ENV{$key};
                last;
              }
            }
          }
          if (defined $croot) {
            last;
          }
        }
        if (!defined $croot) {
          $croot = $line;
        }
      }
      else {
        $croot = $line;
        last;
      }
    }
    close($fh);
  }
  else {
    $croot = $ENV{CVSROOT};
  }

  return $croot;
}


1;