| 1293 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# Codestriker: Copyright (c) 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 |
# Handler for ClearCase Snapshot Views.
|
|
|
9 |
# Contributed by "Kannan Goundan" <kannan@letterboxes.org>.
|
|
|
10 |
|
|
|
11 |
package Codestriker::Repository::ClearCaseSnapshot;
|
|
|
12 |
|
|
|
13 |
use strict;
|
|
|
14 |
use File::Temp qw/ tempdir /;
|
|
|
15 |
use File::Spec;
|
|
|
16 |
|
|
|
17 |
# Constructor.
|
|
|
18 |
# - snapshot_dir: Absolute path to the location that you access the
|
|
|
19 |
# files in the snapshot view from. NOT the view storage directory.
|
|
|
20 |
sub new ($$) {
|
|
|
21 |
my ($type, $snapshot_dir) = @_;
|
|
|
22 |
|
|
|
23 |
my $self = {};
|
|
|
24 |
$self->{snapshot_dir} = $snapshot_dir;
|
|
|
25 |
bless $self, $type;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
# Retrieve the data corresponding to $filename and $revision. Store each line
|
|
|
29 |
# into $content_array_ref.
|
|
|
30 |
sub retrieve ($$$\$) {
|
|
|
31 |
my ($self, $filename, $revision, $content_array_ref) = @_;
|
|
|
32 |
|
|
|
33 |
# full_element_name = {snapshot_dir}/{filename}@@{revision}
|
|
|
34 |
my $full_element_name = File::Spec->catfile($self->{snapshot_dir},
|
|
|
35 |
$filename);
|
|
|
36 |
if (defined($revision) && length($revision) > 0) {
|
|
|
37 |
$full_element_name = $full_element_name . '@@' . $revision;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
# Create a temporary directory to store the results of 'cleartool get'.
|
|
|
41 |
my $tempdir;
|
|
|
42 |
if (defined $Codestriker::tmpdir && $Codestriker::tmpdir ne "") {
|
|
|
43 |
$tempdir = tempdir(DIR => $Codestriker::tmpdir, CLEANUP => 1);
|
|
|
44 |
}
|
|
|
45 |
else {
|
|
|
46 |
$tempdir = tempdir(CLEANUP => 1);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
my $tempfile = File::Spec->catfile($tempdir, "Temp_YouCanDeleteThis");
|
|
|
50 |
my $errorfile = File::Spec->catfile($tempdir, "Error_YouCanDeleteThis");
|
|
|
51 |
|
|
|
52 |
my $error_msg;
|
|
|
53 |
|
|
|
54 |
# Call 'cleartool get' to load the element
|
|
|
55 |
my $command = "\"$Codestriker::cleartool\" get " .
|
|
|
56 |
"-to \"$tempfile\" \"$full_element_name\" " .
|
|
|
57 |
"2> \"$errorfile\"";
|
|
|
58 |
my $ret = system($command);
|
|
|
59 |
|
|
|
60 |
eval {
|
|
|
61 |
|
|
|
62 |
if ($ret != 0) {
|
|
|
63 |
# If there was an error, the message will be in the error file.
|
|
|
64 |
# Read in that file and store it in the "$error_msg" variable
|
|
|
65 |
# so that we can return it to the caller.
|
|
|
66 |
open (ERRORFILE, "<$errorfile")
|
|
|
67 |
|| die "ClearTool returned an error, but Codestriker couldn't read from the error file.";
|
|
|
68 |
my (@errorlines) = <ERRORFILE>;
|
|
|
69 |
$error_msg = "Error from ClearTool: " . join(" ", @errorlines);
|
|
|
70 |
close ERRORFILE;
|
|
|
71 |
} else {
|
|
|
72 |
# Operation was successful. Load the file into the given array.
|
|
|
73 |
open (CONTENTFILE, "<$tempfile")
|
|
|
74 |
|| die "ClearTool execution succeeded, but Codestriker couldn't read from the output file.";
|
|
|
75 |
for (my $i = 1; <CONTENTFILE>; $i++) {
|
|
|
76 |
$_ = Codestriker::decode_topic_text($_);
|
|
|
77 |
chop;
|
|
|
78 |
$$content_array_ref[$i] = $_;
|
|
|
79 |
}
|
|
|
80 |
close CONTENTFILE;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
};
|
|
|
84 |
|
|
|
85 |
# See if anything called 'die' in the 'eval' block.
|
|
|
86 |
if ($@) {
|
|
|
87 |
$error_msg = $@;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
if (defined($tempdir)) {
|
|
|
91 |
unlink $errorfile;
|
|
|
92 |
unlink $tempfile;
|
|
|
93 |
rmdir $tempdir;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
# If there was no error, this will be undefined
|
|
|
97 |
return $error_msg;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
# Retrieve the "root" of this repository.
|
|
|
101 |
sub getRoot ($) {
|
|
|
102 |
my ($self) = @_;
|
|
|
103 |
return $self->{snapshot_dir};
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
# Return a URL which views the specified file and revision.
|
|
|
107 |
sub getViewUrl ($$$) {
|
|
|
108 |
my ($self, $filename, $revision) = @_;
|
|
|
109 |
|
|
|
110 |
# Lookup the file viewer from the configuration.
|
|
|
111 |
my $viewer = $Codestriker::file_viewer->{$self->toString()};
|
|
|
112 |
return (defined $viewer) ? $viewer . "/" . $filename : "";
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
# Return a string representation of this repository.
|
|
|
116 |
sub toString ($) {
|
|
|
117 |
my ($self) = @_;
|
|
|
118 |
return "clearcase:" . $self->{snapshot_dir};
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
# Given a start tag, end tag and a module name, store the text into
|
|
|
122 |
# the specified file handle. If the size of the diff goes beyond the
|
|
|
123 |
# limit, then return the appropriate error code.
|
|
|
124 |
sub getDiff ($$$$$$) {
|
|
|
125 |
my ($self, $start_tag, $end_tag, $module_name, $fh, $stderr_fh) = @_;
|
|
|
126 |
|
|
|
127 |
return $Codestriker::UNSUPPORTED_OPERATION;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
1;
|