use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class AccountIT method stalenessChecker.
@Test
// Instants
@SuppressWarnings("JdkObsolete")
public void stalenessChecker() throws Exception {
// Newly created account is not stale.
AccountInfo accountInfo = gApi.accounts().create(name("foo")).get();
Account.Id accountId = Account.id(accountInfo._accountId);
assertThat(stalenessChecker.check(accountId).isStale()).isFalse();
// Manually updating the user ref makes the index document stale.
String userRef = RefNames.refsUsers(accountId);
try (Repository repo = repoManager.openRepository(allUsers);
ObjectInserter oi = repo.newObjectInserter();
RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(repo.exactRef(userRef).getObjectId());
PersonIdent ident = new PersonIdent(serverIdent.get(), Date.from(TimeUtil.now()));
CommitBuilder cb = new CommitBuilder();
cb.setTreeId(commit.getTree());
cb.setCommitter(ident);
cb.setAuthor(ident);
cb.setMessage(commit.getFullMessage());
ObjectId emptyCommit = oi.insert(cb);
oi.flush();
RefUpdate updateRef = repo.updateRef(userRef);
updateRef.setExpectedOldObjectId(commit.toObjectId());
updateRef.setNewObjectId(emptyCommit);
assertThat(updateRef.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);
}
assertStaleAccountAndReindex(accountId);
// stale.
try (Repository repo = repoManager.openRepository(allUsers)) {
ExternalIdNotes extIdNotes = ExternalIdNotes.load(allUsers, repo, externalIdFactory, authConfig.isUserNameCaseInsensitiveMigrationMode());
ExternalId.Key key = externalIdKeyFactory.create("foo", "foo");
extIdNotes.insert(externalIdFactory.create(key, accountId));
try (MetaDataUpdate update = metaDataUpdateFactory.create(allUsers)) {
extIdNotes.commit(update);
}
assertStaleAccountAndReindex(accountId);
extIdNotes = ExternalIdNotes.load(allUsers, repo, externalIdFactory, authConfig.isUserNameCaseInsensitiveMigrationMode());
extIdNotes.upsert(externalIdFactory.createWithEmail(key, accountId, "foo@example.com"));
try (MetaDataUpdate update = metaDataUpdateFactory.create(allUsers)) {
extIdNotes.commit(update);
}
assertStaleAccountAndReindex(accountId);
extIdNotes = ExternalIdNotes.load(allUsers, repo, externalIdFactory, authConfig.isUserNameCaseInsensitiveMigrationMode());
extIdNotes.delete(accountId, key);
try (MetaDataUpdate update = metaDataUpdateFactory.create(allUsers)) {
extIdNotes.commit(update);
}
assertStaleAccountAndReindex(accountId);
}
// Manually delete account
try (Repository repo = repoManager.openRepository(allUsers);
RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(repo.exactRef(userRef).getObjectId());
RefUpdate updateRef = repo.updateRef(userRef);
updateRef.setExpectedOldObjectId(commit.toObjectId());
updateRef.setNewObjectId(ObjectId.zeroId());
updateRef.setForceUpdate(true);
assertThat(updateRef.delete()).isEqualTo(RefUpdate.Result.FORCED);
}
assertStaleAccountAndReindex(accountId);
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method setUseSignedOffBy.
protected void setUseSignedOffBy(InheritableBoolean value) throws Exception {
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
ProjectConfig config = projectConfigFactory.read(md);
config.updateProject(p -> p.setBooleanConfig(BooleanProjectConfig.USE_SIGNED_OFF_BY, value));
config.commit(md);
projectCache.evictAndReindex(config.getProject());
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class LocalUsernamesToLowerCase method run.
@Override
public int run() throws Exception {
Injector dbInjector = createDbInjector();
manager.add(dbInjector, dbInjector.createChildInjector(NoteDbSchemaVersionCheck.module()));
manager.start();
dbInjector.createChildInjector(new FactoryModule() {
@Override
protected void configure() {
bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
factory(MetaDataUpdate.InternalFactory.class);
// The LocalUsernamesToLowerCase program needs to access all external IDs only
// once to update them. After the update they are not accessed again. Hence the
// LocalUsernamesToLowerCase program doesn't benefit from caching external IDs and
// the external ID cache can be disabled.
install(DisabledExternalIdCache.module());
}
}).injectMembers(this);
Collection<ExternalId> todo = externalIds.all();
monitor.beginTask("Converting local usernames", todo.size());
try (Repository repo = repoManager.openRepository(allUsersName)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(repo);
for (ExternalId extId : todo) {
convertLocalUserToLowerCase(extIdNotes, extId);
monitor.update(1);
}
try (MetaDataUpdate metaDataUpdate = metaDataUpdateServerFactory.get().create(allUsersName)) {
metaDataUpdate.setMessage("Convert local usernames to lower case");
extIdNotes.commit(metaDataUpdate);
}
}
monitor.endTask();
int exitCode = reindexAccounts();
manager.stop();
return exitCode;
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class GroupsOnInit method createMetaDataUpdate.
private MetaDataUpdate createMetaDataUpdate(Repository repository, PersonIdent personIdent) {
MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsers, repository);
metaDataUpdate.getCommitBuilder().setAuthor(personIdent);
metaDataUpdate.getCommitBuilder().setCommitter(personIdent);
return metaDataUpdate;
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class ExternalIdsOnInit method insert.
public synchronized void insert(String commitMessage, Collection<ExternalId> extIds) throws IOException, ConfigInvalidException {
File path = getPath();
if (path != null) {
try (Repository allUsersRepo = new FileRepository(path)) {
ExternalIdNotes extIdNotes = ExternalIdNotes.load(allUsers, allUsersRepo, externalIdFactory, authConfig.isUserNameCaseInsensitiveMigrationMode());
extIdNotes.insert(extIds);
try (MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsers, allUsersRepo)) {
PersonIdent serverIdent = new GerritPersonIdentProvider(flags.cfg).get();
metaDataUpdate.getCommitBuilder().setAuthor(serverIdent);
metaDataUpdate.getCommitBuilder().setCommitter(serverIdent);
metaDataUpdate.getCommitBuilder().setMessage(commitMessage);
extIdNotes.commit(metaDataUpdate);
}
}
}
}
Aggregations