1 /* 2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.openjdk.skara.vcs; 24 25 import java.io.IOException; 26 import java.nio.file.Path; 27 import java.nio.charset.StandardCharsets; 28 import java.util.stream.Collectors; 29 import java.util.*; 30 31 public interface ReadOnlyRepository { 32 Hash head() throws IOException; 33 Branch currentBranch() throws IOException; 34 Optional<Bookmark> currentBookmark() throws IOException; 35 Branch defaultBranch() throws IOException; 36 List<Branch> branches() throws IOException; 37 Optional<Tag> defaultTag() throws IOException; 38 List<Tag> tags() throws IOException; 39 Commits commits() throws IOException; 40 Commits commits(int n) throws IOException; 41 Commits commits(boolean reverse) throws IOException; 42 Commits commits(int n, boolean reverse) throws IOException; 43 Commits commits(String range) throws IOException; 44 Commits commits(String range, boolean reverse) throws IOException; 45 Commits commits(String range, int n) throws IOException; 46 Commits commits(String range, int n, boolean reverse) throws IOException; 47 Optional<Commit> lookup(Hash h) throws IOException; 48 Optional<Commit> lookup(Branch b) throws IOException; 49 Optional<Commit> lookup(Tag t) throws IOException; 50 List<CommitMetadata> commitMetadata() throws IOException; 51 Path root() throws IOException; 52 boolean exists() throws IOException; 53 boolean isHealthy() throws IOException; 54 boolean isEmpty() throws IOException; 55 boolean isClean() throws IOException; 56 Hash mergeBase(Hash first, Hash second) throws IOException; 57 boolean isAncestor(Hash ancestor, Hash descendant) throws IOException; 58 Optional<Hash> resolve(String ref) throws IOException; 59 default Optional<Hash> resolve(Tag t) throws IOException { 60 return resolve(t.name()); 61 } 62 default Optional<Hash> resolve(Branch b) throws IOException { 63 return resolve(b.name()); 64 } 65 boolean contains(Branch b, Hash h) throws IOException; 66 Optional<String> username() throws IOException; 67 Optional<byte[]> show(Path p, Hash h) throws IOException; 68 default Optional<List<String>> lines(Path p, Hash h) throws IOException { 69 return show(p, h).map(bytes -> new String(bytes, StandardCharsets.UTF_8).lines().collect(Collectors.toList())); 70 } 71 72 List<FileEntry> files(Hash h, List<Path> paths) throws IOException; 73 default List<FileEntry> files(Hash h, Path... paths) throws IOException { 74 return files(h, Arrays.asList(paths)); 75 } 76 77 void dump(FileEntry entry, Path to) throws IOException; 78 List<StatusEntry> status(Hash from, Hash to) throws IOException; 79 Diff diff(Hash base, Hash head) throws IOException; 80 Diff diff(Hash head) throws IOException; 81 List<String> config(String key) throws IOException; 82 Repository copyTo(Path destination) throws IOException; 83 String pullPath(String remote) throws IOException; 84 String pushPath(String remote) throws IOException; 85 boolean isValidRevisionRange(String expression) throws IOException; 86 Optional<String> upstreamFor(Branch branch) throws IOException; 87 List<Reference> remoteBranches(String remote) throws IOException; 88 List<String> remotes() throws IOException; 89 90 static Optional<ReadOnlyRepository> get(Path p) throws IOException { 91 return Repository.get(p).map(r -> r); 92 } 93 94 static boolean exists(Path p) throws IOException { 95 return Repository.exists(p); 96 } 97 }