AddCommand: Avoid unnecessary string conversions
Change-Id: I13634caeccd9f675a86adfdfa94099b6fb75463a
This commit is contained in:
parent
bb8627bd9b
commit
a94e517940
|
@ -155,7 +155,7 @@ public DirCache call() throws GitAPIException, NoFilepatternException {
|
||||||
if (!addAll)
|
if (!addAll)
|
||||||
tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));
|
tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));
|
||||||
|
|
||||||
String lastAddedFile = null;
|
byte[] lastAdded = null;
|
||||||
|
|
||||||
while (tw.next()) {
|
while (tw.next()) {
|
||||||
DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
||||||
|
@ -168,8 +168,11 @@ public DirCache call() throws GitAPIException, NoFilepatternException {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = tw.getPathString();
|
DirCacheEntry entry = c != null ? c.getDirCacheEntry() : null;
|
||||||
if (path.equals(lastAddedFile)) {
|
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
|
// In case of an existing merge conflict the
|
||||||
// DirCacheBuildIterator iterates over all stages of
|
// DirCacheBuildIterator iterates over all stages of
|
||||||
// this path, we however want to add only one
|
// this path, we however want to add only one
|
||||||
|
@ -180,27 +183,28 @@ public DirCache call() throws GitAPIException, NoFilepatternException {
|
||||||
if (f == null) { // working tree file does not exist
|
if (f == null) { // working tree file does not exist
|
||||||
if (c != null
|
if (c != null
|
||||||
&& (!update || GITLINK == c.getEntryFileMode())) {
|
&& (!update || GITLINK == c.getEntryFileMode())) {
|
||||||
builder.add(c.getDirCacheEntry());
|
builder.add(entry);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c != null && c.getDirCacheEntry() != null
|
if (entry != null && entry.isAssumeValid()) {
|
||||||
&& c.getDirCacheEntry().isAssumeValid()) {
|
|
||||||
// Index entry is marked assume valid. Even though
|
// Index entry is marked assume valid. Even though
|
||||||
// the user specified the file to be added JGit does
|
// the user specified the file to be added JGit does
|
||||||
// not consider the file for addition.
|
// not consider the file for addition.
|
||||||
builder.add(c.getDirCacheEntry());
|
builder.add(entry);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
long sz = f.getEntryLength();
|
byte[] path = tw.getRawPath();
|
||||||
DirCacheEntry entry = new DirCacheEntry(path);
|
if (entry == null || entry.getStage() > 0) {
|
||||||
|
entry = new DirCacheEntry(path);
|
||||||
|
}
|
||||||
FileMode mode = f.getIndexFileMode(c);
|
FileMode mode = f.getIndexFileMode(c);
|
||||||
entry.setFileMode(mode);
|
entry.setFileMode(mode);
|
||||||
|
|
||||||
if (GITLINK != mode) {
|
if (GITLINK != mode) {
|
||||||
entry.setLength(sz);
|
entry.setLength(f.getEntryLength());
|
||||||
entry.setLastModified(f.getEntryLastModified());
|
entry.setLastModified(f.getEntryLastModified());
|
||||||
long len = f.getEntryContentLength();
|
long len = f.getEntryContentLength();
|
||||||
try (InputStream in = f.openEntryStream()) {
|
try (InputStream in = f.openEntryStream()) {
|
||||||
|
@ -208,10 +212,12 @@ public DirCache call() throws GitAPIException, NoFilepatternException {
|
||||||
entry.setObjectId(id);
|
entry.setObjectId(id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
entry.setLength(0);
|
||||||
|
entry.setLastModified(0);
|
||||||
entry.setObjectId(f.getEntryObjectId());
|
entry.setObjectId(f.getEntryObjectId());
|
||||||
}
|
}
|
||||||
builder.add(entry);
|
builder.add(entry);
|
||||||
lastAddedFile = path;
|
lastAdded = path;
|
||||||
}
|
}
|
||||||
inserter.flush();
|
inserter.flush();
|
||||||
builder.commit();
|
builder.commit();
|
||||||
|
|
Loading…
Reference in New Issue