From 749110b462b3147c6dfff076fb5d1bf0460a4f99 Mon Sep 17 00:00:00 2001 From: James Moger Date: Tue, 7 Aug 2012 08:14:15 -0400 Subject: Do not incrementally index blobs in submodules (issue 119) --- src/com/gitblit/LuceneExecutor.java | 7 +++++-- src/com/gitblit/utils/JGitUtils.java | 24 +++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src/com/gitblit') diff --git a/src/com/gitblit/LuceneExecutor.java b/src/com/gitblit/LuceneExecutor.java index eafb5168..d1c27f4d 100644 --- a/src/com/gitblit/LuceneExecutor.java +++ b/src/com/gitblit/LuceneExecutor.java @@ -494,6 +494,7 @@ public class LuceneExecutor implements Runnable { Map paths = new TreeMap(); while (treeWalk.next()) { + // ensure path is not in a submodule if (treeWalk.getFileMode(0) != FileMode.GITLINK) { paths.put(treeWalk.getPathString(), treeWalk.getObjectId(0)); } @@ -679,8 +680,10 @@ public class LuceneExecutor implements Runnable { // read the blob content String str = JGitUtils.getStringContent(repository, commit.getTree(), path.path, encodings); - doc.add(new Field(FIELD_CONTENT, str, Store.YES, Index.ANALYZED)); - writer.addDocument(doc); + if (str != null) { + doc.add(new Field(FIELD_CONTENT, str, Store.YES, Index.ANALYZED)); + writer.addDocument(doc); + } } } } diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index 4415982a..90e6a76b 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -559,18 +559,20 @@ public class JGitUtils { } ObjectId entid = tw.getObjectId(0); FileMode entmode = tw.getFileMode(0); - RevObject ro = rw.lookupAny(entid, entmode.getObjectType()); - rw.parseBody(ro); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - ObjectLoader ldr = repository.open(ro.getId(), Constants.OBJ_BLOB); - byte[] tmp = new byte[4096]; - InputStream in = ldr.openStream(); - int n; - while ((n = in.read(tmp)) > 0) { - os.write(tmp, 0, n); + if (entmode != FileMode.GITLINK) { + RevObject ro = rw.lookupAny(entid, entmode.getObjectType()); + rw.parseBody(ro); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ObjectLoader ldr = repository.open(ro.getId(), Constants.OBJ_BLOB); + byte[] tmp = new byte[4096]; + InputStream in = ldr.openStream(); + int n; + while ((n = in.read(tmp)) > 0) { + os.write(tmp, 0, n); + } + in.close(); + content = os.toByteArray(); } - in.close(); - content = os.toByteArray(); } } catch (Throwable t) { error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name()); -- cgit v1.2.3