Subversion Repositories DevTools

Rev

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

Rev 1295 Rev 1299
Line 20... Line 20...
20
    # Determine if there are additional parameters required for user
20
    # Determine if there are additional parameters required for user
21
    # authentication.
21
    # authentication.
22
    my @userCmdLine = ();
22
    my @userCmdLine = ();
23
    if (defined($user) && defined($password)) {
23
    if (defined($user) && defined($password)) {
24
        push @userCmdLine, '--username';
24
        push @userCmdLine, '--username';
25
	push @userCmdLine, $user;
25
        push @userCmdLine, $user;
26
	push @userCmdLine, '--password';
26
        push @userCmdLine, '--password';
27
	push @userCmdLine, $password;
27
        push @userCmdLine, $password;
28
    }
28
    }
29
 
29
 
30
    # Sanitise the repository URL.
30
    # Sanitise the repository URL.
31
    $repository_url = sanitise_url_component($repository_url);
31
    $repository_url = sanitise_url_component($repository_url);
32
 
32
 
Line 35... Line 35...
35
    $self->{userCmdLine} = \@userCmdLine;
35
    $self->{userCmdLine} = \@userCmdLine;
36
    $self->{repository_string} = $repository_url;
36
    $self->{repository_string} = $repository_url;
37
    $self->{repository_string} .= ";$user" if defined $user;
37
    $self->{repository_string} .= ";$user" if defined $user;
38
    $self->{repository_string} .= ";$password" if defined $password;
38
    $self->{repository_string} .= ";$password" if defined $password;
39
    if ($self->{repository_string} !~ /^svn:/) {
39
    if ($self->{repository_string} !~ /^svn:/) {
40
	$self->{repository_string} = "svn:" . $self->{repository_string};
40
        $self->{repository_string} = "svn:" . $self->{repository_string};
41
    }
41
    }
42
 
42
 
43
    bless $self, $type;
43
    bless $self, $type;
44
}
44
}
45
 
45
 
Line 68... Line 68...
68
    open($read_stdout_fh, '>', \$read_data);
68
    open($read_stdout_fh, '>', \$read_data);
69
    my @args = ();
69
    my @args = ();
70
    push @args, 'cat';
70
    push @args, 'cat';
71
    push @args, '--non-interactive';
71
    push @args, '--non-interactive';
72
    push @args, '--no-auth-cache';
72
    push @args, '--no-auth-cache';
-
 
73
    push @args, '--trust-server-cert';
73
    push @args, @{ $self->{userCmdLine} };
74
    push @args, @{ $self->{userCmdLine} };
74
    push @args, '--revision';
75
    push @args, '--revision';
75
    push @args, $revision;
76
    push @args, $revision;
76
    push @args, $self->{repository_url} . '/' . $filename;
77
    push @args, $self->{repository_url} . '/' . $filename;
77
    Codestriker::execute_command($read_stdout_fh, undef,
78
    Codestriker::execute_command($read_stdout_fh, undef,
78
				 $Codestriker::svn, @args);
79
                                 $Codestriker::svn, @args);
79
 
80
 
80
    # Process the data for the topic.
81
    # Process the data for the topic.
81
    open($read_stdout_fh, '<', \$read_data);
82
    open($read_stdout_fh, '<', \$read_data);
82
    for (my $i = 1; <$read_stdout_fh>; $i++) {
83
    for (my $i = 1; <$read_stdout_fh>; $i++) {
83
	$_ = Codestriker::decode_topic_text($_);
84
        $_ = Codestriker::decode_topic_text($_);
84
	chop;
85
        chop;
85
	$$content_array_ref[$i] = $_;
86
        $$content_array_ref[$i] = $_;
86
    }
87
    }
87
}
88
}
88
 
89
 
89
# Retrieve the "root" of this repository.
90
# Retrieve the "root" of this repository.
90
sub getRoot ($) {
91
sub getRoot ($) {
Line 97... Line 98...
97
    my ($self, $filename, $revision) = @_;
98
    my ($self, $filename, $revision) = @_;
98
 
99
 
99
    # Lookup the file viewer from the configuration.
100
    # Lookup the file viewer from the configuration.
100
    my $viewer = $Codestriker::file_viewer->{$self->toString()};
101
    my $viewer = $Codestriker::file_viewer->{$self->toString()};
101
    if (! (defined $viewer)) {
102
    if (! (defined $viewer)) {
102
	$viewer = $Codestriker::file_viewer->{$self->{repository_string}};
103
        $viewer = $Codestriker::file_viewer->{$self->{repository_string}};
103
    }
104
    }
104
 
105
 
105
    return (defined $viewer) ? $viewer . "/" . $filename : "";
106
    return (defined $viewer) ? $viewer . "/" . $filename : "";
106
}
107
}
107
 
108
 
Line 115... Line 116...
115
sub is_file_url {
116
sub is_file_url {
116
    my ($self, $url) = @_;
117
    my ($self, $url) = @_;
117
    my $file_url;
118
    my $file_url;
118
 
119
 
119
    eval {
120
    eval {
120
	my @args = ();
121
        my @args = ();
121
	push @args, 'info';
122
        push @args, 'info';
122
	push @args, '--non-interactive';
123
        push @args, '--non-interactive';
123
	push @args, '--no-auth-cache';
124
        push @args, '--no-auth-cache';
-
 
125
        push @args, '--trust-server-cert';
124
	push @args, @{ $self->{userCmdLine} };
126
        push @args, @{ $self->{userCmdLine} };
125
	push @args, '--xml';
127
        push @args, '--xml';
126
	push @args, $self->{repository_url} . '/' . $url;
128
        push @args, $self->{repository_url} . '/' . $url;
127
	my $read_data;
129
        my $read_data;
128
	my $read_stdout_fh = new FileHandle;
130
        my $read_stdout_fh = new FileHandle;
129
	open($read_stdout_fh, '>', \$read_data);
131
        open($read_stdout_fh, '>', \$read_data);
130
 
132
 
131
	Codestriker::execute_command($read_stdout_fh, undef,
133
        Codestriker::execute_command($read_stdout_fh, undef,
132
				     $Codestriker::svn, @args);
134
                                     $Codestriker::svn, @args);
133
	open($read_stdout_fh, '<', \$read_data);
135
        open($read_stdout_fh, '<', \$read_data);
134
	while (<$read_stdout_fh>) {
136
        while (<$read_stdout_fh>) {
135
	    if (/kind\s*\=\s*\"(\w+)\"/) {
137
            if (/kind\s*\=\s*\"(\w+)\"/) {
136
		$file_url = $1 eq "File";
138
                $file_url = $1 eq "File";
137
		last;
139
                last;
138
	    }
140
            }
139
	}
141
        }
140
    };
142
    };
141
    if ($@ || !(defined $file_url)) {
143
    if ($@ || !(defined $file_url)) {
142
	# The above command failed, try using the older method which only works
144
        # The above command failed, try using the older method which only works
143
	# in an English locale.  This supports Subversion 1.2 or earlier
145
        # in an English locale.  This supports Subversion 1.2 or earlier
144
	# releases, which don't support the --xml flag for the info command.
146
        # releases, which don't support the --xml flag for the info command.
145
	my @args = ();
147
        my @args = ();
146
	push @args, 'cat';
148
        push @args, 'cat';
147
	push @args, '--non-interactive';
149
        push @args, '--non-interactive';
148
	push @args, '--no-auth-cache';
150
        push @args, '--no-auth-cache';
-
 
151
        push @args, '--trust-server-cert';
149
	push @args, @{ $self->{userCmdLine} };
152
        push @args, @{ $self->{userCmdLine} };
150
	push @args, '--revision';
153
        push @args, '--revision';
151
	push @args, 'HEAD';
154
        push @args, 'HEAD';
152
	push @args, $self->{repository_url} . '/' . $url;
155
        push @args, $self->{repository_url} . '/' . $url;
153
 
156
 
154
	my $read_stdout_data;
157
        my $read_stdout_data;
155
	my $read_stdout_fh = new FileHandle;
158
        my $read_stdout_fh = new FileHandle;
156
	open($read_stdout_fh, '>', \$read_stdout_data);
159
        open($read_stdout_fh, '>', \$read_stdout_data);
157
 
160
 
158
	my $read_stderr_data;
161
        my $read_stderr_data;
159
	my $read_stderr_fh = new FileHandle;
162
        my $read_stderr_fh = new FileHandle;
160
	open($read_stderr_fh, '>', \$read_stderr_data);
163
        open($read_stderr_fh, '>', \$read_stderr_data);
161
 
164
 
162
	Codestriker::execute_command($read_stdout_fh, $read_stderr_fh,
165
        Codestriker::execute_command($read_stdout_fh, $read_stderr_fh,
163
				     $Codestriker::svn, @args);
166
                                     $Codestriker::svn, @args);
164
	$file_url = 1;
167
        $file_url = 1;
165
	open($read_stderr_fh, '<', \$read_stderr_data);
168
        open($read_stderr_fh, '<', \$read_stderr_data);
166
	while(<$read_stderr_fh>) {
169
        while(<$read_stderr_fh>) {
167
	    if (/^svn:.* refers to a directory/) {
170
            if (/^svn:.* refers to a directory/) {
168
		$file_url = 0;
171
                $file_url = 0;
169
		last;
172
                last;
170
	    }
173
            }
171
	}
174
        }
172
    }
175
    }
173
    
176
    
174
    return $file_url;
177
    return $file_url;
175
}
178
}
176
 
179
 
Line 181... Line 184...
181
 
184
 
182
    # Sanitise the URL, and determine if it refers to a directory or filename.
185
    # Sanitise the URL, and determine if it refers to a directory or filename.
183
    $module_name = sanitise_url_component($module_name);
186
    $module_name = sanitise_url_component($module_name);
184
    my $directory;
187
    my $directory;
185
    if ($self->is_file_url($module_name)) {
188
    if ($self->is_file_url($module_name)) {
186
	$module_name =~ /(.*)\/[^\/]+/;
189
        $module_name =~ /(.*)\/[^\/]+/;
187
	$directory = $1;
190
        $directory = $1;
188
    } else {
191
    } else {
189
	$directory = $module_name;
192
        $directory = $module_name;
190
    }
193
    }
191
 
194
 
192
    # Execute the diff command.
195
    # Execute the diff command.
193
    my $read_stdout_data;
196
    my $read_stdout_data;
194
    my $read_stdout_fh = new FileHandle;
197
    my $read_stdout_fh = new FileHandle;
Line 196... Line 199...
196
 
199
 
197
    my @args = ();
200
    my @args = ();
198
    push @args, 'diff';
201
    push @args, 'diff';
199
    push @args, '--non-interactive';
202
    push @args, '--non-interactive';
200
    push @args, '--no-auth-cache';
203
    push @args, '--no-auth-cache';
-
 
204
    push @args, '--trust-server-cert';
201
    push @args, @{ $self->{userCmdLine} };
205
    push @args, @{ $self->{userCmdLine} };
202
    push @args, '-r';
206
    push @args, '-r';
203
    push @args, $start_tag . ':' . $end_tag;
207
    push @args, $start_tag . ':' . $end_tag;
204
    push @args, '--old';
208
    push @args, '--old';
205
    push @args, $self->{repository_url};
209
    push @args, $self->{repository_url};
206
    push @args, $module_name;
210
    push @args, $module_name;
207
    Codestriker::execute_command($read_stdout_fh, $stderr_fh,
211
    Codestriker::execute_command($read_stdout_fh, $stderr_fh,
208
				 $Codestriker::svn, @args);
212
                                 $Codestriker::svn, @args);
209
 
213
 
210
    open($read_stdout_fh, '<', \$read_stdout_data);
214
    open($read_stdout_fh, '<', \$read_stdout_data);
211
    while(<$read_stdout_fh>) {
215
    while(<$read_stdout_fh>) {
212
	my $line = $_;
216
        my $line = $_;
213
	
217
        
214
	# If the user specifies a path (a branch in Subversion), the
218
        # If the user specifies a path (a branch in Subversion), the
215
	# diff file does not come back with a path rooted from the
219
        # diff file does not come back with a path rooted from the
216
	# repository base making it impossible to pull the entire file
220
        # repository base making it impossible to pull the entire file
217
	# back out. This code attempts to change the diff file on the
221
        # back out. This code attempts to change the diff file on the
218
	# fly to ensure that the full path is present. This is a bug
222
        # fly to ensure that the full path is present. This is a bug
219
	# against Subversion, so eventually it will be fixed, so this
223
        # against Subversion, so eventually it will be fixed, so this
220
	# code can't break when the diff command starts returning the
224
        # code can't break when the diff command starts returning the
221
	# full path.
225
        # full path.
222
	if ($line =~ /^--- / || $line =~ /^\+\+\+ / ||
226
        if ($line =~ /^--- / || $line =~ /^\+\+\+ / ||
223
	    $line =~ /^Index: /) {
227
            $line =~ /^Index: /) {
224
	    # Check if the bug has been fixed.
228
            # Check if the bug has been fixed.
225
	    if ($line =~ /^\+\+\+ $module_name/ == 0 && 
229
            if ($line =~ /^\+\+\+ $module_name/ == 0 && 
226
		$line =~ /^--- $module_name/ == 0 &&
230
                $line =~ /^--- $module_name/ == 0 &&
227
		$line =~ /^Index: $module_name/ == 0) {
231
                $line =~ /^Index: $module_name/ == 0) {
228
		    $line =~ s/^--- /--- $directory\// or
232
                    $line =~ s/^--- /--- $directory\// or
229
		    $line =~ s/^Index: /Index: $directory\// or
233
                    $line =~ s/^Index: /Index: $directory\// or
230
		    $line =~ s/^\+\+\+ /\+\+\+ $directory\//;
234
                    $line =~ s/^\+\+\+ /\+\+\+ $directory\//;
231
	    }
235
            }
232
	}
236
        }
233
 
237
 
234
	print $stdout_fh $line;
238
        print $stdout_fh $line;
235
    }
239
    }
236
 
240
 
237
    return $Codestriker::OK;
241
    return $Codestriker::OK;
238
}
242
}
239
 
243