From 749110b462b3147c6dfff076fb5d1bf0460a4f99 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 07 Aug 2012 08:14:15 -0400
Subject: [PATCH] Do not incrementally index blobs in submodules (issue 119)

---
 docs/04_releases.mkd                 |    1 +
 src/com/gitblit/LuceneExecutor.java  |    7 +++++--
 src/com/gitblit/utils/JGitUtils.java |   24 +++++++++++++-----------
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd
index ac3b31e..a519175 100644
--- a/docs/04_releases.mkd
+++ b/docs/04_releases.mkd
@@ -11,6 +11,7 @@
 
 #### fixes
 
+- Do not index blobs in submodules (issue 119)
 - Restore original user or team object on failure to update (issue 118)
 - Repository URL uses `X-Forwarded-Proto` and `X-Forwarded-Port`, if available, for reverse proxy configurations (issue 115)
 - Fixes to relative path determination in repository searh algorithm for symlinks (issue 116)
diff --git a/src/com/gitblit/LuceneExecutor.java b/src/com/gitblit/LuceneExecutor.java
index eafb516..d1c27f4 100644
--- a/src/com/gitblit/LuceneExecutor.java
+++ b/src/com/gitblit/LuceneExecutor.java
@@ -494,6 +494,7 @@
 				
 				Map<String, ObjectId> paths = new TreeMap<String, ObjectId>();
 				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 @@
 						// 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 4415982..90e6a76 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -559,18 +559,20 @@
 				}
 				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());

--
Gitblit v1.9.1