If we already have a given PackFile open in this repository then we should reuse the existing PackFile handle. Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../src/org/spearce/jgit/lib/PackFile.java | 5 +++++ .../src/org/spearce/jgit/lib/Repository.java | 8 +++++++- .../src/org/spearce/jgit/lib/WindowedFile.java | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java index ca5681b..fc1b6ea 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PackFile.java @@ -94,6 +94,11 @@ final PackedObjectLoader resolveBase(final WindowCursor curs, final long ofs) return reader(curs, ofs); } + /** @return the File object which locates this pack on disk. */ + public File getPackFile() { + return pack.getFile(); + } + /** * Determine if an object is contained within the pack file. * <p> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java index 89ad991..8f6e96e 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -825,6 +825,7 @@ synchronized (this) { */ public void scanForPacks() { final ArrayList<PackFile> p = new ArrayList<PackFile>(); + p.addAll(Arrays.asList(packs())); for (final File d : objectsDirs()) scanForPacks(new File(d, "pack"), p); final PackFile[] arr = new PackFile[p.size()]; @@ -843,7 +844,7 @@ public boolean accept(final File baseDir, final String n) { } }); if (idxList != null) { - for (final String indexName : idxList) { + SCAN: for (final String indexName : idxList) { final String n = indexName.substring(0, indexName.length() - 4); final File idxFile = new File(packDir, n + ".idx"); final File packFile = new File(packDir, n + ".pack"); @@ -856,6 +857,11 @@ public boolean accept(final File baseDir, final String n) { continue; } + for (final PackFile p : packList) { + if (packFile.equals(p.getPackFile())) + continue SCAN; + } + try { packList.add(new PackFile(this, idxFile, packFile)); } catch (IOException ioe) { diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java index 454f98b..f640c42 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java @@ -101,13 +101,18 @@ public long length() { return length; } + /** @return the absolute file object this file reads from. */ + public File getFile() { + return fPath.getAbsoluteFile(); + } + /** * Get the path name of this file. * * @return the absolute path name of the file. */ public String getName() { - return fPath.getAbsolutePath(); + return getFile().getPath(); } /** -- 1.6.1.rc4.301.g5497a -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html