3
* ====================================================================
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
20
* ====================================================================
24
package org.apache.subversion.javahl.types;
26
import java.util.ArrayList;
27
import java.util.HashMap;
28
import java.util.List;
31
import java.util.StringTokenizer;
33
import org.apache.subversion.javahl.SubversionException;
36
* Merge history for a path.
38
public class Mergeinfo implements java.io.Serializable
40
// Update the serialVersionUID when there is a incompatible change
41
// made to this class. See any of the following, depending upon
43
// http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/version.doc7.html
44
// http://java.sun.com/j2se/1.4/pdf/serial-spec.pdf
45
// http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/version.html#6678
46
// http://java.sun.com/javase/6/docs/platform/serialization/spec/version.html#6678
47
private static final long serialVersionUID = 1L;
50
* A mapping of repository-relative paths to a list of revision
53
private Map<String, List<RevisionRange>> mergeSources;
57
mergeSources = new HashMap<String, List<RevisionRange>>();
61
* Create and populate an instance using the contents of the
62
* <code>svn:mergeinfo</code> property.
63
* @param mergeinfo <code>svn:mergeinfo</code> property value.
65
public Mergeinfo(String mergeinfo)
68
this.loadFromMergeinfoProperty(mergeinfo);
72
* Add one or more RevisionRange objects to merge info. If the
73
* merge source is already stored, the list of revisions is
75
* @param mergeSrc The merge source URL.
76
* @param ranges RevisionRange objects to add.
77
* @throws SubversionException If range list contains objects of
78
* type other than RevisionRange.
80
public void addRevisions(String mergeSrc, List<RevisionRange> ranges)
82
for (RevisionRange range : ranges)
83
addRevisionRange(mergeSrc, range);
87
* Add a revision range to the merged revisions for a path. If
88
* the merge source already has associated revision ranges, add
89
* the revision range to the existing list.
90
* @param mergeSrc The merge source URL.
91
* @param range The revision range to add.
93
public void addRevisionRange(String mergeSrc, RevisionRange range)
95
List<RevisionRange> revisions = this.getRevisions(mergeSrc);
96
if (revisions == null)
97
revisions = new ArrayList<RevisionRange>();
99
this.setRevisionList(mergeSrc, revisions);
103
* Get the merge source URLs.
104
* @return The merge source URLs.
106
public Set<String> getPaths()
108
return mergeSources.keySet();
112
* Get the revision ranges for the specified merge source URL.
113
* @param mergeSrc The merge source URL, or <code>null</code>.
114
* @return List of RevisionRange objects, or <code>null</code>.
116
public List<RevisionRange> getRevisions(String mergeSrc)
118
if (mergeSrc == null)
120
return mergeSources.get(mergeSrc);
124
* Get the RevisionRange objects for the specified merge source URL
125
* @param mergeSrc The merge source URL, or <code>null</code>.
126
* @return Array of RevisionRange objects, or <code>null</code>.
128
public List<RevisionRange> getRevisionRange(String mergeSrc)
130
return this.getRevisions(mergeSrc);
134
* Parse the <code>svn:mergeinfo</code> property to populate the
135
* merge source URLs and revision ranges of this instance.
136
* @param mergeinfo <code>svn:mergeinfo</code> property value.
138
public void loadFromMergeinfoProperty(String mergeinfo)
140
if (mergeinfo == null)
142
StringTokenizer st = new StringTokenizer(mergeinfo, "\n");
143
while (st.hasMoreTokens())
145
parseMergeinfoLine(st.nextToken());
150
* Parse a merge source line from a <code>svn:mergeinfo</code>
151
* property value (e.g.
152
* <code>"/trunk:1-100,104,108,110-115"</code>).
154
* @param line A line of merge info for a single merge source.
156
private void parseMergeinfoLine(String line)
158
int colon = line.indexOf(':');
161
String pathElement = line.substring(0, colon);
162
String revisions = line.substring(colon + 1);
163
parseRevisions(pathElement, revisions);
168
* Parse the revisions in a merge info line into RevisionRange
169
* objects and adds each of them to the internal Map
170
* (e.g. <code>"1-100,104,108,110-115"</code>)
172
* @param path The merge source path.
173
* @param revisions A textual representation of the revision ranges.
175
private void parseRevisions(String path, String revisions)
177
List<RevisionRange> rangeList = this.getRevisions(path);
178
StringTokenizer st = new StringTokenizer(revisions, ",");
179
while (st.hasMoreTokens())
181
String revisionElement = st.nextToken();
182
RevisionRange range = new RevisionRange(revisionElement);
183
if (rangeList == null)
184
rangeList = new ArrayList<RevisionRange>();
185
rangeList.add(range);
187
if (rangeList != null)
188
setRevisionList(path, rangeList);
193
* Add the List object to the map. This method is only
194
* used internally where we know that List contains a
195
* type-safe set of RevisionRange objects.
196
* @param mergeSrc The merge source URL.
197
* @param range List of RevisionRange objects to add.
199
private void setRevisionList(String mergeSrc, List<RevisionRange> range)
201
mergeSources.put(mergeSrc, range);
205
* Constants to specify which collection of revisions to report in
210
/** Revisions eligible for merging from merge-source to merge-target. */
213
/** Revisions already merged from merge-source to merge-target. */