tikhomirov@239: /*
tikhomirov@403: * Copyright (c) 2011-2012 TMate Software Ltd
tikhomirov@239: *
tikhomirov@239: * This program is free software; you can redistribute it and/or modify
tikhomirov@239: * it under the terms of the GNU General Public License as published by
tikhomirov@239: * the Free Software Foundation; version 2 of the License.
tikhomirov@239: *
tikhomirov@239: * This program is distributed in the hope that it will be useful,
tikhomirov@239: * but WITHOUT ANY WARRANTY; without even the implied warranty of
tikhomirov@239: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tikhomirov@239: * GNU General Public License for more details.
tikhomirov@239: *
tikhomirov@239: * For information on how to redistribute this software under
tikhomirov@239: * the terms of a license other than GNU General Public License
tikhomirov@239: * contact TMate Software at support@hg4j.com
tikhomirov@239: */
tikhomirov@239: package org.tmatesoft.hg.repo;
tikhomirov@239:
tikhomirov@239: import java.io.File;
tikhomirov@239:
tikhomirov@423: import org.tmatesoft.hg.core.HgRepositoryNotFoundException;
tikhomirov@239: import org.tmatesoft.hg.internal.Experimental;
tikhomirov@239: import org.tmatesoft.hg.util.Path;
tikhomirov@239:
tikhomirov@239: /**
tikhomirov@239: * WORK IN PROGRESS, DO NOT USE
tikhomirov@239: * @author Artem Tikhomirov
tikhomirov@239: * @author TMate Software Ltd.
tikhomirov@239: */
tikhomirov@239: @Experimental(reason="Work in progress")
tikhomirov@239: public class HgSubrepoLocation {
tikhomirov@239:
tikhomirov@239: private final HgRepository owner;
tikhomirov@239: private final Kind kind;
tikhomirov@239: private final Path location;
tikhomirov@239: private final String source;
tikhomirov@239: private final String revInfo;
tikhomirov@239:
tikhomirov@239: public enum Kind { Hg, SVN, Git, }
tikhomirov@239:
tikhomirov@239: public HgSubrepoLocation(HgRepository parentRepo, String repoLocation, String actualLocation, Kind type, String revision) {
tikhomirov@239: owner = parentRepo;
tikhomirov@239: location = Path.create(repoLocation);
tikhomirov@239: source = actualLocation;
tikhomirov@239: kind = type;
tikhomirov@239: revInfo = revision;
tikhomirov@239: }
tikhomirov@239:
tikhomirov@239: // as defined in .hgsub, key value
tikhomirov@239: public Path getLocation() {
tikhomirov@239: return location;
tikhomirov@239: }
tikhomirov@239:
tikhomirov@239: // value from .hgsub
tikhomirov@239: public String getSource() {
tikhomirov@239: return source;
tikhomirov@239: }
tikhomirov@239:
tikhomirov@239: public Kind getType() {
tikhomirov@239: return kind;
tikhomirov@239: }
tikhomirov@239:
tikhomirov@239: public String getRevision() {
tikhomirov@239: return revInfo;
tikhomirov@239: }
tikhomirov@239:
tikhomirov@239: /**
tikhomirov@239: * @return whether this sub repository is known only locally
tikhomirov@239: */
tikhomirov@239: public boolean isCommitted() {
tikhomirov@239: return revInfo != null;
tikhomirov@239: }
tikhomirov@239:
tikhomirov@239: /**
tikhomirov@239: * @return true
when there are local changes in the sub repository
tikhomirov@239: */
tikhomirov@239: public boolean hasChanges() {
tikhomirov@239: throw HgRepository.notImplemented();
tikhomirov@239: }
tikhomirov@239:
tikhomirov@239: // public boolean isLocal() {
tikhomirov@239: // }
tikhomirov@239:
tikhomirov@239: public HgRepository getOwner() {
tikhomirov@239: return owner;
tikhomirov@239: }
tikhomirov@239:
tikhomirov@423: /**
tikhomirov@423: *
tikhomirov@423: * @return object to access sub-repository
tikhomirov@423: * @throws HgRepositoryNotFoundException if failed to find repository
tikhomirov@423: * @throws HgRuntimeException subclass thereof to indicate issues with the library. Runtime exception
tikhomirov@423: */
tikhomirov@423: public HgRepository getRepo() throws HgRepositoryNotFoundException {
tikhomirov@239: if (kind != Kind.Hg) {
tikhomirov@423: throw new HgInvalidStateException(String.format("Unsupported subrepository %s", kind));
tikhomirov@239: }
tikhomirov@239: return new HgLookup().detect(new File(owner.getWorkingDir(), source));
tikhomirov@239: }
tikhomirov@239: }