comparison hg4j/src/main/java/org/tmatesoft/hg/repo/HgInternals.java @ 213:6ec4af642ba8 gradle

Project uses Gradle for build - actual changes
author Alexander Kitaev <kitaev@gmail.com>
date Tue, 10 May 2011 10:52:53 +0200
parents
children
comparison
equal deleted inserted replaced
212:edb2e2829352 213:6ec4af642ba8
1 /*
2 * Copyright (c) 2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.repo;
18
19 import static org.tmatesoft.hg.repo.HgRepository.*;
20
21 import java.io.File;
22 import java.net.InetAddress;
23 import java.net.UnknownHostException;
24
25 import org.tmatesoft.hg.internal.ConfigFile;
26 import org.tmatesoft.hg.util.Path;
27
28
29 /**
30 * DO NOT USE THIS CLASS, INTENDED FOR TESTING PURPOSES.
31 *
32 * Debug helper, to access otherwise restricted (package-local) methods
33 *
34 * @author Artem Tikhomirov
35 * @author TMate Software Ltd.
36
37 */
38 public class HgInternals {
39
40 private final HgRepository repo;
41
42 public HgInternals(HgRepository hgRepo) {
43 repo = hgRepo;
44 }
45
46 public void dumpDirstate() {
47 repo.loadDirstate().dump();
48 }
49
50 public boolean[] checkIgnored(String... toCheck) {
51 HgIgnore ignore = repo.getIgnore();
52 boolean[] rv = new boolean[toCheck.length];
53 for (int i = 0; i < toCheck.length; i++) {
54 rv[i] = ignore.isIgnored(Path.create(toCheck[i]));
55 }
56 return rv;
57 }
58
59 public File getRepositoryDir() {
60 return repo.getRepositoryRoot();
61 }
62
63 public ConfigFile getRepoConfig() {
64 return repo.getConfigFile();
65 }
66
67 // in fact, need a setter for this anyway, shall move to internal.Internals perhaps?
68 public String getNextCommitUsername() {
69 String hgUser = System.getenv("HGUSER");
70 if (hgUser != null && hgUser.trim().length() > 0) {
71 return hgUser.trim();
72 }
73 String configValue = getRepoConfig().getString("ui", "username", null);
74 if (configValue != null) {
75 return configValue;
76 }
77 String email = System.getenv("EMAIL");
78 if (email != null && email.trim().length() > 0) {
79 return email;
80 }
81 String username = System.getProperty("user.name");
82 try {
83 String hostname = InetAddress.getLocalHost().getHostName();
84 return username + '@' + hostname;
85 } catch (UnknownHostException ex) {
86 return username;
87 }
88 }
89
90 // Convenient check of local revision number for validity (not all negative values are wrong as long as we use negative constants)
91 public static boolean wrongLocalRevision(int rev) {
92 return rev < 0 && rev != TIP && rev != WORKING_COPY && rev != BAD_REVISION;
93 }
94 }