| 1293 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# Codestriker: Copyright (c) 2001 - 2004 David Sitsky. All rights reserved.
|
|
|
3 |
# sits@users.sourceforge.net
|
|
|
4 |
#
|
|
|
5 |
# This program is free software; you can redistribute it and modify it under
|
|
|
6 |
# the terms of the GPL.
|
|
|
7 |
|
|
|
8 |
# CVS repository class which handles both local and pserver access methods.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Repository::Cvs;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
use FileHandle;
|
|
|
14 |
use Fatal qw / open close /;
|
|
|
15 |
|
|
|
16 |
# Factory method for creating a local CVS repository object.
|
|
|
17 |
sub build_local {
|
|
|
18 |
my ($type, $cvsroot, $optional_prefix) = @_;
|
|
|
19 |
|
|
|
20 |
my $self = {};
|
|
|
21 |
$self->{cvsroot} = $cvsroot;
|
|
|
22 |
$optional_prefix = "" unless defined $optional_prefix;
|
|
|
23 |
$self->{optional_prefix} = $optional_prefix;
|
|
|
24 |
$self->{url} = "${optional_prefix}${cvsroot}";
|
|
|
25 |
bless $self, $type;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
# Factory method for creating a pserver CVS repository object.
|
|
|
29 |
sub build_pserver {
|
|
|
30 |
my ($type, $optional_args, $username, $password, $hostname, $cvsroot) = @_;
|
|
|
31 |
|
|
|
32 |
my $self = {};
|
|
|
33 |
$optional_args = "" unless defined $optional_args;
|
|
|
34 |
$self->{optional_args} = $optional_args;
|
|
|
35 |
$self->{username} = $username;
|
|
|
36 |
$self->{password} = $password;
|
|
|
37 |
$self->{hostname} = $hostname;
|
|
|
38 |
$self->{cvsroot} = $cvsroot;
|
|
|
39 |
$self->{url} = ":pserver${optional_args}:${username}:${password}\@" .
|
|
|
40 |
"${hostname}:${cvsroot}";
|
|
|
41 |
bless $self, $type;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
# Factory method for creating a ext CVS repository object.
|
|
|
45 |
sub build_ext {
|
|
|
46 |
my ($type, $optional_args, $username, $hostname, $cvsroot) = @_;
|
|
|
47 |
|
|
|
48 |
my $self = {};
|
|
|
49 |
$optional_args = "" unless defined $optional_args;
|
|
|
50 |
$self->{optional_args} = $optional_args;
|
|
|
51 |
$self->{username} = $username;
|
|
|
52 |
$self->{hostname} = $hostname;
|
|
|
53 |
$self->{cvsroot} = $cvsroot;
|
|
|
54 |
$self->{url} = ":ext${optional_args}:${username}\@${hostname}:${cvsroot}";
|
|
|
55 |
bless $self, $type;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
# Factory method for creating an SSPI CVS repository object.
|
|
|
59 |
sub build_sspi {
|
|
|
60 |
my ($type, $username, $password, $hostname, $cvsroot) = @_;
|
|
|
61 |
|
|
|
62 |
my $self = {};
|
|
|
63 |
$self->{optional_args} = "";
|
|
|
64 |
$self->{username} = $username;
|
|
|
65 |
$self->{hostname} = $hostname;
|
|
|
66 |
$self->{cvsroot} = $cvsroot;
|
|
|
67 |
$self->{url} = ":sspi:${username}:${password}\@${hostname}:${cvsroot}";
|
|
|
68 |
bless $self, $type;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
# Retrieve the data corresponding to $filename and $revision. Store each line
|
|
|
73 |
# into $content_array_ref.
|
|
|
74 |
sub retrieve {
|
|
|
75 |
my ($self, $filename, $revision, $content_array_ref) = @_;
|
|
|
76 |
|
|
|
77 |
# Open a pipe to the CVS repository.
|
|
|
78 |
$ENV{'CVS_RSH'} = $Codestriker::ssh if defined $Codestriker::ssh;
|
|
|
79 |
|
|
|
80 |
my $read_data;
|
|
|
81 |
my $read_stdout_fh = new FileHandle;
|
|
|
82 |
open($read_stdout_fh, '>', \$read_data);
|
|
|
83 |
my @args = ();
|
|
|
84 |
push @args, '-q';
|
|
|
85 |
push @args, '-d';
|
|
|
86 |
push @args, $self->{url};
|
|
|
87 |
push @args, 'co';
|
|
|
88 |
push @args, '-p';
|
|
|
89 |
push @args, '-r';
|
|
|
90 |
push @args, $revision;
|
|
|
91 |
push @args, $filename;
|
|
|
92 |
Codestriker::execute_command($read_stdout_fh, undef,
|
|
|
93 |
$Codestriker::cvs, @args);
|
|
|
94 |
|
|
|
95 |
# Process the data for the topic.
|
|
|
96 |
open($read_stdout_fh, '<', \$read_data);
|
|
|
97 |
for (my $i = 1; <$read_stdout_fh>; $i++) {
|
|
|
98 |
$_ = Codestriker::decode_topic_text($_);
|
|
|
99 |
chop;
|
|
|
100 |
$$content_array_ref[$i] = $_;
|
|
|
101 |
}
|
|
|
102 |
close $read_stdout_fh;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
# Retrieve the "root" of this repository.
|
|
|
106 |
sub getRoot ($) {
|
|
|
107 |
my ($self) = @_;
|
|
|
108 |
return $self->{cvsroot};
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
# Return a URL which views the specified file and revision.
|
|
|
112 |
sub getViewUrl ($$$) {
|
|
|
113 |
my ($self, $filename, $revision) = @_;
|
|
|
114 |
|
|
|
115 |
# Lookup the file viewer from the configuration.
|
|
|
116 |
my $viewer = $Codestriker::file_viewer->{$self->{url}};
|
|
|
117 |
return (defined $viewer) ? $viewer . "/" . $filename : "";
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
# Return a string representation of this repository.
|
|
|
121 |
sub toString ($) {
|
|
|
122 |
my ($self) = @_;
|
|
|
123 |
return $self->{url};
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
# Given a start tag, end tag and a module name, store the text into
|
|
|
127 |
# the specified file handle. If the size of the diff goes beyond the
|
|
|
128 |
# limit, then return the appropriate error code.
|
|
|
129 |
sub getDiff ($$$$$$) {
|
|
|
130 |
my ($self, $start_tag, $end_tag, $module_name,
|
|
|
131 |
$stdout_fh, $stderr_fh, $default_to_head) = @_;
|
|
|
132 |
|
|
|
133 |
# If $end_tag is empty, but the $start_tag has a value, or
|
|
|
134 |
# $start_tag is empty, but $end_tag has a value, simply
|
|
|
135 |
# retrieve the diff that corresponds to the files full
|
|
|
136 |
# contents corresponding to that tag value.
|
|
|
137 |
if ($start_tag eq "" && $end_tag ne "") {
|
|
|
138 |
$start_tag = "1.0";
|
|
|
139 |
} elsif ($start_tag ne "" && $end_tag eq "") {
|
|
|
140 |
$end_tag = $start_tag;
|
|
|
141 |
$start_tag = "1.0";
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
# Cheat - having two '-u's changes nothing.
|
|
|
145 |
my $extra_options = $default_to_head ? '-u' : '-f';
|
|
|
146 |
|
|
|
147 |
$ENV{'CVS_RSH'} = $Codestriker::ssh if defined $Codestriker::ssh;
|
|
|
148 |
|
|
|
149 |
Codestriker::execute_command($stdout_fh, $stderr_fh, $Codestriker::cvs,
|
|
|
150 |
'-q', '-d', $self->{url}, 'rdiff',
|
|
|
151 |
$extra_options, '-u', '-r', $start_tag,
|
|
|
152 |
'-r', $end_tag, $module_name);
|
|
|
153 |
return $Codestriker::OK;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
1;
|