tikhomirov@127: /* tikhomirov@127: * Copyright (c) 2011 TMate Software Ltd tikhomirov@127: * tikhomirov@127: * This program is free software; you can redistribute it and/or modify tikhomirov@127: * it under the terms of the GNU General Public License as published by tikhomirov@127: * the Free Software Foundation; version 2 of the License. tikhomirov@127: * tikhomirov@127: * This program is distributed in the hope that it will be useful, tikhomirov@127: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@127: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@127: * GNU General Public License for more details. tikhomirov@127: * tikhomirov@127: * For information on how to redistribute this software under tikhomirov@127: * the terms of a license other than GNU General Public License tikhomirov@128: * contact TMate Software at support@hg4j.com tikhomirov@127: */ tikhomirov@127: package org.tmatesoft.hg.core; tikhomirov@127: tikhomirov@128: import java.util.Date; tikhomirov@128: tikhomirov@128: import org.tmatesoft.hg.internal.ChangelogHelper; tikhomirov@129: import org.tmatesoft.hg.repo.HgChangelog.Changeset; tikhomirov@128: tikhomirov@131: /** tikhomirov@131: * Repository file status and extra handy information. tikhomirov@131: * tikhomirov@131: * @author Artem Tikhomirov tikhomirov@131: * @author TMate Software Ltd. tikhomirov@131: */ tikhomirov@127: public class HgStatus { tikhomirov@127: tikhomirov@127: public enum Kind { tikhomirov@127: Modified, Added, Removed, Unknown, Missing, Clean, Ignored tikhomirov@127: }; tikhomirov@127: tikhomirov@127: private final HgStatus.Kind kind; tikhomirov@127: private final Path path; tikhomirov@127: private final Path origin; tikhomirov@128: private final ChangelogHelper logHelper; tikhomirov@127: tikhomirov@128: HgStatus(HgStatus.Kind kind, Path path, ChangelogHelper changelogHelper) { tikhomirov@128: this(kind, path, null, changelogHelper); tikhomirov@127: } tikhomirov@127: tikhomirov@128: HgStatus(HgStatus.Kind kind, Path path, Path copyOrigin, ChangelogHelper changelogHelper) { tikhomirov@127: this.kind = kind; tikhomirov@127: this.path = path; tikhomirov@127: origin = copyOrigin; tikhomirov@128: logHelper = changelogHelper; tikhomirov@127: } tikhomirov@127: tikhomirov@127: public HgStatus.Kind getKind() { tikhomirov@127: return kind; tikhomirov@127: } tikhomirov@127: tikhomirov@127: public Path getPath() { tikhomirov@127: return path; tikhomirov@127: } tikhomirov@127: tikhomirov@127: public Path getOriginalPath() { tikhomirov@127: return origin; tikhomirov@127: } tikhomirov@127: tikhomirov@127: public boolean isCopy() { tikhomirov@127: return origin != null; tikhomirov@127: } tikhomirov@128: tikhomirov@128: /** tikhomirov@128: * @return null if author for the change can't be deduced (e.g. for clean files it's senseless) tikhomirov@128: */ tikhomirov@128: public String getModificationAuthor() { tikhomirov@128: Changeset cset = logHelper.findLatestChangeWith(path); tikhomirov@128: if (cset == null) { tikhomirov@128: if (kind == Kind.Modified || kind == Kind.Added || kind == Kind.Removed /*&& RightBoundary is TIP*/) { tikhomirov@128: return logHelper.getNextCommitUsername(); tikhomirov@128: } tikhomirov@128: } else { tikhomirov@128: return cset.user(); tikhomirov@128: } tikhomirov@128: return null; tikhomirov@128: } tikhomirov@128: tikhomirov@128: public Date getModificationDate() { tikhomirov@128: Changeset cset = logHelper.findLatestChangeWith(path); tikhomirov@128: if (cset == null) { tikhomirov@128: // FIXME check dirstate and/or local file for tstamp tikhomirov@128: return new Date(); // what's correct tikhomirov@128: } else { tikhomirov@128: return cset.date(); tikhomirov@128: } tikhomirov@128: } tikhomirov@127: }