Class MetaDataUpdate.User

java.lang.Object
com.google.gerrit.server.git.meta.MetaDataUpdate.User
Enclosing class:
MetaDataUpdate

public static class MetaDataUpdate.User extends Object
  • Method Details

    • getUserPersonIdent

      public org.eclipse.jgit.lib.PersonIdent getUserPersonIdent()
    • create

      public MetaDataUpdate create(Project.NameKey name) throws org.eclipse.jgit.errors.RepositoryNotFoundException, IOException
      Throws:
      org.eclipse.jgit.errors.RepositoryNotFoundException
      IOException
    • create

      public MetaDataUpdate create(Project.NameKey name, IdentifiedUser user) throws org.eclipse.jgit.errors.RepositoryNotFoundException, IOException
      Throws:
      org.eclipse.jgit.errors.RepositoryNotFoundException
      IOException
    • create

      public MetaDataUpdate create(Project.NameKey name, IdentifiedUser user, org.eclipse.jgit.lib.BatchRefUpdate batch) throws org.eclipse.jgit.errors.RepositoryNotFoundException, IOException
      Create an update using an existing batch ref update.

      This allows batching together updates to multiple metadata refs. For making multiple commits to a single metadata ref, see VersionedMetaData.openUpdate(MetaDataUpdate).

      Parameters:
      name - project name.
      user - user for the update.
      batch - batch update to use; the caller is responsible for committing the update.
      Throws:
      org.eclipse.jgit.errors.RepositoryNotFoundException
      IOException
    • create

      public MetaDataUpdate create(Project.NameKey name, org.eclipse.jgit.lib.Repository repository, IdentifiedUser user, org.eclipse.jgit.lib.BatchRefUpdate batch)
      Create an update using an existing batch ref update.

      This allows batching together updates to multiple metadata refs. For making multiple commits to a single metadata ref, see VersionedMetaData.openUpdate(MetaDataUpdate).

      Important: Create a new MetaDataUpdate instance for each update:

       
         try (Repository repo = repoMgr.openRepository(allUsersName);
             RevWalk rw = new RevWalk(repo)) {
           BatchRefUpdate batchUpdate = repo.getRefDatabase().newBatchUpdate();
           // WRONG: create the MetaDataUpdate instance here and reuse it for
           //        all updates in the loop
           for(Map.Entry<Account.Id, DiffPreferencesInfo> e : diffPrefsFromDb) {
             // CORRECT: create a new MetaDataUpdate instance for each update
             try (MetaDataUpdate md =
                 metaDataUpdateFactory.create(allUsersName, batchUpdate)) {
               md.setMessage("Import diff preferences from reviewdb\n");
               VersionedAccountPreferences vPrefs =
                   VersionedAccountPreferences.forUser(e.getKey());
               storeSection(vPrefs.getConfig(), UserConfigSections.DIFF, null,
                   e.getValue(), DiffPreferencesInfo.defaults());
               vPrefs.commit(md);
             } catch (ConfigInvalidException e) {
               // TODO handle exception
             }
           }
           batchUpdate.execute(rw, NullProgressMonitor.INSTANCE);
         }
       
       
      Parameters:
      name - project name.
      repository - the repository to update; the caller is responsible for closing the repository.
      user - user for the update.
      batch - batch update to use; the caller is responsible for committing the update.