From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [EGIT PATCH 25/26] Rewrite UntrackOperation to use DirCacheBuilder
Date: Mon, 11 Aug 2008 18:08:12 -0700 [thread overview]
Message-ID: <1218503293-14057-26-git-send-email-spearce@spearce.org> (raw)
In-Reply-To: <1218503293-14057-25-git-send-email-spearce@spearce.org>
We can more efficiently untrack single files and entire directories using
the DirCacheBuilder API as that API is able to perform range edits on
the index data structure. Its also able to perform faster disk IO, due
to less conversion overheads.
Although performance of untrack is not a critical feature it is a good
idea to move it over to the newer API, as we will eventually get rid of
the GitIndex class entirely.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../org/spearce/egit/core/op/UntrackOperation.java | 98 +++++++++++---------
1 files changed, 55 insertions(+), 43 deletions(-)
diff --git a/org.spearce.egit.core/src/org/spearce/egit/core/op/UntrackOperation.java b/org.spearce.egit.core/src/org/spearce/egit/core/op/UntrackOperation.java
index b491e6d..4656552 100644
--- a/org.spearce.egit.core/src/org/spearce/egit/core/op/UntrackOperation.java
+++ b/org.spearce.egit.core/src/org/spearce/egit/core/op/UntrackOperation.java
@@ -1,6 +1,7 @@
/*******************************************************************************
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2008, Google Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,15 +9,14 @@
*******************************************************************************/
package org.spearce.egit.core.op;
-import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.IdentityHashMap;
-import java.util.Iterator;
+import java.util.Map;
import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
@@ -26,7 +26,9 @@ import org.spearce.egit.core.Activator;
import org.spearce.egit.core.CoreText;
import org.spearce.egit.core.project.GitProjectData;
import org.spearce.egit.core.project.RepositoryMapping;
-import org.spearce.jgit.lib.GitIndex;
+import org.spearce.jgit.dircache.DirCache;
+import org.spearce.jgit.dircache.DirCacheEditor;
+import org.spearce.jgit.lib.Repository;
/**
* Remove one or more existing files/folders from the Git repository.
@@ -43,6 +45,10 @@ import org.spearce.jgit.lib.GitIndex;
public class UntrackOperation implements IWorkspaceRunnable {
private final Collection rsrcList;
+ private final IdentityHashMap<Repository, DirCacheEditor> edits;
+
+ private final IdentityHashMap<RepositoryMapping, Object> mappings;
+
/**
* Create a new operation to stop tracking existing files/folders.
*
@@ -52,63 +58,69 @@ public class UntrackOperation implements IWorkspaceRunnable {
*/
public UntrackOperation(final Collection rsrcs) {
rsrcList = rsrcs;
+ edits = new IdentityHashMap<Repository, DirCacheEditor>();
+ mappings = new IdentityHashMap<RepositoryMapping, Object>();
}
public void run(IProgressMonitor m) throws CoreException {
- if (m == null) {
+ if (m == null)
m = new NullProgressMonitor();
- }
- final IdentityHashMap<RepositoryMapping, Boolean> tomerge = new IdentityHashMap<RepositoryMapping, Boolean>();
+ edits.clear();
+ mappings.clear();
+
m.beginTask(CoreText.AddOperation_adding, rsrcList.size() * 200);
try {
for (Object obj : rsrcList) {
- obj = ((IAdaptable)obj).getAdapter(IResource.class);
- if (obj instanceof IResource) {
- final IResource toRemove = (IResource)obj;
- final GitProjectData pd = GitProjectData.get(toRemove.getProject());
- final RepositoryMapping rm = pd.getRepositoryMapping(toRemove);
- final GitIndex index = rm.getRepository().getIndex();
- tomerge.put(rm, Boolean.TRUE);
- if (toRemove instanceof IContainer) {
- ((IContainer)toRemove).accept(new IResourceVisitor() {
- public boolean visit(IResource resource) throws CoreException {
- if (resource.getType() == IResource.FILE) {
- index.remove(rm.getWorkDir(), new File(rm.getWorkDir(),rm.getRepoRelativePath(resource)));
- }
- return true;
- }
- },IResource.DEPTH_INFINITE, IContainer.EXCLUDE_DERIVED);
- } else {
- index.remove(rm.getWorkDir(), new File(rm.getWorkDir(),rm.getRepoRelativePath(toRemove)));
- }
- }
+ obj = ((IAdaptable) obj).getAdapter(IResource.class);
+ if (obj instanceof IResource)
+ remove((IResource) obj);
m.worked(200);
}
- for (RepositoryMapping rm : tomerge.keySet()) {
- m.setTaskName("Writing index for "+rm.getRepository().getDirectory());
- rm.getRepository().getIndex().write();
+
+ for (Map.Entry<Repository, DirCacheEditor> e : edits.entrySet()) {
+ final Repository db = e.getKey();
+ final DirCacheEditor editor = e.getValue();
+ m.setTaskName("Writing index for " + db.getDirectory());
+ editor.commit();
}
} catch (RuntimeException e) {
- e.printStackTrace();
throw Activator.error(CoreText.UntrackOperation_failed, e);
} catch (IOException e) {
- e.printStackTrace();
throw Activator.error(CoreText.UntrackOperation_failed, e);
} finally {
+ for (final RepositoryMapping rm : mappings.keySet())
+ rm.fireRepositoryChanged();
+ edits.clear();
+ mappings.clear();
+ m.done();
+ }
+ }
+
+ private void remove(final IResource path) throws CoreException {
+ final IProject proj = path.getProject();
+ final GitProjectData pd = GitProjectData.get(proj);
+ if (pd == null)
+ return;
+ final RepositoryMapping rm = pd.getRepositoryMapping(path);
+ if (rm == null)
+ return;
+ final Repository db = rm.getRepository();
+
+ DirCacheEditor e = edits.get(db);
+ if (e == null) {
try {
- final Iterator i = tomerge.keySet().iterator();
- while (i.hasNext()) {
- final RepositoryMapping r = (RepositoryMapping) i.next();
- r.getRepository().getIndex().read();
- r.fireRepositoryChanged();
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- m.done();
+ e = DirCache.lock(db).editor();
+ } catch (IOException err) {
+ throw Activator.error(CoreText.UntrackOperation_failed, err);
}
+ edits.put(db, e);
+ mappings.put(rm, rm);
}
- }
+ if (path instanceof IContainer)
+ e.add(new DirCacheEditor.DeleteTree(rm.getRepoRelativePath(path)));
+ else
+ e.add(new DirCacheEditor.DeletePath(rm.getRepoRelativePath(path)));
+ }
}
--
1.6.0.rc2.22.g71b99
next prev parent reply other threads:[~2008-08-12 1:11 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-12 1:07 [EGIT PATCH 00/26] New DirCache API Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 01/26] Force all source code to UTF-8 encoding by default Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 02/26] Protect WorkingTreeIterator's name encoding from weird ByteBuffers Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 03/26] Add Constants.encode as a utility for quick encoding in UTF-8 Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 04/26] Rely upon Constants.CHARSET over Constants.CHARACTER_ENCODING Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 05/26] Allow AbstractTreeIterators to find out about StopWalkExceptions Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 06/26] Implement a new .git/index (aka dircache) read interface Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 07/26] Export the new DirCache API to Eclipse plugins using jgit Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 08/26] Support locking (and unlocking) a .git/index through DirCache Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 09/26] Support writing " Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 10/26] Support the 'TREE' extension in " Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 11/26] Support using a DirCache within a TreeWalk Shawn O. Pearce
2008-08-12 1:07 ` [EGIT PATCH 12/26] Support recreating a .git/index through DirCache Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 13/26] Support iterating and building a DirCache at the same time Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 14/26] Support creating a new DirCacheEntry for an arbitrary path Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 15/26] Support a simplified model of editing index entries Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 16/26] Support recursively getting all entries under a subtree path Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 17/26] Support copying meta fields from one DirCacheEntry to another Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 18/26] Add JUnit tests for new DirCache API Shawn O. Pearce
[not found] ` <1218503293-14057-20-git-send-email-spearce@spearce.org>
2008-08-12 1:08 ` [EGIT PATCH 20/26] Allow the new DirCacheIterator in command line arguments Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 21/26] Add debugging commands to interact with the new DirCache code Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 22/26] Add a basic command line implementation of rm Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 23/26] Rewrite GitMoveDeleteHook to use DirCacheBuilder Shawn O. Pearce
2008-08-12 1:08 ` [EGIT PATCH 24/26] Teach GitMoveDeleteHook how to move a folder recursively Shawn O. Pearce
2008-08-12 1:08 ` Shawn O. Pearce [this message]
2008-08-12 1:08 ` [EGIT PATCH 26/26] Rewrite AssumeUnchangedOperation to use DirCache Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1218503293-14057-26-git-send-email-spearce@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg@dewire.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).