Skip to content

Commit

Permalink
Issue #513
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrojdeCTL committed Oct 1, 2018
1 parent 19ed965 commit e2b3c7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
Expand Down Expand Up @@ -350,10 +351,13 @@ public String getRemoteCommit(String branch) throws Exception {
return null;
}

public long getCommitTime(String commitId) throws Exception {
public Long getCommitTime(String commitId) throws Exception {
try (RevWalk revWalk = new RevWalk(localRepo)) {
return revWalk.parseCommit(ObjectId.fromString(commitId)).getCommitterIdent().getWhen().getTime();
}
catch (MissingObjectException e) { // Means commit is not known to local repo (need a fetch)
return null;
}
}

public String getBranch() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public void start() {
}
// Proceed if latest commit from VALUE table doesn't match current local Git commit (Potential import done in other instance)
if (latestImportCommit != null && !vcs.getCommit().equals(latestImportCommit)) {
Date localCommitTime = new Date(vcs.getCommitTime(vcs.getCommit()));
Date lastImportTime = new Date(vcs.getCommitTime(latestImportCommit));
Long localCommitTime = vcs.getCommitTime(vcs.getCommit());
Long lastImportTime = vcs.getCommitTime(latestImportCommit);
// Check if import commit is newer than the current local commit - Otherwise, means new local commit - asset saved, or new instance spun up
if (localCommitTime.getTime() < lastImportTime.getTime()) {
if (lastImportTime == null || localCommitTime < lastImportTime) {
logger.info("Detected Asset Import in cluster. Performing Asset Import...");
bulletin = SystemMessages.bulletinOn("Asset import in progress...");
Import importer = new Import(gitRoot, vcs, branch, gitHardReset, dbAccess.getConnection());
Expand Down

0 comments on commit e2b3c7a

Please sign in to comment.