/
RefDatabase.java
107 lines (88 loc) · 3.28 KB
/
RefDatabase.java
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
/* Copyright (c) 2012-2016 Boundless and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/edl-v10.html
*
* Contributors:
* Gabriel Roldan (Boundless) - initial implementation
*/
package org.locationtech.geogig.storage;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeoutException;
import org.locationtech.geogig.model.ObjectId;
import org.locationtech.geogig.model.Ref;
import lombok.NonNull;
/**
* Provides an interface for GeoGig reference databases.
*
* @since 1.0
*/
public interface RefDatabase extends Store {
/**
* Locks access to the main repository refs.
*/
public void lock() throws TimeoutException;
/**
* Unlocks access to the main repository refs.
*/
public void unlock();
/**
* Retrieves a ref with the specified name.
*
* @param name the name of the ref (e.g. {@code "refs/remotes/origin"}, etc).
* @return the ref, or {@code null} if it doesn't exist
* @since 2.0
*/
public Optional<Ref> get(@NonNull String name);
public List<Ref> getAllPresent(@NonNull Iterable<String> names);
/**
* @return all known references, including top level ones like HEAD, WORK_HEAD, and STAGE_HEAD,
* but not including transaction references (e.g. the ones under the
* {@link Ref#TRANSACTIONS_PREFIX transactions/} prefix.
*/
public @NonNull List<Ref> getAll();
/**
* Retrieves all refs under a specific prefix (.e.g. {@code /}, {@code /refs},
* {@code /refs/remotes}, etc.
*
* @param prefix the prefix
* @return the refs that matched the prefix
*/
public @NonNull List<Ref> getAll(@NonNull String prefix);
/**
* Adds a ref to the database.
*
* @param refName the name of the ref
* @param refValue the value of the ref
* @return the old value
*/
public @NonNull RefChange put(@NonNull Ref ref);
public @NonNull RefChange putRef(@NonNull String name, @NonNull ObjectId value);
public @NonNull RefChange putSymRef(@NonNull String name, @NonNull String target);
public @NonNull List<RefChange> putAll(@NonNull Iterable<Ref> refs);
/**
* Removes a ref from the database.
*
* @param refName the name of the ref to remove (e.g. {@code "HEAD"},
* {@code "refs/remotes/origin"}, etc).
* @return the value of the ref before removing it, or {@code null} if it didn't exist
*/
public @NonNull RefChange delete(@NonNull String refName);
public @NonNull List<RefChange> delete(@NonNull Iterable<String> refNames);
public @NonNull RefChange delete(@NonNull Ref ref);
/**
* Removes all references.
*
* @return the references removed, may be empty.
*/
public @NonNull List<Ref> deleteAll();
/**
* Removes all references under the given {@code namespace} and the namespace itself
*
* @param namespace the refs namespace to remove (e.g. {@code "refs/remotes/origin"}, etc)
* @return the references removed, may be empty.
*/
public List<Ref> deleteAll(@NonNull String namespace);
}