From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH (RESEND) 3/4] Don't create new pack lists if the directory hasn't changed
Date: Wed, 12 Aug 2009 12:45:22 -0700 [thread overview]
Message-ID: <1250106323-19408-4-git-send-email-spearce@spearce.org> (raw)
In-Reply-To: <1250106323-19408-3-git-send-email-spearce@spearce.org>
If we scan the directory and it hasn't changed since the last time we
scanned it, there is no reason to build a new PackList and update the
volatile reference. This just generates unnecessary garbage and may
make it more difficult to detect an unmodified directory.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/lib/ObjectDirectory.java | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
index 5b28207..0bb3c01 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
@@ -260,10 +260,8 @@ protected ObjectLoader openObject2(final WindowCursor curs,
@Override
protected boolean tryAgain1() {
final PackList old = packList.get();
- if (old.tryAgain(packDirectory.lastModified())) {
- scanPacks(old);
- return true;
- }
+ if (old.tryAgain(packDirectory.lastModified()))
+ return old != scanPacks(old);
return false;
}
@@ -317,6 +315,8 @@ private PackList scanPacks(final PackList original) {
return o;
}
n = scanPacksImpl(o);
+ if (n == o)
+ return n;
} while (!packList.compareAndSet(o, n));
return n;
}
@@ -327,6 +327,7 @@ private PackList scanPacksImpl(final PackList old) {
final long lastModified = packDirectory.lastModified();
final Set<String> names = listPackDirectory();
final List<PackFile> list = new ArrayList<PackFile>(names.size() >> 2);
+ boolean foundNew = false;
for (final String indexName : names) {
// Must match "pack-[0-9a-f]{40}.idx" to be an index.
//
@@ -352,8 +353,17 @@ private PackList scanPacksImpl(final PackList old) {
final File packFile = new File(packDirectory, packName);
final File idxFile = new File(packDirectory, indexName);
list.add(new PackFile(idxFile, packFile));
+ foundNew = true;
}
+ // If we did not discover any new files, the modification time was not
+ // changed, and we did not remove any files, then the set of files is
+ // the same as the set we were given. Instead of building a new object
+ // return the same collection.
+ //
+ if (!foundNew && lastModified == old.lastModified && forReuse.isEmpty())
+ return old;
+
for (final PackFile p : forReuse.values()) {
p.close();
}
--
1.6.4.225.gb589e
next prev parent reply other threads:[~2009-08-12 19:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-12 19:45 [JGIT PATCH (RESEND) 0/4] Fix race condition on loading pack files Shawn O. Pearce
2009-08-12 19:45 ` [JGIT PATCH (RESEND) 1/4] Avoid unnecessary stat when scanning packs in the objects directory Shawn O. Pearce
2009-08-12 19:45 ` [JGIT PATCH (RESEND) 2/4] Make ObjectDirectory last modified time atomically updated with list Shawn O. Pearce
2009-08-12 19:45 ` Shawn O. Pearce [this message]
2009-08-12 19:45 ` [JGIT PATCH (RESEND) 4/4] Fix racy condition when a repository is repacked 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=1250106323-19408-4-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).