Include tip SHA-1 of notedb graph in change ETag
Change-Id: I3febdf3a95fc3f2d15288e577e699f5b38fee4c5
This commit is contained in:
committed by
David Pursehouse
parent
64eb1e2f21
commit
0dc6256cca
@@ -26,6 +26,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -68,11 +69,24 @@ public class ChangeResource implements RestResource, HasETag {
|
||||
: 0);
|
||||
|
||||
byte[] buf = new byte[20];
|
||||
ObjectId noteId;
|
||||
try {
|
||||
noteId = getNotes().loadRevision();
|
||||
} catch (OrmException e) {
|
||||
noteId = null; // This ETag will be invalidated if it loads next time.
|
||||
}
|
||||
hashObjectId(h, noteId, buf);
|
||||
// TODO(dborowitz): Include more notedb and other related refs, e.g. drafts
|
||||
// and edits.
|
||||
|
||||
for (ProjectState p : control.getProjectControl().getProjectState().tree()) {
|
||||
ObjectId id = p.getConfig().getRevision();
|
||||
MoreObjects.firstNonNull(id, ObjectId.zeroId()).copyRawTo(buf, 0);
|
||||
h.putBytes(buf);
|
||||
hashObjectId(h, p.getConfig().getRevision(), buf);
|
||||
}
|
||||
return h.hash().toString();
|
||||
}
|
||||
|
||||
private void hashObjectId(Hasher h, ObjectId id, byte[] buf) {
|
||||
MoreObjects.firstNonNull(id, ObjectId.zeroId()).copyRawTo(buf, 0);
|
||||
h.putBytes(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import com.google.gerrit.server.git.VersionedMetaData;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -69,6 +71,26 @@ public abstract class AbstractChangeNotes<T> extends VersionedMetaData {
|
||||
return self();
|
||||
}
|
||||
|
||||
public ObjectId loadRevision() throws OrmException {
|
||||
if (loaded) {
|
||||
return getRevision();
|
||||
} else if (!migration.enabled()) {
|
||||
return null;
|
||||
}
|
||||
Repository repo;
|
||||
try {
|
||||
repo = repoManager.openMetadataRepository(getProjectName());
|
||||
try {
|
||||
Ref ref = repo.getRef(getRefName());
|
||||
return ref != null ? ref.getObjectId() : null;
|
||||
} finally {
|
||||
repo.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new OrmException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Load default values for any instance variables when notedb is disabled. */
|
||||
protected abstract void loadDefaults();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user