summaryrefslogtreecommitdiff
path: root/subversion/bindings/javahl/src/org/apache/subversion/javahl/ISVNEditor.java
blob: f1daa834d43f8b85e8bca84c558c457f0c9d5c97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/**
 * @copyright
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you under the Apache License, Version 2.0 (the
 *    "License"); you may not use this file except in compliance
 *    with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing,
 *    software distributed under the License is distributed on an
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *    KIND, either express or implied.  See the License for the
 *    specific language governing permissions and limitations
 *    under the License.
 * ====================================================================
 * @endcopyright
 */

package org.apache.subversion.javahl;

import org.apache.subversion.javahl.types.*;
import org.apache.subversion.javahl.callback.*;

import java.io.InputStream;
import java.util.Map;

/**
 * Commit/update/status editor interface.
 * <p>
 * <b>This interface is EXPERIMENTAL.
 * It may change or be removed in a future version of JavaHL</b>
 * @see <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/include/private/svn_editor.h">svn_editor.h</a>
 *      for all restrictions on driving an editor.
 * @since 1.9
 */
public interface ISVNEditor
{
    /**
     * Release the native peer (should not depend on finalize),
     * and abort the edit if it has not been completed yet.
     */
    void dispose();

    /**
     * Create a new directory at <code>relativePath</code>.
     * The immediate parent of <code>relativePath</code> is expected to exist.
     * <p>
     * For descriptions of <code>properties</code> and
     * <code>replacesRevision</code>, see #addFile().
     * <p>
     * A complete listing of the immediate children of
     * <code>relativePath</code> that will be added subsequently is
     * given in <code>children</code>. <code>children</code> is a
     * collection of const strings, each giving the basename of an
     * immediate child. It is an error to pass <code>null</code> for
     * <code>children</code>; use an empty collection to indicate that
     * the new directory will have no children.
     *
     * @throws ClientException
     */
    void addDirectory(String relativePath,
                      Iterable<String> children,
                      Map<String, byte[]> properties,
                      long replacesRevision)
            throws ClientException;

    /**
     * Create a new file at <code>relativePath</code>.
     * The immediate parent of <code>relativePath</code> is expected to exist.
     * <p>
     * The file's contents are specified in <code>contents</code>
     * which has a checksum matching <code>checksum</code>. Both
     * values must be non-<code>null</code>.
     * <p>
     * Set the properties of the new file to
     * <code>properties</code>. If no properties are being set on the
     * new file, <code>properties</code> must be empty. It is an error
     * to pass <code>null</code> for <code>properties</code>.
     * <p>
     * If this add is expected to replace a previously existing file,
     * symlink or directory at <code>relativePath</code>, the revision
     * number of the node to be replaced must be given in
     * <code>replacesRevision</code>. Otherwise,
     * <code>replacesRevision</code> must be
     * Revision.SVN_INVALID_REVNUM.
     * <p>
     * <b>Note:</b> It is not allowed to call a "delete" followed by
     * an "add" on the same path. Instead, an "add" with
     * <code>replacesRevision</code> set accordingly <em>must</em> be used.
     * <p>
     * <b>Note:</b> The <code>contents</code> stream's lifetime must not
     *      extend beyond the scope of this function. An
     *      implementation <b>must</b> close the stream after
     *      consuming its contents.
     *
     * @throws ClientException
     */
    void addFile(String relativePath,
                 Checksum checksum,
                 InputStream contents,
                 Map<String, byte[]> properties,
                 long replacesRevision)
            throws ClientException;

    /**
     * Create a new symbolic link at <code>relativePath</code>, with a
     * link target of <code>target</code>. The immediate parent of
     * <code>relativePath</code> is expected to exist.
     *
     * For descriptions of <code>properties</code> and
     * <code>replacesRevision</code>, see #addFile().
     *
     * @throws ClientException
     */
    void addSymlink(String relativePath,
                    String target,
                    Map<String, byte[]> properties,
                    long replacesRevision)
            throws ClientException;

    /**
     * Create an "absent" node of kind <code>kind</code> at
     * <code>relativePath</code>. The immediate parent of
     * <code>relativePath</code> is expected to exist.
     *
     * For a description of <code>replacesRevision</code>, see #addFile().
     *
     * @throws ClientException
     */
    void addAbsent(String relativePath,
                   NodeKind kind,
                   long replacesRevision)
            throws ClientException;

    /**
     * Alter the properties of the directory at <code>relativePath</code>.
     * <p>
     * <code>revision</code> specifies the revision at which the
     * receiver should expect to find this node. That is,
     * <code>relativePath</code> at the start of the whole edit and
     * <code>relativePath</code> at <code>revision</code> must lie
     * within the same node-rev (aka location history segment). This
     * information may be used to catch an attempt to alter and
     * out-of-date directory. If the directory does not have a
     * corresponding revision in the repository (e.g. it has not yet
     * been committed), then <code>revision</code> should be
     * Revision.SVN_INVALID_REVNUM.
     * <p>
     * If any changes to the set of children will be made in the
     * future of the edit drive, then <code>children</code>
     * <em>must</em> specify the resulting set of children. See
     * #addDirectory() for the format of <code>children</code>.  If
     * not changes will be made, then NULL may be specified.
     * <p>
     * For a description of <code>properties</code>, see
     * #addFile(). If no changes to the properties will be made
     * (ie. only future changes to the set of children), then
     * <code>properties</code> may be <code>null</code>.
     *
     * @throws ClientException
     */
    void alterDirectory(String relativePath,
                        long revision,
                        Iterable<String> children,
                        Map<String, byte[]> properties)
            throws ClientException;

    /**
     * Alter the contents and/or the properties of the file at
     * <code>relativePath</code> with <code>revision</code> as its
     * expected revision. See #alterDirectory() for more information
     * about <code>revision</code>.
     * <p>
     * If <code>contents</code> is non-<code>null</code>, then the
     * stream will be copied to the file, and its checksum must match
     * <code>checksum</code> (which must also be
     * non-<code>null</code>). If <code>contents</code> is
     * <code>null</code>, then <code>checksum</code> must also be
     * <code>null</code>, and no change will be applied to the file's
     * contents.
     * <p>
     * If <code>properties</code> is non-<code>null</code>, then the
     * properties will be applied.
     * <p>
     * For a description of <code>checksum</code> and
     * <code>contents</code>, see #addFile().
     * <p>
     * This function allows <code>properties</code> to be
     * <code>null</code>, but the parameter is otherwise described by
     * #addFile().
     * <p>
     * <b>Note:</b> The <code>contents</code> stream's lifetime must not
     *      extend beyond the scope of this function. An
     *      implementation <b>must</b> close the stream after
     *      consuming its contents.
     *
     * @throws ClientException
     */
    void alterFile(String relativePath,
                   long revision,
                   Checksum checksum,
                   InputStream contents,
                   Map<String, byte[]> properties)
            throws ClientException;

    /**
     * Alter the target and/or the properties of the symlink at
     * <code>relativePath</code> with <code>revision</code> as its
     * expected revision. See #alterDirectory() for more information
     * about <code>revision</code>.
     * <p>
     * If <code>target</code> is non-<code>null</code>, then the
     * symlink's target will be updated.
     * <p>
     * If <code>properties</code> is non-<code>null</code>, then the
     * properties will be applied.
     * <p>
     * The target and/or the properties must be changed. It is an
     * error to pass <code>null</code> for both <code>target</code>
     * and <code>properties</code>.
     * <p>
     * This function allows <code>properties</code> to be
     * <code>null</code>, but the parameter is otherwise described by
     * #addFile().
     *
     * @throws ClientException
     */
    void alterSymlink(String relativePath,
                      long revision,
                      String target,
                      Map<String, byte[]> properties)
            throws ClientException;

    /**
     * Delete the existing node at <code>relativePath</code>, expected
     * to be identical to revision <code>revision</code> of that path.
     *
     * @throws ClientException
     */
    void delete(String relativePath,
                long revision)
            throws ClientException;

    /**
     * Move the node at <code>sourceRelativePath</code> to
     * <code>destinationRelativePath</code>.
     * <p>
     * For a description of <code>replacesRevision</code>, see #addFile().
     * <p>
     * <b>Note:</b> See the general instructions on paths for this API.
     * Sice the <code>sourceRelativePath</code> argument must generally be
     * able to reference any node in the repository, the implication
     * is that the editor's root must be the repository root.
     *
     * @throws ClientException
     */
    void copy(String sourceRelativePath,
              long sourceRevision,
              String destinationRelativePath,
              long replacesRevision)
            throws ClientException;

    /**
     * Move the node at <code>sourceRelativePath</code> to
     * <code>destinationRelativePath</code>.
     * <p>
     * <code>sourceRevision</code> specifies the revision at which the
     * receiver should expect to find this node.  That is,
     * <code>sourceRelativePath</code> at the start of the whole edit
     * and<code>sourceRelativePath</code> at
     * <code>sourceRevision</code> must lie within the same node-rev
     * (aka history-segment).  This is just like the #delete().
     * <p>
     * For a description of <code>replacesRevision</code>, see #addFile().
     *
     * @throws ClientException
     */
    void move(String sourceRelativePath,
              long sourceRevision,
              String destinationRelativePath,
              long replacesRevision)
            throws ClientException;

    /**
     * Signal that the edit has been completed successfully.
     * After this method is called, the editor is considered closed.
     *
     * @throws ClientException
     */
    void complete() throws ClientException;

    /**
     * Signal that the edit transmission was not successful.
     * After this method is called, the editor is considered closed.
     *
     * @throws ClientException
     */
    void abort() throws ClientException;


    /**
     * Callback interface for providing the base contents of a file
     * that is being modified.
     * @see ISVNRemote.getCommitEditor(Map,CommitCallback,Set,boolean,ISVNEditor.ProvideBaseCallback,ISVNEditor.ProvidePropsCallback,ISVNEditor.GetNodeKindCallback)
     */
    public interface ProvideBaseCallback
    {
        public static class ReturnValue
        {
            /**
             * @param contents The base ({@link Revision#BASE}) contents
             *         of the file.
             * @param revision The base revision number.
             */
            public ReturnValue(InputStream contents, long revision)
            {
                this.contents = contents;
                this.revision = revision;
            }

            final InputStream contents;
            final long revision;
        }

        /**
         * Returns the base contents and revision number of the file.
         * @param reposRelpath The repository path of the file,
         *        relative to the session base URL.
         */
        ReturnValue getContents(String reposRelpath);
    }

    /**
     * Callback interface for providing the base properties of a file
     * or directory that is being modified.
     * @see ISVNRemote.getCommitEditor(Map,CommitCallback,Set,boolean,ISVNEditor.ProvideBaseCallback,ISVNEditor.ProvidePropsCallback,ISVNEditor.GetNodeKindCallback)
     */
    public interface ProvidePropsCallback
    {
        public static class ReturnValue
        {
            /**
             * @param properties The base ({@link Revision#BASE}) properties
             *         of the file or directory.
             * @param revision The base revision number.
             */
            public ReturnValue(Map<String, byte[]> properties, long revision)
            {
                this.properties = properties;
                this.revision = revision;
            }

            final Map<String, byte[]> properties;
            final long revision;
        }

        /**
         * Returns the base properties and revision number of the file
         * or directory.
         * @param reposRelpath The repository path of the file or directory,
         *        relative to the session base URL.
         */
        ReturnValue getProperties(String reposRelpath);
    }

    /**
     * Callback interface for providing the kind of the node that was
     * the source of a copy.
     * @see ISVNRemote.getCommitEditor(Map,CommitCallback,Set,boolean,ISVNEditor.ProvideBaseCallback,ISVNEditor.ProvidePropsCallback,ISVNEditor.GetNodeKindCallback)
     */
    public interface GetNodeKindCallback
    {
        /**
         * Returns the kind of the node that was the source of a copy.
         * @param reposRelpath The repository path of the node,
         *        relative to the session base URL.
         * @param revision The copy-from revision.
         */
        NodeKind getKind(String reposRelpath, long revision);
    }
}