Subversion Repositories DevTools

Rev

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

Rev 1295 Rev 1299
Line 22... Line 22...
22
    # Array of results found.
22
    # Array of results found.
23
    my @result = ();
23
    my @result = ();
24
 
24
 
25
    my $line = <$fh>;
25
    my $line = <$fh>;
26
    while (defined($line)) {
26
    while (defined($line)) {
27
	# Values associated with the diff.
27
        # Values associated with the diff.
28
	my $entry_type;
28
        my $entry_type;
29
	my $revision;
29
        my $revision;
30
	my $filename = "";
30
        my $filename = "";
31
	my $old_linenumber = -1;
31
        my $old_linenumber = -1;
32
	my $new_linenumber = -1;
32
        my $new_linenumber = -1;
33
	my $binary = 0;
33
        my $binary = 0;
34
	my $diff = "";
34
        my $diff = "";
35
 
35
 
36
	# Skip whitespace.
36
        # Skip whitespace.
37
	while (defined($line) && $line =~ /^\s*$/o) {
37
        while (defined($line) && $line =~ /^\s*$/o) {
38
	    $line = <$fh>;
38
            $line = <$fh>;
39
	}
39
        }
40
	return @result unless defined $line;
40
        return @result unless defined $line;
41
 
41
 
42
	# For SVN diffs, the start of the diff block is the Index line.
42
        # For SVN diffs, the start of the diff block is the Index line.
43
	# For SVN look diffs, the start of the diff block contains the change type.
43
        # For SVN look diffs, the start of the diff block contains the change type.
44
	# Also check for presence of property set blocks.
44
        # Also check for presence of property set blocks.
45
	while ($line =~ /^.*Property changes on: .*$/o) {
45
        while ($line =~ /^.*Property changes on: .*$/o) {
46
	    $line = <$fh>;
46
            $line = <$fh>;
47
	    return () unless defined $line &&
47
            return () unless defined $line &&
48
		$line =~ /^___________________________________________________________________$/o;
48
              $line =~ /^___________________________________________________________________$/o;
49
	    
49
 
50
	    # Keep reading until we either get to an Index: line, a property
50
            # Keep reading until we either get to the separator line or end of file.
51
	    # block, an Added/Deleted/Modified lines or the end of file.
51
            while (defined $line &&
52
	    while (defined $line &&
52
                   $line !~ /^===================================================================$/o) {
53
		   $line !~ /^.*Index:/o &&
53
                if ($line =~ /^.*(Index|Added|Modified|Copied|Deleted): (.*)$/o) {
54
		   $line !~ /^.*Added:/o &&
54
                    $entry_type = $1;
55
		   $line !~ /^.*Deleted:/o &&
55
                    $filename = $2;
56
		   $line !~ /^.*Modified:/o &&
56
                }
57
		   $line !~ /^.*Copied:/o &&
57
                $line = <$fh>;
58
		   $line !~ /^.*Property changes on:/o) {
58
            }
59
		$line = <$fh>;
59
 
60
	    }
60
            if (!defined $line) {
61
	    
61
                # End of file has been reached, return what we have parsed.
62
	    if (! defined $line) {
62
                return @result;
63
		# End of file has been reached, return what we have parsed.
63
            }
64
		return @result;
64
        }
65
	    }
65
 
66
	}
66
        if ($line =~ /^.*(Index|Added|Modified|Copied|Deleted): (.*)$/o) {
67
 
67
            $entry_type = $1;
68
	return () unless
68
            $filename = $2;
69
	    $line =~ /^.*(Index|Added|Modified|Copied|Deleted): (.*)$/o;
69
            $line = <$fh>;
70
	$entry_type = $1;
70
        }
71
	$filename = $2;
71
 
72
	$line = <$fh>;
72
        # The separator line appears next.
73
 
73
        return () unless defined $line && $line =~ /^===================================================================$/o;
74
	# The separator line appears next.
74
        $line = <$fh>;
75
	return () unless defined $line && $line =~ /^===================================================================$/o;
75
 
76
	$line = <$fh>;
76
        # Check if this is a file entry with no content.  If so, skip it.
77
 
77
        next if ! defined $line || $line =~ /^\s*$/o;
78
	# Check if the delta represents a binary file.
78
 
79
	if ($line =~ /^Cannot display: file marked as a binary type\./o ||
79
        # Check if the delta represents a binary file.
80
	    $line =~ /^\(Binary files differ\)/o) {
80
        if ($line =~ /^Cannot display: file marked as a binary type\./o ||
81
 
81
            $line =~ /^\(Binary files differ\)/o) {
82
	    # If it is a new binary file, there will be some lines before
82
 
83
	    # the next Index: line, or end of file.  In other cases, it is
83
            # If it is a new binary file, there will be some lines before
84
	    # impossible to know whether the file is being modified or
84
            # the next Index: line, or end of file.  In other cases, it is
85
	    # removed, and what revision it is based off.
85
            # impossible to know whether the file is being modified or
86
	    $line = <$fh>;
86
            # removed, and what revision it is based off.
87
	    my $count = 0;
87
            $line = <$fh>;
88
	    while (defined $line && $line !~ /^Index|Added|Modified|Deleted/o) {
88
            my $count = 0;
89
		$line = <$fh>;
89
            while (defined $line && $line !~ /^Index|Added|Modified|Deleted|Property changes on:/o) {
90
		$count++;
90
                $line = <$fh>;
91
	    }
91
                $count++;
92
 
92
            }
93
	    my $chunk = {};
93
 
94
	    $chunk->{filename} = $filename;
94
            my $chunk = {};
95
	    if ($entry_type eq "Index") {
95
            $chunk->{filename} = $filename;
96
		$chunk->{revision} = $count > 0 ? $Codestriker::ADDED_REVISION :
96
            if ($entry_type eq "Index") {
97
		    $Codestriker::PATCH_REVISION;
97
                $chunk->{revision} = $count > 0 ? $Codestriker::ADDED_REVISION :
98
	    } elsif ($entry_type eq "Added") {
98
                  $Codestriker::PATCH_REVISION;
99
		$chunk->{revision} = $Codestriker::ADDED_REVISION;
99
            } elsif ($entry_type eq "Added") {
100
	    } elsif ($entry_type eq "Deleted") {
100
                $chunk->{revision} = $Codestriker::ADDED_REVISION;
101
		$chunk->{revision} = $Codestriker::REMOVED_REVISION;
101
            } elsif ($entry_type eq "Deleted") {
102
	    } else {
102
                $chunk->{revision} = $Codestriker::REMOVED_REVISION;
103
		$chunk->{revision} = $Codestriker::PATCH_REVISION;
103
            } else {
104
	    }
104
                $chunk->{revision} = $Codestriker::PATCH_REVISION;
105
	    $chunk->{old_linenumber} = -1;
105
            }
106
	    $chunk->{new_linenumber} = -1;
106
            $chunk->{old_linenumber} = -1;
107
	    $chunk->{binary} = 1;
107
            $chunk->{new_linenumber} = -1;
108
	    $chunk->{text} = "";
108
            $chunk->{binary} = 1;
109
	    $chunk->{description} = "";
109
            $chunk->{text} = "";
110
	    $chunk->{repmatch} = 1;
110
            $chunk->{description} = "";
111
	    push @result, $chunk;
111
            $chunk->{repmatch} = 1;
112
	} else {
112
            push @result, $chunk;
113
	    # Try and read the base revision this change is against,
113
        } else {
114
	    # while handling new and removed files.
114
            # Try and read the base revision this change is against,
115
	    my $base_revision = -1;
115
            # while handling new and removed files.
116
	    if ($line =~ /^\-\-\- .*\s.* (\d+)/io) {
116
            my $base_revision = -1;
117
		$base_revision = $1;
117
            if ($line =~ /^\-\-\- .*\s.*\(.*?(\d+)\)/io) {
118
	    } elsif ($line !~ /^\-\-\- .*/io) {
118
                $base_revision = $1;
119
		return ();
119
            } elsif ($line !~ /^\-\-\- .*/io) {
120
	    }
120
                # This appears to be a new entry with no data - construct
121
 
121
                # an appropriate entry.
122
	    # Make sure the +++ line is present next.
122
                my $chunk = {};
123
	    $line = <$fh>;
123
                $chunk->{filename} = $filename;
124
	    return () unless defined $line;
124
                $chunk->{revision} = $Codestriker::ADDED_REVISION;
125
	    if ($line !~ /^\+\+\+ .*/io) {
125
                $chunk->{old_linenumber} = -1;
126
		return ();
126
                $chunk->{new_linenumber} = -1;
127
	    }
127
                $chunk->{binary} = 1;
128
 
128
                $chunk->{text} = "";
129
	    # Now parse the unidiff chunks.
129
                $chunk->{description} = "";
130
	    my @file_diffs = Codestriker::FileParser::UnidiffUtils->
130
                $chunk->{repmatch} = 1;
131
		read_unidiff_text($fh, $filename, $base_revision, 1);
131
                push @result, $chunk;
132
	    
132
                next;
133
	    # If $base_revision is -1, and old_linenumber is 0, then
133
            }
134
	    # the file is added.  If $base_revision is -1, and
134
 
135
	    # new_linenumber is 0, then the file is removed.  Update
135
            # Make sure the +++ line is present next.
136
	    # any chunks to indicate this.
136
            $line = <$fh>;
137
	    if ($base_revision == -1) {
137
            return () unless defined $line;
138
		for (my $i = 0; $i <= $#file_diffs; $i++) {
138
            if ($line !~ /^\+\+\+ .*/io) {
139
		    my $delta = $file_diffs[$i];
139
                return ();
140
		    if ($delta->{old_linenumber} == 0) {
140
            }
141
			$delta->{revision} = $Codestriker::ADDED_REVISION;
141
 
142
		    } elsif ($delta->{new_linenumber} == 0) {
142
            # Now parse the unidiff chunks.
143
			$delta->{revision} = $Codestriker::REMOVED_REVISION;
143
            my @file_diffs = Codestriker::FileParser::UnidiffUtils->
144
		    }
144
              read_unidiff_text($fh, $filename, $base_revision, 1);
145
		}
145
 
146
	    }
146
            # If $base_revision is -1, and old_linenumber is 0, then
147
		
147
            # the file is added.  If $base_revision is -1, and
148
	    push @result, @file_diffs;
148
            # new_linenumber is 0, then the file is removed.  Update
149
 
149
            # any chunks to indicate this.
150
	    # Read the next line.
150
            if ($base_revision == -1) {
151
	    $line = <$fh>;
151
                for (my $i = 0; $i <= $#file_diffs; $i++) {
152
	}
152
                    my $delta = $file_diffs[$i];
-
 
153
                    if ($delta->{old_linenumber} == 0) {
-
 
154
                        $delta->{revision} = $Codestriker::ADDED_REVISION;
-
 
155
                    } elsif ($delta->{new_linenumber} == 0) {
-
 
156
                        $delta->{revision} = $Codestriker::REMOVED_REVISION;
-
 
157
                    }
-
 
158
                }
-
 
159
            }
-
 
160
 
-
 
161
            push @result, @file_diffs;
-
 
162
 
-
 
163
            # Read the next line.
-
 
164
            $line = <$fh>;
-
 
165
        }
153
    }
166
    }
154
 
167
 
155
    # Return the found diff chunks.
168
    # Return the found diff chunks.
156
    return @result;
169
    return @result;
157
}
170
}
158
	
171
 
159
1;
172
1;