| 1293 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# Codestriker: Copyright (c) 2001, 2002 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 |
# Perforce repository class.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Repository::Perforce;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
|
|
|
14 |
# Constructor, which takes as a parameter the password, hostname and port.
|
|
|
15 |
sub new ($$$$$) {
|
|
|
16 |
my ($type, $user, $password, $hostname, $port) = @_;
|
|
|
17 |
|
|
|
18 |
my $self = {};
|
|
|
19 |
$self->{user} = $user;
|
|
|
20 |
$self->{password} = $password;
|
|
|
21 |
$self->{hostname} = $hostname;
|
|
|
22 |
$self->{port} = $port;
|
|
|
23 |
$self->{root} = "perforce:${user}" .
|
|
|
24 |
(defined $password && $password ne '' ? ":${password}" : '') .
|
|
|
25 |
"@" . "${hostname}:${port}";
|
|
|
26 |
bless $self, $type;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
# Retrieve the data corresponding to $filename and $revision. Store each line
|
|
|
30 |
# into $content_array_ref.
|
|
|
31 |
sub retrieve ($$$\$) {
|
|
|
32 |
my ($self, $filename, $revision, $content_array_ref) = @_;
|
|
|
33 |
|
|
|
34 |
# Open a pipe to the local CVS repository.
|
|
|
35 |
my $password = $self->{password};
|
|
|
36 |
open(P4, "\"$Codestriker::p4\"" .
|
|
|
37 |
" -p " . $self->{hostname} . ':' . $self->{port} .
|
|
|
38 |
" -u " . $self->{user} .
|
|
|
39 |
(defined $password && $password ne '' ?
|
|
|
40 |
" -P " . $self->{password} : '') .
|
|
|
41 |
" print -q \"$filename\"" . "#" . "$revision |")
|
|
|
42 |
|| die "Can't retrieve data using p4: $!";
|
|
|
43 |
|
|
|
44 |
# Read the data.
|
|
|
45 |
for (my $i = 1; <P4>; $i++) {
|
|
|
46 |
$_ = Codestriker::decode_topic_text($_);
|
|
|
47 |
chop;
|
|
|
48 |
$$content_array_ref[$i] = $_;
|
|
|
49 |
}
|
|
|
50 |
close P4;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
# Retrieve the "root" of this repository.
|
|
|
54 |
sub getRoot ($) {
|
|
|
55 |
my ($self) = @_;
|
|
|
56 |
return $self->{root};
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
# Return a URL which views the specified file and revision.
|
|
|
60 |
sub getViewUrl ($$$) {
|
|
|
61 |
my ($self, $filename, $revision) = @_;
|
|
|
62 |
|
|
|
63 |
# Lookup the file viewer from the configuration.
|
|
|
64 |
my $viewer = $Codestriker::file_viewer->{$self->{root}};
|
|
|
65 |
return (defined $viewer) ? $viewer . "/" . $filename : "";
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
# Return a string representation of this repository.
|
|
|
69 |
sub toString ($) {
|
|
|
70 |
my ($self) = @_;
|
|
|
71 |
return $self->{root};
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
# Given a start tag, end tag and a module name, store the text into
|
|
|
75 |
# the specified file handle. If the size of the diff goes beyond the
|
|
|
76 |
# limit, then return the appropriate error code.
|
|
|
77 |
sub getDiff ($$$$$) {
|
|
|
78 |
my ($self, $start_tag, $end_tag, $module_name,
|
|
|
79 |
$stdout_fh, $stderr_fh) = @_;
|
|
|
80 |
|
|
|
81 |
return $Codestriker::UNSUPPORTED_OPERATION;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
1;
|