Subversion Repositories DevTools

Rev

Rev 1308 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 Dynamic Views.
9
# Contributed by "Avinandan Sengupta" <avinna_seng at users.sourceforge.net>.
10
 
11
package Codestriker::Repository::ClearCaseDynamic;
12
 
13
use strict;
14
use File::Spec;
1312 dpurdie 15
use Carp;
1293 dpurdie 16
 
17
# Put this in an eval block so that this becomes an optional dependency for
18
# those people who don't use this module.
19
eval("use ClearCase::CtCmd");
20
 
21
# Constructor.
22
# viewname:vobs_dir - absolute path to the vobs dir
23
#                     (mount point on unix/drive letter on windows)
24
# This dynamic view should be mounted on the same host on which Codestriker
25
# is running.
26
sub new ($$)
27
{
28
    my ($type, $url) = @_;
29
 
30
    my $self = {};
31
 
32
    $url =~ /([^:]*):(.*)/;
33
    $self->{dynamic_view_name} = $1;
34
    $self->{vobs_dir} = $2;
35
 
36
    bless $self, $type;
37
}
38
 
39
# Retrieve the data corresponding to $filename and $revision.  Store each line
40
# into $content_array_ref.
41
sub retrieve ($$$\$)
42
{
43
    my ($self, $filename, $revision, $content_array_ref) = @_;
44
    my $error_msg = '';
45
    my $clearcase;
46
    my $setview;
47
 
48
    # Check if we are running under Windows, which doesn't support
49
    # the setview
50
    if (! Codestriker::is_windows()) {
51
	$setview = 'setview';
52
    } else {
53
	$setview = 'startview';
54
    }
55
 
56
    {
57
	# Set the current view to the repository's dynamic view name.
58
	$clearcase = ClearCase::CtCmd->new();
59
	(my $status, my $stdout, $error_msg) =
60
	    $clearcase->exec($setview, $self->{dynamic_view_name});
61
 
62
	# Check the result of the setview command.
63
	if ($status) {
64
	    $error_msg = "Failed to open view: " . $self->{dynamic_view_name} .
65
		": $error_msg\n";
1312 dpurdie 66
	    croak ("$error_msg\n");
1293 dpurdie 67
	    return $error_msg;
68
	}
69
    }
70
 
71
    # Execute the remaining code in an eval block to ensure the endview
72
    # command is always called.
73
    eval {
74
	# Construct the filename in the view, based on its path and
75
	# revision.
76
	my $full_element_name = File::Spec->catfile($self->{vobs_dir},
77
						    $filename);
78
	if (defined($revision) && length($revision) > 0) {
79
	    $full_element_name = $full_element_name . '@@' . $revision;
80
	}
81
 
82
	# Load the file directly into the given array.
83
	open (CONTENTFILE, "$full_element_name")
84
	    || die "Couldn't open file: $full_element_name: $!";
85
	for (my $i = 1; <CONTENTFILE>; $i++) {
86
	    chop;
87
	    $$content_array_ref[$i] = $_;
88
	}
89
	close CONTENTFILE;
90
    };
91
    if ($@) {
92
	# Something went wrong in the above code, record the error message
93
	# and continue to ensure the view is closed.
94
	$error_msg = $@;
1312 dpurdie 95
	croak "$error_msg\n";
1293 dpurdie 96
    }
97
 
98
    # Close the view.
99
    {
100
	(my $status, my $stdout, $error_msg) =
101
	    $clearcase->exec('endview', $self->{dynamic_view_name});
102
	if ($status) {
103
	    $error_msg = "Failed to close view: " . $self->{dynamic_view_name} .
104
		": $error_msg\n";
1312 dpurdie 105
	    croak "$error_msg\n";
1293 dpurdie 106
	}
107
    }
108
 
109
    return $error_msg;
110
}
111
 
112
# Retrieve the "root" of this repository.
113
sub getRoot ($) {
114
    my ($self) = @_;
115
    return $self->{vobs_dir};
116
}
117
 
118
# Return a URL which views the specified file and revision.
119
sub getViewUrl ($$$) {
120
    my ($self, $filename, $revision) = @_;
121
 
122
    # Lookup the file viewer from the configuration.
123
    my $viewer = $Codestriker::file_viewer->{$self->toString()};
124
    return (defined $viewer) ? $viewer . "/" . $filename : "";
125
}
126
 
127
# Return a string representation of this repository.
128
sub toString ($) {
129
    my ($self) = @_;
130
    return "clearcase:dyn:" . $self->{dynamic_view_name} .
131
	":" . $self->{vobs_dir};
132
}
133
 
134
# Given a start tag, end tag and a module name, store the text into
135
# the specified file handle.  If the size of the diff goes beyond the
136
# limit, then return the appropriate error code.
137
sub getDiff ($$$$$$) {
138
    my ($self, $start_tag, $end_tag, $module_name, $fh, $stderr_fh) = @_;
139
 
140
    return $Codestriker::UNSUPPORTED_OPERATION;
141
}
142
 
143
1;