Subversion Repositories DevTools

Rev

Rev 1299 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1299 Rev 1300
Line 14... Line 14...
14
use Fatal qw / open close /;
14
use Fatal qw / open close /;
15
 
15
 
16
# Constructor, which takes as a parameter the repository url.
16
# Constructor, which takes as a parameter the repository url.
17
sub new {
17
sub new {
18
    my ($type, $repository_url, $user, $password) = @_;
18
    my ($type, $repository_url, $user, $password) = @_;
19
 
-
 
20
    # Determine if there are additional parameters required for user
19
    # Determine if there are additional parameters required for user
21
    # authentication.
20
    # authentication.
22
    my @userCmdLine = ();
21
    my @userCmdLine = ();
23
    if (defined($user) && defined($password)) {
22
    if (defined($user) && defined($password)) {
24
        push @userCmdLine, '--username';
23
        push @userCmdLine, '--username';
Line 180... Line 179...
180
# The getDiff operation, pull out a change set based on the start and end 
179
# The getDiff operation, pull out a change set based on the start and end 
181
# revision number, confined to the specified moduled_name.
180
# revision number, confined to the specified moduled_name.
182
sub getDiff {
181
sub getDiff {
183
    my ($self, $start_tag, $end_tag, $module_name, $stdout_fh, $stderr_fh) = @_;
182
    my ($self, $start_tag, $end_tag, $module_name, $stdout_fh, $stderr_fh) = @_;
184
 
183
 
-
 
184
 
-
 
185
    #
-
 
186
    #   Check Module Name
-
 
187
    #
-
 
188
    my @errors;
-
 
189
    $self->{getDiffError} = undef;
-
 
190
    unless ( $module_name =~ m~/(tags|branches|trunk)(/|$)~ )
-
 
191
    {
-
 
192
        push @errors,
-
 
193
            "Module does not contain 'tags', 'trunk' or 'branches'",
-
 
194
            "Module must specify a development branch or trunk";
-
 
195
    }
-
 
196
 
-
 
197
    if ( $module_name =~ m~^/~ )
-
 
198
    {
-
 
199
        push @errors, "Module must not start with a '/'"
-
 
200
    }
-
 
201
 
-
 
202
 
-
 
203
    if ( @errors )
-
 
204
    {
-
 
205
        $self->{getDiffError} = join ('<br>', @errors);
-
 
206
        return $Codestriker::OK;
-
 
207
    }
-
 
208
 
-
 
209
 
185
    # Sanitise the URL, and determine if it refers to a directory or filename.
210
    # Sanitise the URL, and determine if it refers to a directory or filename.
186
    $module_name = sanitise_url_component($module_name);
211
    $module_name = sanitise_url_component($module_name);
187
    my $directory;
212
    my $directory;
188
    if ($self->is_file_url($module_name)) {
213
    if ($self->is_file_url($module_name)) {
189
        $module_name =~ /(.*)\/[^\/]+/;
214
        $module_name =~ /(.*)\/[^\/]+/;
Line 195... Line 220...
195
    # Execute the diff command.
220
    # Execute the diff command.
196
    my $read_stdout_data;
221
    my $read_stdout_data;
197
    my $read_stdout_fh = new FileHandle;
222
    my $read_stdout_fh = new FileHandle;
198
    open($read_stdout_fh, '>', \$read_stdout_data);
223
    open($read_stdout_fh, '>', \$read_stdout_data);
199
 
224
 
-
 
225
    #
-
 
226
    #   Determine the commad to use
-
 
227
    #   If user provides two numbers, then module is a full path
-
 
228
    #   Otherwise assume that the user has provided named tags
-
 
229
    #
-
 
230
    #
200
    my @args = ();
231
    my @args = ();
201
    push @args, 'diff';
232
    push @args, 'diff';
202
    push @args, '--non-interactive';
233
    push @args, '--non-interactive';
203
    push @args, '--no-auth-cache';
234
    push @args, '--no-auth-cache';
204
    push @args, '--trust-server-cert';
235
    push @args, '--trust-server-cert';
205
    push @args, @{ $self->{userCmdLine} };
236
    push @args, @{ $self->{userCmdLine} };
-
 
237
 
-
 
238
    if ( $start_tag =~ m~^\d+$~ )
-
 
239
    {
-
 
240
        my $rtag = $start_tag;
-
 
241
        $rtag .= (':' . $end_tag) if $end_tag;
206
    push @args, '-r';
242
        push @args, '-r';
207
    push @args, $start_tag . ':' . $end_tag;
243
        push @args, $rtag;
208
    push @args, '--old';
244
        push @args, '--old';
209
    push @args, $self->{repository_url};
245
        push @args, $self->{repository_url};
210
    push @args, $module_name;
246
        push @args, $module_name;
-
 
247
    }
-
 
248
    else
-
 
249
    {
-
 
250
        my $clean_module_name = $module_name;
-
 
251
        $clean_module_name =~ s~/trunk$~~;
-
 
252
        $clean_module_name =~ s~/branches/.*~~;
-
 
253
        $clean_module_name =~ s~/tags/.*~~;
-
 
254
        push @args, '--old';
-
 
255
        push @args, join ('/', $self->{repository_url}, $clean_module_name, 'tags', $start_tag);
-
 
256
 
-
 
257
        if ( $end_tag )
-
 
258
        {
-
 
259
            push @args, '--new';
-
 
260
            push @args, join ('/', $self->{repository_url}, $clean_module_name, 'tags', $end_tag);
-
 
261
        }
-
 
262
        else
-
 
263
        {
-
 
264
            push @args, '--new';
-
 
265
            push @args, join ('/', $self->{repository_url}, $module_name);
-
 
266
        }
-
 
267
    }
211
    Codestriker::execute_command($read_stdout_fh, $stderr_fh,
268
    Codestriker::execute_command($read_stdout_fh, $stderr_fh,
212
                                 $Codestriker::svn, @args);
269
                                 $Codestriker::svn, @args);
213
 
270
 
214
    open($read_stdout_fh, '<', \$read_stdout_data);
271
    my $rv = open($read_stdout_fh, '<', \$read_stdout_data);
-
 
272
    if ( $rv ) {
215
    while(<$read_stdout_fh>) {
273
        while(<$read_stdout_fh>) {
216
        my $line = $_;
274
            my $line = $_;
217
        
275
        
218
        # If the user specifies a path (a branch in Subversion), the
276
            # If the user specifies a path (a branch in Subversion), the
219
        # diff file does not come back with a path rooted from the
277
            # diff file does not come back with a path rooted from the
220
        # repository base making it impossible to pull the entire file
278
            # repository base making it impossible to pull the entire file
221
        # back out. This code attempts to change the diff file on the
279
            # back out. This code attempts to change the diff file on the
222
        # fly to ensure that the full path is present. This is a bug
280
            # fly to ensure that the full path is present. This is a bug
223
        # against Subversion, so eventually it will be fixed, so this
281
            # against Subversion, so eventually it will be fixed, so this
224
        # code can't break when the diff command starts returning the
282
            # code can't break when the diff command starts returning the
225
        # full path.
283
            # full path.
226
        if ($line =~ /^--- / || $line =~ /^\+\+\+ / ||
284
            if ($line =~ /^--- / || $line =~ /^\+\+\+ / ||
227
            $line =~ /^Index: /) {
285
                $line =~ /^Index: /) {
228
            # Check if the bug has been fixed.
286
                # Check if the bug has been fixed.
229
            if ($line =~ /^\+\+\+ $module_name/ == 0 && 
287
                if ($line =~ /^\+\+\+ $module_name/ == 0 && 
230
                $line =~ /^--- $module_name/ == 0 &&
288
                    $line =~ /^--- $module_name/ == 0 &&
231
                $line =~ /^Index: $module_name/ == 0) {
289
                    $line =~ /^Index: $module_name/ == 0) {
232
                    $line =~ s/^--- /--- $directory\// or
290
                        $line =~ s/^--- /--- $directory\// or
233
                    $line =~ s/^Index: /Index: $directory\// or
291
                        $line =~ s/^Index: /Index: $directory\// or
234
                    $line =~ s/^\+\+\+ /\+\+\+ $directory\//;
292
                        $line =~ s/^\+\+\+ /\+\+\+ $directory\//;
-
 
293
                }
235
            }
294
            }
236
        }
-
 
237
 
295
 
238
        print $stdout_fh $line;
296
            print $stdout_fh $line;
-
 
297
        }
239
    }
298
    }
240
 
299
 
241
    return $Codestriker::OK;
300
    return $Codestriker::OK;
242
}
301
}
243
 
302