~ubuntu-branches/ubuntu/trusty/subversion/trusty-proposed

« back to all changes in this revision

Viewing changes to subversion/bindings/javahl/src/org/apache/subversion/javahl/types/Mergeinfo.java

  • Committer: Package Import Robot
  • Author(s): Andy Whitcroft
  • Date: 2012-06-21 15:36:36 UTC
  • mfrom: (0.4.13 sid)
  • Revision ID: package-import@ubuntu.com-20120621153636-amqqmuidgwgxz1ly
Tags: 1.7.5-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Create pot file on build.
  - Build a python-subversion-dbg package.
  - Build-depend on python-dbg.
  - Build-depend on default-jre-headless/-jdk.
  - Do not apply java-build patch.
  - debian/rules: Manually create the doxygen output directory, otherwise
    we get weird build failures when running parallel builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @copyright
 
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
 
11
 *
 
12
 *      http://www.apache.org/licenses/LICENSE-2.0
 
13
 *
 
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
 
19
 *    under the License.
 
20
 * ====================================================================
 
21
 * @endcopyright
 
22
 */
 
23
 
 
24
package org.apache.subversion.javahl.types;
 
25
 
 
26
import java.util.ArrayList;
 
27
import java.util.HashMap;
 
28
import java.util.List;
 
29
import java.util.Map;
 
30
import java.util.Set;
 
31
import java.util.StringTokenizer;
 
32
 
 
33
import org.apache.subversion.javahl.SubversionException;
 
34
 
 
35
/**
 
36
 * Merge history for a path.
 
37
 */
 
38
public class Mergeinfo implements java.io.Serializable
 
39
{
 
40
    // Update the serialVersionUID when there is a incompatible change
 
41
    // made to this class.  See any of the following, depending upon
 
42
    // the Java release.
 
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;
 
48
 
 
49
    /**
 
50
     * A mapping of repository-relative paths to a list of revision
 
51
     * ranges.
 
52
     */
 
53
    private Map<String, List<RevisionRange>> mergeSources;
 
54
 
 
55
    public Mergeinfo()
 
56
    {
 
57
        mergeSources = new HashMap<String, List<RevisionRange>>();
 
58
    }
 
59
 
 
60
    /**
 
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.
 
64
     */
 
65
    public Mergeinfo(String mergeinfo)
 
66
    {
 
67
        this();
 
68
        this.loadFromMergeinfoProperty(mergeinfo);
 
69
    }
 
70
 
 
71
    /**
 
72
     * Add one or more RevisionRange objects to merge info. If the
 
73
     * merge source is already stored, the list of revisions is
 
74
     * replaced.
 
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.
 
79
     */
 
80
    public void addRevisions(String mergeSrc, List<RevisionRange> ranges)
 
81
    {
 
82
        for (RevisionRange range : ranges)
 
83
            addRevisionRange(mergeSrc, range);
 
84
    }
 
85
 
 
86
    /**
 
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.
 
92
     */
 
93
    public void addRevisionRange(String mergeSrc, RevisionRange range)
 
94
    {
 
95
        List<RevisionRange> revisions = this.getRevisions(mergeSrc);
 
96
        if (revisions == null)
 
97
            revisions = new ArrayList<RevisionRange>();
 
98
        revisions.add(range);
 
99
        this.setRevisionList(mergeSrc, revisions);
 
100
    }
 
101
 
 
102
    /**
 
103
     * Get the merge source URLs.
 
104
     * @return The merge source URLs.
 
105
     */
 
106
    public Set<String> getPaths()
 
107
    {
 
108
        return mergeSources.keySet();
 
109
    }
 
110
 
 
111
    /**
 
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>.
 
115
     */
 
116
    public List<RevisionRange> getRevisions(String mergeSrc)
 
117
    {
 
118
        if (mergeSrc == null)
 
119
            return null;
 
120
        return mergeSources.get(mergeSrc);
 
121
    }
 
122
 
 
123
    /**
 
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>.
 
127
     */
 
128
    public List<RevisionRange> getRevisionRange(String mergeSrc)
 
129
    {
 
130
        return this.getRevisions(mergeSrc);
 
131
    }
 
132
 
 
133
    /**
 
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.
 
137
     */
 
138
    public void loadFromMergeinfoProperty(String mergeinfo)
 
139
    {
 
140
        if (mergeinfo == null)
 
141
            return;
 
142
        StringTokenizer st = new StringTokenizer(mergeinfo, "\n");
 
143
        while (st.hasMoreTokens())
 
144
        {
 
145
            parseMergeinfoLine(st.nextToken());
 
146
        }
 
147
    }
 
148
 
 
149
    /**
 
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>).
 
153
     *
 
154
     * @param line A line of merge info for a single merge source.
 
155
     */
 
156
    private void parseMergeinfoLine(String line)
 
157
    {
 
158
        int colon = line.indexOf(':');
 
159
        if (colon > 0)
 
160
        {
 
161
            String pathElement = line.substring(0, colon);
 
162
            String revisions = line.substring(colon + 1);
 
163
            parseRevisions(pathElement, revisions);
 
164
        }
 
165
    }
 
166
 
 
167
    /**
 
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>)
 
171
     *
 
172
     * @param path The merge source path.
 
173
     * @param revisions A textual representation of the revision ranges.
 
174
     */
 
175
    private void parseRevisions(String path, String revisions)
 
176
    {
 
177
        List<RevisionRange> rangeList = this.getRevisions(path);
 
178
        StringTokenizer st = new StringTokenizer(revisions, ",");
 
179
        while (st.hasMoreTokens())
 
180
        {
 
181
            String revisionElement = st.nextToken();
 
182
            RevisionRange range = new RevisionRange(revisionElement);
 
183
            if (rangeList == null)
 
184
                rangeList = new ArrayList<RevisionRange>();
 
185
            rangeList.add(range);
 
186
        }
 
187
        if (rangeList != null)
 
188
            setRevisionList(path, rangeList);
 
189
    }
 
190
 
 
191
 
 
192
    /**
 
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.
 
198
     */
 
199
    private void setRevisionList(String mergeSrc, List<RevisionRange> range)
 
200
    {
 
201
        mergeSources.put(mergeSrc, range);
 
202
    }
 
203
 
 
204
    /**
 
205
     * Constants to specify which collection of revisions to report in
 
206
     * getMergeinfoLog.
 
207
     */
 
208
    public enum LogKind
 
209
    {
 
210
        /** Revisions eligible for merging from merge-source to merge-target. */
 
211
        eligible,
 
212
 
 
213
        /** Revisions already merged from merge-source to merge-target. */
 
214
        merged;
 
215
    }
 
216
}