1152N/A/*
1152N/A * CDDL HEADER START
1152N/A *
1152N/A * The contents of this file are subject to the terms of the
1152N/A * Common Development and Distribution License (the "License").
1152N/A * You may not use this file except in compliance with the License.
1152N/A *
1152N/A * See LICENSE.txt included in this distribution for the specific
1152N/A * language governing permissions and limitations under the License.
1152N/A *
1152N/A * When distributing Covered Code, include this CDDL HEADER in each
1152N/A * file and include the License file at LICENSE.txt.
1152N/A * If applicable, add the following below this CDDL HEADER, with the
1152N/A * fields enclosed by brackets "[]" replaced with your own identifying
1152N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1152N/A *
1152N/A * CDDL HEADER END
1152N/A */
1152N/A
1152N/A/*
1152N/A * Copyright (c) 2010, Trond Norbye <trond.norbye@gmail.com>. All rights reserved.
1152N/A */
1152N/Apackage org.opensolaris.opengrok.history;
1152N/A
1152N/Aimport java.io.File;
1152N/Aimport java.io.IOException;
1152N/Aimport java.io.InputStream;
1152N/Aimport java.util.ArrayList;
1152N/Aimport java.util.List;
1152N/Aimport org.opensolaris.opengrok.util.Executor;
1152N/A
1152N/A/**
1152N/A * Access to a Git repository.
1152N/A *
1152N/A * @author Trond Norbye <trond.norbye@gmail.com>
1152N/A */
1152N/Apublic class RepoRepository extends Repository {
1289N/A // TODO: cache all of the GitRepositories within the class
1152N/A
1152N/A private static final long serialVersionUID = 1L;
1182N/A /** The property name used to obtain the client command for this repository.*/
1190N/A public static final String CMD_PROPERTY_KEY =
1182N/A "org.opensolaris.opengrok.history.repo";
1182N/A /** The command to use to access the repository if none was given explicitly */
1182N/A public static final String CMD_FALLBACK = "repo";
1152N/A
1152N/A public RepoRepository() {
1152N/A type = "repo";
1182N/A setWorking(Boolean.TRUE);
1152N/A }
1152N/A
1152N/A @Override
1152N/A public boolean isWorking() {
1182N/A ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
1152N/A return true;
1152N/A }
1152N/A
1152N/A @Override
1152N/A public void update() throws IOException {
1152N/A File directory = new File(getDirectoryName());
1152N/A List<String> cmd = new ArrayList<String>();
1182N/A ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
1182N/A cmd.add(this.cmd);
1152N/A cmd.add("sync");
1152N/A
1152N/A Executor executor = new Executor(cmd, directory);
1152N/A if (executor.exec() != 0) {
1152N/A throw new IOException(executor.getErrorString());
1152N/A }
1152N/A }
1152N/A
1152N/A @Override
1152N/A boolean isRepositoryFor(File file) {
1152N/A if (file.isDirectory()) {
1152N/A File f = new File(file, ".repo");
1152N/A return f.exists() && f.isDirectory();
1152N/A }
1182N/A return false;
1152N/A }
1152N/A
1152N/A @Override
1152N/A boolean supportsSubRepositories() {
1152N/A return true;
1152N/A }
1152N/A
1152N/A @Override
1152N/A boolean fileHasHistory(File file) {
1152N/A return false;
1152N/A }
1152N/A
1152N/A @Override
1152N/A boolean hasHistoryForDirectories() {
1152N/A return false;
1152N/A }
1152N/A
1152N/A @Override
1182N/A History getHistory(File file) {
1152N/A throw new UnsupportedOperationException("Should never be called!");
1152N/A }
1152N/A
1152N/A @Override
1152N/A InputStream getHistoryGet(String parent, String basename, String rev) {
1152N/A throw new UnsupportedOperationException("Should never be called!");
1152N/A }
1152N/A
1152N/A @Override
1152N/A boolean fileHasAnnotation(File file) {
1171N/A return false;
1152N/A }
1152N/A
1152N/A @Override
1182N/A Annotation annotate(File file, String revision) {
1152N/A throw new UnsupportedOperationException("Should never be called!");
1152N/A }
1152N/A
1152N/A}