forked from MonsterClosetGames/SSIndexPlasticSCM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplasticscm.pm
More file actions
254 lines (207 loc) · 8.54 KB
/
plasticscm.pm
File metadata and controls
254 lines (207 loc) · 8.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# -----------------------------------------------------------------------------
# PlasticSCM.pm
#
# Contributed by Patrice Beauvais
# Monster Closet Games
#
# Source Server indexing module for PlasticSCM
# -----------------------------------------------------------------------------
package PLASTICSCM;
require Exporter;
use strict;
our %EXPORT_TAGS = ( 'all' => [ qw() ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
our $VERSION = '0.1';
use Data::Dumper;
# -----------------------------------------------------------------------------
# Simple subs to make it clear when we're testing for BOOL values
# -----------------------------------------------------------------------------
sub TRUE {return(1);} # BOOLEAN TRUE
sub FALSE {return(0);} # BOOLEAN FALSE
# -----------------------------------------------------------------------------
# Create a new blessed reference that will maintain state for this instance of
# indexing
# -----------------------------------------------------------------------------
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless($self, $class);
#
# The command to use for talking to the server. We don't allow this
# to be overridden at the command line.
#
$$self{'PLASTICSCM_CMD'} = "CM.exe";
# Allow environment overrides for these settings.
$$self{'PLASTICSCMCHANGESET'} = $ENV{'PLASTICSCMCHANGESET'} if (defined $ENV{'PLASTICSCMCHANGESET'});
$$self{'PLASTICREPOSITORY'} = $ENV{'PLASTICREPOSITORY'} if (defined $ENV{'PLASTICREPOSITORY'});
$$self{'PLASTICSERVER'} = $ENV{'PLASTICSERVER'} if (defined $ENV{'PLASTICSERVER'});
# Block for option parsing.
PARSEOPTIONS: {
my @unused_opts;
my @opt;
foreach (@ARGV) {
# handle command options
if (substr($_, 0, 1) =~ /^[\/-]$/) {
# options that set values
if ( (@opt = split(/=/, $_))==2 ) {
block: {
$$self{'PLASTICSCMCHANGESET'} = $opt[1], last if ( uc substr($opt[0], 1) eq "CHANGESET" );
$$self{'PLASTICREPOSITORY'} = $opt[1], last if ( uc substr($opt[0], 1) eq "REPOSITORY" );
$$self{'PLASTICSERVER'} = $opt[1], last if ( uc substr($opt[0], 1) eq "SERVER" );
# Remember this was unused
push(@unused_opts, $_);
1;
}
# options that are just flags
}
} else {
# Remember this was unused
push(@unused_opts, $_);
}
}
# Fixup @ARGV to only contained unused options so SSIndex.cmd
# can warn the user about them if necessary.
@ARGV = @unused_opts;
}
return($self);
}
# -----------------------------------------------------------------------------
# Display module internal option state
# -----------------------------------------------------------------------------
sub DisplayVariableInfo {
my $self = shift;
::status_message("%-15s: %s\n",
"PlasticSCM Executable",
$$self{'PLASTICSCM_CMD'});
::status_message("%-15s: %s\n",
"PlasticSCM Changeset",
$$self{'PLASTICSCMCHANGESET'} ? $$self{'PLASTICSCMCHANGESET'} : "<N/A>");
::status_message("%-15s: %s\n",
"PlasticSCM Repository",
$$self{'PLASTICREPOSITORY'} ? $$self{'PLASTICREPOSITORY'} : "<N/A>");
::status_message("%-15s: %s\n",
"PlasticSCM Server",
$$self{'PLASTICSERVER'} ? $$self{'PLASTICSERVER'} : "<N/A>");
}
# -----------------------------------------------------------------------------
# Given our init data and a local source path, create a lookup table that can
# return individual stream data for each source file.
# -----------------------------------------------------------------------------
sub GatherFileInformation {
my $self = shift;
my $SourceRoot = shift;
my $ServerRefs = shift;
my ($Server, $Root, $PreferredAlias, $PreferredServer);
# This will return a line with the server path and the latest revid
my @Files = `$$self{'PLASTICSCM_CMD'} ls -R --format="{path}|{revid}|{repspec}" --tree=$$self{'PLASTICSCMCHANGESET'}\@$$self{'PLASTICREPOSITORY'}\@$$self{'PLASTICSERVER'} 2>NUL`;
# For each file, calculate a local file path for the lookup table.
foreach (@Files) {
chomp $_;
my @splitResult = split(/\|/, $_);
my $LocalFile = @splitResult[0];
my $LocalFileWithPath = ($SourceRoot . $LocalFile);
$LocalFileWithPath=~ s/\//\\/g;
my $FileRevisionId = @splitResult[1];
my $FileRepSpec = @splitResult[2];
@{$$self{'FILE_LOOKUP_TABLE'}{lc $LocalFileWithPath}} = ( { }, "$LocalFileWithPath*$$self{'PLASTICREPOSITORY'}*$LocalFile*$FileRevisionId*$FileRepSpec");
}
}
# -----------------------------------------------------------------------------
# Return ths SRCSRV stream data for a single file.
# -----------------------------------------------------------------------------
sub GetFileInfo {
my $self = shift;
my $file = shift;
# We stored the necessary information when GatherFileInformation() was
# called so we just need to return that information.
if ( defined $$self{'FILE_LOOKUP_TABLE'}{lc $file} ) {
return( @{$$self{'FILE_LOOKUP_TABLE'}{lc $file}} );
} else {
return(undef);
}
}
# -----------------------------------------------------------------------------
# The long name that should be written the SRCSRV stream to describe
# the source control system being indexed.
# -----------------------------------------------------------------------------
sub LongName {
return("PlasticSCM");
}
# -----------------------------------------------------------------------------
# Set the debug level for output.
# -----------------------------------------------------------------------------
sub SetDebugMode {
my $self = shift;
}
# -----------------------------------------------------------------------------
# Return the SCS specific stream variables.
# -----------------------------------------------------------------------------
sub SourceStreamVariables {
my $self = shift;
my @stream;
push(@stream, "PLASTICSCM_EXTRACT_CMD=cm.exe cat ".
"revid:%var4%@%var5%".
"> \"%PLASTICSCM_EXTRACT_TARGET%\"");
push(@stream, "PLASTICSCM_EXTRACT_TARGET=".
"%targ%\\%var2%\\%fnbksl%(%var3%)\\%var4%\\%fnfile%(%var1%)");
return(@stream);
}
# -----------------------------------------------------------------------------
# Loads previously saved file information.
# -----------------------------------------------------------------------------
sub LoadFileInfo {
my $self = shift;
my $dir = shift;
if ( -e "$dir\\plasticscm_files.dat" ) {
our $FileData1;
require "$dir\\plasticscm_files.dat";
$$self{'FILE_LOOKUP_TABLE'} = $FileData1;
} else {
::status_message("No PlasticSCM information saved in $dir.\n");
}
return();
}
# -----------------------------------------------------------------------------
# Saves current file information.
# -----------------------------------------------------------------------------
sub SaveFileInfo {
my $self = shift;
my $dir = shift;
my $fh;
if ( open($fh, ">$dir\\plasticscm_files.dat") ) {
$Data::Dumper::Varname = "FileData";
$Data::Dumper::Indent = 0;
print $fh Dumper($$self{'FILE_LOOKUP_TABLE'});
close($fh);
} else {
::status_message("Failed to save data to $dir.\n");
}
return();
}
# -----------------------------------------------------------------------------
# Simple usage ('-?')
# -----------------------------------------------------------------------------
sub SimpleUsage {
print<<PLASTICSCM_SIMPLE_USAGE;
PlasticSCM specific settings:
NAME SWITCH ENV. VAR Default
-----------------------------------------------------------------------------
A) Changeset CHANGESET PLASTICSCMCHANGESET <n/a>
B) Repository REPOSITORY PLASTICREPOSITORY <n/a>
C) Server SERVER PLASTICSERVER <n/a>
PLASTICSCM_SIMPLE_USAGE
}
# -----------------------------------------------------------------------------
# Verbose usage ('-??')
# -----------------------------------------------------------------------------
sub VerboseUsage {
print<<PLASTICSCM_VERBOSE_USAGE;
(A) Changeset - The changeset to sync to
(B) Repository - The name of the repository in PlasticSCM
(C) Server - The server address:port
PLASTICSCM_VERBOSE_USAGE
}
1;
__END__