summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <sop@google.com>2015-12-28 14:24:30 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2015-12-28 14:24:33 -0500
commit21cec184b7ba99efcda8b05f78d1745fee32e7a3 (patch)
tree489201a106ff1e516d31fd5a037b12fb28e38c82
parent2fdce1ef8cac73a6f043a12ab413cd3c1dbc291a (diff)
parenta94e517940b6c7a5173bba5cb8b3312755751b7d (diff)
downloadjgit-21cec184b7ba99efcda8b05f78d1745fee32e7a3.tar.gz
jgit-21cec184b7ba99efcda8b05f78d1745fee32e7a3.zip
Merge "AddCommand: Avoid unnecessary string conversions"
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java28
1 files changed, 17 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
index 40102447a3..8a2c08c805 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
@@ -155,7 +155,7 @@ public class AddCommand extends GitCommand<DirCache> {
if (!addAll)
tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));
- String lastAddedFile = null;
+ byte[] lastAdded = null;
while (tw.next()) {
DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
@@ -168,8 +168,11 @@ public class AddCommand extends GitCommand<DirCache> {
continue;
}
- String path = tw.getPathString();
- if (path.equals(lastAddedFile)) {
+ DirCacheEntry entry = c != null ? c.getDirCacheEntry() : null;
+ if (entry != null && entry.getStage() > 0
+ && lastAdded != null
+ && lastAdded.length == tw.getPathLength()
+ && tw.isPathPrefix(lastAdded, lastAdded.length) == 0) {
// In case of an existing merge conflict the
// DirCacheBuildIterator iterates over all stages of
// this path, we however want to add only one
@@ -180,27 +183,28 @@ public class AddCommand extends GitCommand<DirCache> {
if (f == null) { // working tree file does not exist
if (c != null
&& (!update || GITLINK == c.getEntryFileMode())) {
- builder.add(c.getDirCacheEntry());
+ builder.add(entry);
}
continue;
}
- if (c != null && c.getDirCacheEntry() != null
- && c.getDirCacheEntry().isAssumeValid()) {
+ if (entry != null && entry.isAssumeValid()) {
// Index entry is marked assume valid. Even though
// the user specified the file to be added JGit does
// not consider the file for addition.
- builder.add(c.getDirCacheEntry());
+ builder.add(entry);
continue;
}
- long sz = f.getEntryLength();
- DirCacheEntry entry = new DirCacheEntry(path);
+ byte[] path = tw.getRawPath();
+ if (entry == null || entry.getStage() > 0) {
+ entry = new DirCacheEntry(path);
+ }
FileMode mode = f.getIndexFileMode(c);
entry.setFileMode(mode);
if (GITLINK != mode) {
- entry.setLength(sz);
+ entry.setLength(f.getEntryLength());
entry.setLastModified(f.getEntryLastModified());
long len = f.getEntryContentLength();
try (InputStream in = f.openEntryStream()) {
@@ -208,10 +212,12 @@ public class AddCommand extends GitCommand<DirCache> {
entry.setObjectId(id);
}
} else {
+ entry.setLength(0);
+ entry.setLastModified(0);
entry.setObjectId(f.getEntryObjectId());
}
builder.add(entry);
- lastAddedFile = path;
+ lastAdded = path;
}
inserter.flush();
builder.commit();