Rename Repository getWorkDir to getWorkTree

This better matches with the name used in the environment
(GIT_WORK_TREE), in the configuration file (core.worktree),
and in our builder object.

Since we are already breaking a good chunk of other code
related to repository access, and this fairly easy to fix
in an application's code base, I'm not going to offer the
wrapper getWorkDir() method.

Change-Id: Ib698ba4bbc213c48114f342378cecfe377e37bb7
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce 2010-06-25 17:53:03 -07:00
parent 532421d989
commit 203bd66267
12 changed files with 39 additions and 38 deletions

View File

@ -324,7 +324,7 @@ protected int runHook(final Repository db, final File hook,
putPersonIdent(env, "AUTHOR", author); putPersonIdent(env, "AUTHOR", author);
putPersonIdent(env, "COMMITTER", committer); putPersonIdent(env, "COMMITTER", committer);
final File cwd = db.getWorkDir(); final File cwd = db.getWorkTree();
final Process p = Runtime.getRuntime().exec(argv, toEnvArray(env), cwd); final Process p = Runtime.getRuntime().exec(argv, toEnvArray(env), cwd);
p.getOutputStream().close(); p.getOutputStream().close();
p.getErrorStream().close(); p.getErrorStream().close();

View File

@ -183,7 +183,7 @@ private void doCheckout(final Ref branch) throws IOException {
final Tree tree = commit.getTree(); final Tree tree = commit.getTree();
final WorkDirCheckout co; final WorkDirCheckout co;
co = new WorkDirCheckout(db, db.getWorkDir(), index, tree); co = new WorkDirCheckout(db, db.getWorkTree(), index, tree);
co.checkout(); co.checkout();
index.write(); index.write();
} }

View File

@ -67,7 +67,7 @@ class Rm extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
root = db.getWorkDir(); root = db.getWorkTree();
final DirCache dirc = DirCache.lock(db); final DirCache dirc = DirCache.lock(db);
final DirCacheBuilder edit = dirc.builder(); final DirCacheBuilder edit = dirc.builder();

View File

@ -91,7 +91,7 @@ protected void run() throws Exception {
} }
if (output == null) if (output == null)
output = new File(db.getWorkDir(), IpLogMeta.IPLOG_CONFIG_FILE); output = new File(db.getWorkTree(), IpLogMeta.IPLOG_CONFIG_FILE);
IpLogMeta meta = new IpLogMeta(); IpLogMeta meta = new IpLogMeta();
meta.syncCQs(output, ipzilla, username, password); meta.syncCQs(output, ipzilla, username, password);

View File

@ -116,7 +116,7 @@ public void run() {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
db = createWorkRepository(); db = createWorkRepository();
trash = db.getWorkDir(); trash = db.getWorkTree();
} }
public void testCreateEmptyIndex() throws Exception { public void testCreateEmptyIndex() throws Exception {

View File

@ -100,20 +100,20 @@ public void testFastForwardWithFiles() throws Exception {
addNewFileToIndex("file1"); addNewFileToIndex("file1");
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
assertTrue(new File(db.getWorkDir(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file1").exists());
createBranch(first, "refs/heads/branch1"); createBranch(first, "refs/heads/branch1");
addNewFileToIndex("file2"); addNewFileToIndex("file2");
RevCommit second = git.commit().setMessage("second commit").call(); RevCommit second = git.commit().setMessage("second commit").call();
assertTrue(new File(db.getWorkDir(), "file2").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists());
checkoutBranch("refs/heads/branch1"); checkoutBranch("refs/heads/branch1");
assertFalse(new File(db.getWorkDir(), "file2").exists()); assertFalse(new File(db.getWorkTree(), "file2").exists());
MergeResult result = git.merge().include(db.getRef(Constants.MASTER)).call(); MergeResult result = git.merge().include(db.getRef(Constants.MASTER)).call();
assertTrue(new File(db.getWorkDir(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file1").exists());
assertTrue(new File(db.getWorkDir(), "file2").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists());
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead()); assertEquals(second, result.getNewHead());
} }
@ -132,8 +132,8 @@ public void testMultipleHeads() throws Exception {
git.commit().setMessage("third commit").call(); git.commit().setMessage("third commit").call();
checkoutBranch("refs/heads/branch1"); checkoutBranch("refs/heads/branch1");
assertFalse(new File(db.getWorkDir(), "file2").exists()); assertFalse(new File(db.getWorkTree(), "file2").exists());
assertFalse(new File(db.getWorkDir(), "file3").exists()); assertFalse(new File(db.getWorkTree(), "file3").exists());
MergeCommand merge = git.merge(); MergeCommand merge = git.merge();
merge.include(second.getId()); merge.include(second.getId());
@ -152,7 +152,7 @@ private void createBranch(ObjectId objectId, String branchName) throws IOExcepti
} }
private void checkoutBranch(String branchName) throws Exception { private void checkoutBranch(String branchName) throws Exception {
File workDir = db.getWorkDir(); File workDir = db.getWorkTree();
if (workDir != null) { if (workDir != null) {
WorkDirCheckout workDirCheckout = new WorkDirCheckout(db, WorkDirCheckout workDirCheckout = new WorkDirCheckout(db,
workDir, db.mapCommit(Constants.HEAD).getTree(), workDir, db.mapCommit(Constants.HEAD).getTree(),
@ -176,7 +176,7 @@ private void addNewFileToIndex(String filename) throws IOException,
File writeTrashFile = writeTrashFile(filename, filename); File writeTrashFile = writeTrashFile(filename, filename);
GitIndex index = db.getIndex(); GitIndex index = db.getIndex();
Entry entry = index.add(db.getWorkDir(), writeTrashFile); Entry entry = index.add(db.getWorkTree(), writeTrashFile);
entry.update(writeTrashFile); entry.update(writeTrashFile);
index.write(); index.write();
} }

View File

@ -73,7 +73,7 @@ public void testWorkdirIsParentDir_CreateRepositoryFromDotGitGitDir()
throws Exception { throws Exception {
File gitDir = getFile("workdir", Constants.DOT_GIT); File gitDir = getFile("workdir", Constants.DOT_GIT);
Repository repo = new FileRepository(gitDir); Repository repo = new FileRepository(gitDir);
String workdir = repo.getWorkDir().getName(); String workdir = repo.getWorkTree().getName();
assertEquals(workdir, "workdir"); assertEquals(workdir, "workdir");
} }
@ -132,7 +132,7 @@ public void testNotBare_CreateRepositoryFromGitDirOnlyWithBareConfigFalse()
public void testExceptionThrown_BareRepoGetWorkDir() throws Exception { public void testExceptionThrown_BareRepoGetWorkDir() throws Exception {
File gitDir = getFile("workdir"); File gitDir = getFile("workdir");
try { try {
new FileRepository(gitDir).getWorkDir(); new FileRepository(gitDir).getWorkTree();
fail("Expected IllegalStateException missing"); fail("Expected IllegalStateException missing");
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// expected // expected
@ -202,7 +202,7 @@ private void assertGitdirPath(Repository repo, String... expected)
private void assertWorkdirPath(Repository repo, String... expected) private void assertWorkdirPath(Repository repo, String... expected)
throws IOException { throws IOException {
File exp = getFile(expected).getCanonicalFile(); File exp = getFile(expected).getCanonicalFile();
File act = repo.getWorkDir().getCanonicalFile(); File act = repo.getWorkTree().getCanonicalFile();
assertEquals("Wrong working Directory", exp, act); assertEquals("Wrong working Directory", exp, act);
} }
} }

View File

@ -83,7 +83,7 @@ protected static void copyFile(final File src, final File dst)
protected File writeTrashFile(final String name, final String data) protected File writeTrashFile(final String name, final String data)
throws IOException { throws IOException {
File path = new File(db.getWorkDir(), name); File path = new File(db.getWorkTree(), name);
write(path, data); write(path, data);
return path; return path;
} }
@ -111,6 +111,6 @@ protected static void checkFile(File f, final String checkData)
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
db = createWorkRepository(); db = createWorkRepository();
trash = db.getWorkDir(); trash = db.getWorkTree();
} }
} }

View File

@ -104,7 +104,7 @@ public void test000_openrepo_default_gitDirSet() throws IOException {
File theDir = new File(repo1Parent, Constants.DOT_GIT); File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build(); FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent, r.getWorkDir()); assertEqualsPath(repo1Parent, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
} }
@ -125,7 +125,7 @@ public void test000_openrepo_default_gitDirAndWorkTreeSet() throws IOException {
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir) FileRepository r = new FileRepositoryBuilder().setGitDir(theDir)
.setWorkTree(repo1Parent.getParentFile()).build(); .setWorkTree(repo1Parent.getParentFile()).build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent.getParentFile(), r.getWorkDir()); assertEqualsPath(repo1Parent.getParentFile(), r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
} }
@ -145,7 +145,7 @@ public void test000_openrepo_default_workDirSet() throws IOException {
File theDir = new File(repo1Parent, Constants.DOT_GIT); File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setWorkTree(repo1Parent).build(); FileRepository r = new FileRepositoryBuilder().setWorkTree(repo1Parent).build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent, r.getWorkDir()); assertEqualsPath(repo1Parent, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
} }
@ -170,7 +170,7 @@ public void test000_openrepo_default_absolute_workdirconfig()
File theDir = new File(repo1Parent, Constants.DOT_GIT); File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build(); FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(workdir, r.getWorkDir()); assertEqualsPath(workdir, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
} }
@ -195,7 +195,7 @@ public void test000_openrepo_default_relative_workdirconfig()
File theDir = new File(repo1Parent, Constants.DOT_GIT); File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build(); FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(workdir, r.getWorkDir()); assertEqualsPath(workdir, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
} }
@ -223,7 +223,7 @@ public void test000_openrepo_alternate_index_file_and_objdirs()
.setIndexFile(indexFile) // .setIndexFile(indexFile) //
.build(); .build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(theDir.getParentFile(), r.getWorkDir()); assertEqualsPath(theDir.getParentFile(), r.getWorkTree());
assertEqualsPath(indexFile, r.getIndexFile()); assertEqualsPath(indexFile, r.getIndexFile());
assertEqualsPath(objDir, r.getObjectsDirectory()); assertEqualsPath(objDir, r.getObjectsDirectory());
assertNotNull(r.mapCommit("6db9c2ebf75590eef973081736730a9ea169a0c4")); assertNotNull(r.mapCommit("6db9c2ebf75590eef973081736730a9ea169a0c4"));
@ -726,10 +726,10 @@ public void test30_stripWorkDir() {
assertEquals("", Repository.stripWorkDir(relBase, relNonFile)); assertEquals("", Repository.stripWorkDir(relBase, relNonFile));
assertEquals("", Repository.stripWorkDir(absBase, absNonFile)); assertEquals("", Repository.stripWorkDir(absBase, absNonFile));
assertEquals("", Repository.stripWorkDir(db.getWorkDir(), db.getWorkDir())); assertEquals("", Repository.stripWorkDir(db.getWorkTree(), db.getWorkTree()));
File file = new File(new File(db.getWorkDir(), "subdir"), "File.java"); File file = new File(new File(db.getWorkTree(), "subdir"), "File.java");
assertEquals("subdir/File.java", Repository.stripWorkDir(db.getWorkDir(), file)); assertEquals("subdir/File.java", Repository.stripWorkDir(db.getWorkTree(), file));
} }

View File

@ -163,7 +163,7 @@ private void checkoutNewHead(RevWalk revWalk, RevCommit headCommit,
RevCommit newHeadCommit) throws IOException, CheckoutConflictException { RevCommit newHeadCommit) throws IOException, CheckoutConflictException {
GitIndex index = repo.getIndex(); GitIndex index = repo.getIndex();
File workDir = repo.getWorkDir(); File workDir = repo.getWorkTree();
if (workDir != null) { if (workDir != null) {
WorkDirCheckout workDirCheckout = new WorkDirCheckout(repo, WorkDirCheckout workDirCheckout = new WorkDirCheckout(repo,
workDir, headCommit.asCommit(revWalk).getTree(), index, workDir, headCommit.asCommit(revWalk).getTree(), index,

View File

@ -89,7 +89,7 @@ public IndexDiff(Tree tree, GitIndex index) {
* @throws IOException * @throws IOException
*/ */
public boolean diff() throws IOException { public boolean diff() throws IOException {
final File root = index.getRepository().getWorkDir(); final File root = index.getRepository().getWorkTree();
new IndexTreeWalker(index, tree, root, new AbstractIndexTreeVisitor() { new IndexTreeWalker(index, tree, root, new AbstractIndexTreeVisitor() {
public void visitEntry(TreeEntry treeEntry, Entry indexEntry, File file) { public void visitEntry(TreeEntry treeEntry, Entry indexEntry, File file) {
if (treeEntry == null) { if (treeEntry == null) {

View File

@ -96,7 +96,7 @@ public abstract class Repository {
static private final List<RepositoryListener> allListeners = new Vector<RepositoryListener>(); // thread safe static private final List<RepositoryListener> allListeners = new Vector<RepositoryListener>(); // thread safe
/** If not bare, the top level directory of the working files. */ /** If not bare, the top level directory of the working files. */
private final File workDir; private final File workTree;
/** If not bare, the index file caching the working file states. */ /** If not bare, the index file caching the working file states. */
private final File indexFile; private final File indexFile;
@ -110,7 +110,7 @@ public abstract class Repository {
protected Repository(final BaseRepositoryBuilder options) { protected Repository(final BaseRepositoryBuilder options) {
gitDir = options.getGitDir(); gitDir = options.getGitDir();
fs = options.getFS(); fs = options.getFS();
workDir = options.getWorkTree(); workTree = options.getWorkTree();
indexFile = options.getIndexFile(); indexFile = options.getIndexFile();
} }
@ -886,7 +886,7 @@ public RepositoryState getRepositoryState() {
return RepositoryState.BARE; return RepositoryState.BARE;
// Pre Git-1.6 logic // Pre Git-1.6 logic
if (new File(getWorkDir(), ".dotest").exists()) if (new File(getWorkTree(), ".dotest").exists())
return RepositoryState.REBASING; return RepositoryState.REBASING;
if (new File(getDirectory(), ".dotest-merge").exists()) if (new File(getDirectory(), ".dotest-merge").exists())
return RepositoryState.REBASING_INTERACTIVE; return RepositoryState.REBASING_INTERACTIVE;
@ -1011,19 +1011,20 @@ public static String stripWorkDir(File workDir, File file) {
* @return the "bare"-ness of this Repository * @return the "bare"-ness of this Repository
*/ */
public boolean isBare() { public boolean isBare() {
return workDir == null; return workTree == null;
} }
/** /**
* @return the workdir file, i.e. where the files are checked out * @return the root directory of the working tree, where files are checked
* out for viewing and editing.
* @throws IllegalStateException * @throws IllegalStateException
* if the repository is "bare" * if the repository is bare and has no working directory.
*/ */
public File getWorkDir() throws IllegalStateException { public File getWorkTree() throws IllegalStateException {
if (isBare()) if (isBare())
throw new IllegalStateException( throw new IllegalStateException(
JGitText.get().bareRepositoryNoWorkdirAndIndex); JGitText.get().bareRepositoryNoWorkdirAndIndex);
return workDir; return workTree;
} }
/** /**