kitaev@213: /* kitaev@213: * Copyright (c) 2011 TMate Software Ltd kitaev@213: * kitaev@213: * This program is free software; you can redistribute it and/or modify kitaev@213: * it under the terms of the GNU General Public License as published by kitaev@213: * the Free Software Foundation; version 2 of the License. kitaev@213: * kitaev@213: * This program is distributed in the hope that it will be useful, kitaev@213: * but WITHOUT ANY WARRANTY; without even the implied warranty of kitaev@213: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the kitaev@213: * GNU General Public License for more details. kitaev@213: * kitaev@213: * For information on how to redistribute this software under kitaev@213: * the terms of a license other than GNU General Public License kitaev@213: * contact TMate Software at support@hg4j.com kitaev@213: */ kitaev@213: package org.tmatesoft.hg.repo; kitaev@213: kitaev@213: import static org.tmatesoft.hg.repo.HgRepository.*; kitaev@213: kitaev@213: import java.io.File; kitaev@213: import java.net.InetAddress; kitaev@213: import java.net.UnknownHostException; kitaev@213: kitaev@213: import org.tmatesoft.hg.internal.ConfigFile; kitaev@213: import org.tmatesoft.hg.util.Path; kitaev@213: kitaev@213: kitaev@213: /** kitaev@213: * DO NOT USE THIS CLASS, INTENDED FOR TESTING PURPOSES. kitaev@213: * kitaev@213: * Debug helper, to access otherwise restricted (package-local) methods kitaev@213: * kitaev@213: * @author Artem Tikhomirov kitaev@213: * @author TMate Software Ltd. kitaev@213: kitaev@213: */ kitaev@213: public class HgInternals { kitaev@213: kitaev@213: private final HgRepository repo; kitaev@213: kitaev@213: public HgInternals(HgRepository hgRepo) { kitaev@213: repo = hgRepo; kitaev@213: } kitaev@213: kitaev@213: public void dumpDirstate() { kitaev@213: repo.loadDirstate().dump(); kitaev@213: } kitaev@213: kitaev@213: public boolean[] checkIgnored(String... toCheck) { kitaev@213: HgIgnore ignore = repo.getIgnore(); kitaev@213: boolean[] rv = new boolean[toCheck.length]; kitaev@213: for (int i = 0; i < toCheck.length; i++) { kitaev@213: rv[i] = ignore.isIgnored(Path.create(toCheck[i])); kitaev@213: } kitaev@213: return rv; kitaev@213: } kitaev@213: kitaev@213: public File getRepositoryDir() { kitaev@213: return repo.getRepositoryRoot(); kitaev@213: } kitaev@213: kitaev@213: public ConfigFile getRepoConfig() { kitaev@213: return repo.getConfigFile(); kitaev@213: } kitaev@213: kitaev@213: // in fact, need a setter for this anyway, shall move to internal.Internals perhaps? kitaev@213: public String getNextCommitUsername() { kitaev@213: String hgUser = System.getenv("HGUSER"); kitaev@213: if (hgUser != null && hgUser.trim().length() > 0) { kitaev@213: return hgUser.trim(); kitaev@213: } kitaev@213: String configValue = getRepoConfig().getString("ui", "username", null); kitaev@213: if (configValue != null) { kitaev@213: return configValue; kitaev@213: } kitaev@213: String email = System.getenv("EMAIL"); kitaev@213: if (email != null && email.trim().length() > 0) { kitaev@213: return email; kitaev@213: } kitaev@213: String username = System.getProperty("user.name"); kitaev@213: try { kitaev@213: String hostname = InetAddress.getLocalHost().getHostName(); kitaev@213: return username + '@' + hostname; kitaev@213: } catch (UnknownHostException ex) { kitaev@213: return username; kitaev@213: } kitaev@213: } kitaev@213: kitaev@213: // Convenient check of local revision number for validity (not all negative values are wrong as long as we use negative constants) kitaev@213: public static boolean wrongLocalRevision(int rev) { kitaev@213: return rev < 0 && rev != TIP && rev != WORKING_COPY && rev != BAD_REVISION; kitaev@213: } kitaev@213: }