Subversion Repositories DevTools

Rev

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