当前位置: 首页>>代码示例>>Java>>正文


Java GitRepositoryManager.openRepository方法代码示例

本文整理汇总了Java中com.google.gerrit.server.git.GitRepositoryManager.openRepository方法的典型用法代码示例。如果您正苦于以下问题:Java GitRepositoryManager.openRepository方法的具体用法?Java GitRepositoryManager.openRepository怎么用?Java GitRepositoryManager.openRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gerrit.server.git.GitRepositoryManager的用法示例。


在下文中一共展示了GitRepositoryManager.openRepository方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: refsAreStale

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
private static boolean refsAreStale(
    GitRepositoryManager repoManager,
    Change.Id id,
    Project.NameKey project,
    SetMultimap<Project.NameKey, RefState> allStates,
    ListMultimap<Project.NameKey, RefStatePattern> allPatterns) {
  try (Repository repo = repoManager.openRepository(project)) {
    Set<RefState> states = allStates.get(project);
    for (RefState state : states) {
      if (!state.match(repo)) {
        return true;
      }
    }
    for (RefStatePattern pattern : allPatterns.get(project)) {
      if (!pattern.match(repo, states)) {
        return true;
      }
    }
    return false;
  } catch (IOException e) {
    log.warn(String.format("error checking staleness of %s in %s", id, project), e);
    return true;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:StalenessChecker.java

示例2: readFromGit

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
static EditPreferencesInfo readFromGit(
    Account.Id id, GitRepositoryManager gitMgr, AllUsersName allUsersName, EditPreferencesInfo in)
    throws IOException, ConfigInvalidException, RepositoryNotFoundException {
  try (Repository git = gitMgr.openRepository(allUsersName)) {
    VersionedAccountPreferences p = VersionedAccountPreferences.forUser(id);
    p.load(git);

    return loadSection(
        p.getConfig(),
        UserConfigSections.EDIT,
        null,
        new EditPreferencesInfo(),
        EditPreferencesInfo.defaults(),
        in);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:GetEditPreferences.java

示例3: readFromGit

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
static DiffPreferencesInfo readFromGit(
    GitRepositoryManager gitMgr, AllUsersName allUsersName, DiffPreferencesInfo in)
    throws IOException, ConfigInvalidException, RepositoryNotFoundException {
  try (Repository git = gitMgr.openRepository(allUsersName)) {
    // Load all users prefs.
    VersionedAccountPreferences dp = VersionedAccountPreferences.forDefault();
    dp.load(git);
    DiffPreferencesInfo allUserPrefs = new DiffPreferencesInfo();
    loadSection(
        dp.getConfig(),
        UserConfigSections.DIFF,
        null,
        allUserPrefs,
        DiffPreferencesInfo.defaults(),
        in);
    return allUserPrefs;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:19,代码来源:GetDiffPreferences.java

示例4: readFromGit

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
static GeneralPreferencesInfo readFromGit(
    GitRepositoryManager gitMgr,
    GeneralPreferencesLoader loader,
    AllUsersName allUsersName,
    GeneralPreferencesInfo in)
    throws IOException, ConfigInvalidException, RepositoryNotFoundException {
  try (Repository git = gitMgr.openRepository(allUsersName)) {
    VersionedAccountPreferences p = VersionedAccountPreferences.forDefault();
    p.load(git);

    GeneralPreferencesInfo r =
        loadSection(
            p.getConfig(),
            UserConfigSections.GENERAL,
            null,
            new GeneralPreferencesInfo(),
            GeneralPreferencesInfo.defaults(),
            in);

    // TODO(davido): Maintain cache of default values in AllUsers repository
    return loader.loadMyMenusAndUrlAliases(r, p, null);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:24,代码来源:GetPreferences.java

示例5: create

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
public static FileResource create(
    GitRepositoryManager repoManager, ProjectState projectState, ObjectId rev, String path)
    throws ResourceNotFoundException, IOException {
  try (Repository repo = repoManager.openRepository(projectState.getNameKey());
      RevWalk rw = new RevWalk(repo)) {
    RevTree tree = rw.parseTree(rev);
    if (TreeWalk.forPath(repo, path, tree) != null) {
      return new FileResource(projectState, rev, path);
    }
  }
  throw new ResourceNotFoundException(IdString.fromDecoded(path));
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:13,代码来源:FileResource.java

示例6: RepoView

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
RepoView(GitRepositoryManager repoManager, Project.NameKey project) throws IOException {
  repo = repoManager.openRepository(project);
  inserter = repo.newObjectInserter();
  inserterWrapper = new NonFlushingInserter(inserter);
  rw = new RevWalk(inserter.newReader());
  commands = new ChainedReceiveCommands(repo);
  closeRepo = true;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:9,代码来源:RepoView.java

示例7: branchExists

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
/**
 * Checks whether the specified branch exists.
 *
 * @param repoManager Git repository manager to open the git repository
 * @param branch the branch for which it should be checked if it exists
 * @return {@code true} if the specified branch exists or if {@code HEAD} points to this branch,
 *     otherwise {@code false}
 * @throws RepositoryNotFoundException the repository of the branch's project does not exist.
 * @throws IOException error while retrieving the branch from the repository.
 */
public static boolean branchExists(final GitRepositoryManager repoManager, Branch.NameKey branch)
    throws RepositoryNotFoundException, IOException {
  try (Repository repo = repoManager.openRepository(branch.getParentKey())) {
    boolean exists = repo.getRefDatabase().exactRef(branch.get()) != null;
    if (!exists) {
      exists =
          repo.getFullBranch().equals(branch.get()) || RefNames.REFS_CONFIG.equals(branch.get());
    }
    return exists;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:ProjectUtil.java

示例8: createValue

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
@Override
public Repository createValue(Prolog engine) {
  PrologEnvironment env = (PrologEnvironment) engine.control;
  GitRepositoryManager gitMgr = env.getArgs().getGitRepositoryManager();
  Change change = getChange(engine);
  Project.NameKey projectKey = change.getProject();
  Repository repo;
  try {
    repo = gitMgr.openRepository(projectKey);
  } catch (IOException e) {
    throw new SystemException(e.getMessage());
  }
  env.addToCleanup(repo::close);
  return repo;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:16,代码来源:StoredValues.java

示例9: readFromGit

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
static DiffPreferencesInfo readFromGit(
    Account.Id id, GitRepositoryManager gitMgr, AllUsersName allUsersName, DiffPreferencesInfo in)
    throws IOException, ConfigInvalidException, RepositoryNotFoundException {
  try (Repository git = gitMgr.openRepository(allUsersName)) {
    VersionedAccountPreferences p = VersionedAccountPreferences.forUser(id);
    p.load(git);
    DiffPreferencesInfo prefs = new DiffPreferencesInfo();
    loadSection(
        p.getConfig(), UserConfigSections.DIFF, null, prefs, readDefaultsFromGit(git, in), in);
    return prefs;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:13,代码来源:GetDiffPreferences.java

示例10: getChangeKindInternal

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
private static ChangeKind getChangeKindInternal(
    ChangeKindCache cache,
    ReviewDb db,
    Change change,
    PatchSet patch,
    ChangeData.Factory changeDataFactory,
    GitRepositoryManager repoManager) {
  // TODO - dborowitz: add NEW_CHANGE type for default.
  ChangeKind kind = ChangeKind.REWORK;
  // Trivial case: if we're on the first patch, we don't need to open
  // the repository.
  if (patch.getId().get() > 1) {
    try (Repository repo = repoManager.openRepository(change.getProject());
        RevWalk rw = new RevWalk(repo)) {
      kind =
          getChangeKindInternal(
              cache, rw, repo.getConfig(), changeDataFactory.create(db, change), patch);
    } catch (IOException e) {
      // Do nothing; assume we have a complex change
      log.warn(
          "Unable to get change kind for patchSet "
              + patch.getPatchSetId()
              + "of change "
              + change.getChangeId(),
          e);
    }
  }
  return kind;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:30,代码来源:ChangeKindCacheImpl.java

示例11: rebuildOneChangeTrialMode

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
@Test
public void rebuildOneChangeTrialMode() throws Exception {
  assertNoAutoMigrateConfig(gerritConfig);
  assertNoAutoMigrateConfig(noteDbConfig);
  assertNotesMigrationState(NotesMigrationState.REVIEW_DB);
  setUpOneChange();

  migrate("--trial");
  assertNotesMigrationState(NotesMigrationState.READ_WRITE_NO_SEQUENCE);

  try (ServerContext ctx = startServer()) {
    GitRepositoryManager repoManager = ctx.getInjector().getInstance(GitRepositoryManager.class);
    ObjectId metaId;
    try (Repository repo = repoManager.openRepository(project)) {
      Ref ref = repo.exactRef(RefNames.changeMetaRef(changeId));
      assertThat(ref).isNotNull();
      metaId = ref.getObjectId();
    }

    try (ReviewDb db = openUnderlyingReviewDb(ctx)) {
      Change c = db.changes().get(changeId);
      assertThat(c).isNotNull();
      NoteDbChangeState state = NoteDbChangeState.parse(c);
      assertThat(state).isNotNull();
      assertThat(state.getPrimaryStorage()).isEqualTo(PrimaryStorage.REVIEW_DB);
      assertThat(state.getRefState()).hasValue(RefState.create(metaId, ImmutableMap.of()));
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:30,代码来源:StandaloneNoteDbMigrationIT.java

示例12: migrateOneChange

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
@Test
public void migrateOneChange() throws Exception {
  assertNoAutoMigrateConfig(gerritConfig);
  assertNoAutoMigrateConfig(noteDbConfig);
  assertNotesMigrationState(NotesMigrationState.REVIEW_DB);
  setUpOneChange();

  migrate();
  assertNotesMigrationState(NotesMigrationState.NOTE_DB);

  try (ServerContext ctx = startServer()) {
    GitRepositoryManager repoManager = ctx.getInjector().getInstance(GitRepositoryManager.class);
    try (Repository repo = repoManager.openRepository(project)) {
      assertThat(repo.exactRef(RefNames.changeMetaRef(changeId))).isNotNull();
    }

    try (ReviewDb db = openUnderlyingReviewDb(ctx)) {
      Change c = db.changes().get(changeId);
      assertThat(c).isNotNull();
      NoteDbChangeState state = NoteDbChangeState.parse(c);
      assertThat(state).isNotNull();
      assertThat(state.getPrimaryStorage()).isEqualTo(PrimaryStorage.NOTE_DB);
      assertThat(state.getRefState()).isEmpty();

      ChangeInput in = new ChangeInput(project.get(), "master", "NoteDb-only change");
      in.newBranch = true;
      GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
      Change.Id id2 = new Change.Id(gApi.changes().create(in).info()._number);
      assertThat(db.changes().get(id2)).isNull();
    }
  }
  assertNoAutoMigrateConfig(gerritConfig);
  assertAutoMigrateConfig(noteDbConfig, false);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:35,代码来源:StandaloneNoteDbMigrationIT.java

示例13: newUpdate

import com.google.gerrit.server.git.GitRepositoryManager; //导入方法依赖的package包/类
public static ChangeUpdate newUpdate(Injector injector, Change c, CurrentUser user)
    throws Exception {
  injector =
      injector.createChildInjector(
          new FactoryModule() {
            @Override
            public void configure() {
              bind(CurrentUser.class).toInstance(user);
            }
          });
  ChangeUpdate update =
      injector
          .getInstance(ChangeUpdate.Factory.class)
          .create(
              new ChangeNotes(injector.getInstance(AbstractChangeNotes.Args.class), c).load(),
              user,
              TimeUtil.nowTs(),
              Ordering.<String>natural());

  ChangeNotes notes = update.getNotes();
  boolean hasPatchSets = notes.getPatchSets() != null && !notes.getPatchSets().isEmpty();
  NotesMigration migration = injector.getInstance(NotesMigration.class);
  if (hasPatchSets || !migration.readChanges()) {
    return update;
  }

  // Change doesn't exist yet. NoteDb requires that there be a commit for the
  // first patch set, so create one.
  GitRepositoryManager repoManager = injector.getInstance(GitRepositoryManager.class);
  try (Repository repo = repoManager.openRepository(c.getProject())) {
    TestRepository<Repository> tr = new TestRepository<>(repo);
    PersonIdent ident =
        user.asIdentifiedUser().newCommitterIdent(update.getWhen(), TimeZone.getDefault());
    TestRepository<Repository>.CommitBuilder cb =
        tr.commit()
            .author(ident)
            .committer(ident)
            .message(firstNonNull(c.getSubject(), "Test change"));
    Ref parent = repo.exactRef(c.getDest().get());
    if (parent != null) {
      cb.parent(tr.getRevWalk().parseCommit(parent.getObjectId()));
    }
    update.setBranch(c.getDest().get());
    update.setChangeId(c.getKey().get());
    update.setCommit(tr.getRevWalk(), cb.create());
    return update;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:49,代码来源:TestChanges.java


注:本文中的com.google.gerrit.server.git.GitRepositoryManager.openRepository方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。