Browse Source

Remove use of GitIndex to detect index changes

We can detect index changes using FileSnapshot. This is more efficient
and removes usage of a deprecated class.

Change-Id: I4a679102c9a1bd8e82b9ca93eb9dbbde445e9be4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-1.2
Matthias Sohn 13 years ago
parent
commit
46771e9e88
  1. 31
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java

31
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java

@ -56,6 +56,7 @@ import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.events.ConfigChangedEvent;
import org.eclipse.jgit.events.ConfigChangedListener;
import org.eclipse.jgit.events.IndexChangedEvent;
import org.eclipse.jgit.lib.BaseRepositoryBuilder;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
@ -105,6 +106,8 @@ public class FileRepository extends Repository {
private final ObjectDirectory objectDatabase;
private FileSnapshot snapshot;
/**
* Construct a representation of a Git repository.
* <p>
@ -187,6 +190,9 @@ public class FileRepository extends Repository {
repositoryFormatVersion));
}
}
if (!isBare())
snapshot = FileSnapshot.save(getIndexFile());
}
private void loadSystemConfig() throws IOException {
@ -371,15 +377,26 @@ public class FileRepository extends Repository {
objectDatabase.openPack(pack, idx);
}
/**
* Force a scan for changed refs.
*
* @throws IOException
*/
@Override
public void scanForRepoChanges() throws IOException {
getAllRefs(); // This will look for changes to refs
if (!isBare())
getIndex(); // This will detect changes in the index
detectIndexChanges();
}
/**
* Detect index changes.
*/
private void detectIndexChanges() {
if (isBare())
return;
File indexFile = getIndexFile();
if (snapshot == null)
snapshot = FileSnapshot.save(indexFile);
else if (snapshot.isModified(indexFile)) {
snapshot = FileSnapshot.save(indexFile);
fireEvent(new IndexChangedEvent());
}
}
/**

Loading…
Cancel
Save