當前位置: 首頁>>代碼示例>>Java>>正文


Java Merger類代碼示例

本文整理匯總了Java中org.eclipse.jgit.merge.Merger的典型用法代碼示例。如果您正苦於以下問題:Java Merger類的具體用法?Java Merger怎麽用?Java Merger使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Merger類屬於org.eclipse.jgit.merge包,在下文中一共展示了Merger類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: newMerger

import org.eclipse.jgit.merge.Merger; //導入依賴的package包/類
public static Merger newMerger(ObjectInserter inserter, Config repoConfig, String strategyName) {
  MergeStrategy strategy = MergeStrategy.get(strategyName);
  checkArgument(strategy != null, "invalid merge strategy: %s", strategyName);
  return strategy.newMerger(
      new ObjectInserter.Filter() {
        @Override
        protected ObjectInserter delegate() {
          return inserter;
        }

        @Override
        public void flush() {}

        @Override
        public void close() {}
      },
      repoConfig);
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:19,代碼來源:MergeUtil.java

示例2: merge

import org.eclipse.jgit.merge.Merger; //導入依賴的package包/類
@Nullable
  public static ObjectId merge(Repository repository, ObjectId source, ObjectId target, 
  		boolean squash, PersonIdent committer, String commitMessage) {
  	try (	RevWalk revWalk = new RevWalk(repository);
  			ObjectInserter inserter = repository.newObjectInserter();) {
  		RevCommit sourceCommit = revWalk.parseCommit(source);
  		RevCommit targetCommit = revWalk.parseCommit(target);
  		Merger merger = MergeStrategy.RECURSIVE.newMerger(repository, true);
  		if (merger.merge(targetCommit, sourceCommit)) {
        CommitBuilder mergedCommit = new CommitBuilder();
        mergedCommit.setAuthor(sourceCommit.getAuthorIdent());
        mergedCommit.setCommitter(committer);
        if (squash)
        	mergedCommit.setParentId(targetCommit);
        else
        	mergedCommit.setParentIds(targetCommit, sourceCommit);
        mergedCommit.setMessage(commitMessage);
        mergedCommit.setTreeId(merger.getResultTreeId());
        ObjectId mergedCommitId = inserter.insert(mergedCommit);
        inserter.flush();
        return mergedCommitId;
  		} else {
  			return null;
  		}
  	} catch (IOException e) {
  		throw new RuntimeException(e);
}
  }
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:29,代碼來源:GitUtils.java

示例3: createMergeCommit

import org.eclipse.jgit.merge.Merger; //導入依賴的package包/類
public static RevCommit createMergeCommit(
    ObjectInserter inserter,
    Config repoConfig,
    RevCommit mergeTip,
    RevCommit originalCommit,
    String mergeStrategy,
    PersonIdent committerIndent,
    String commitMsg,
    RevWalk rw)
    throws IOException, MergeIdenticalTreeException, MergeConflictException {

  if (!MergeStrategy.THEIRS.getName().equals(mergeStrategy)
      && rw.isMergedInto(originalCommit, mergeTip)) {
    throw new ChangeAlreadyMergedException(
        "'" + originalCommit.getName() + "' has already been merged");
  }

  Merger m = newMerger(inserter, repoConfig, mergeStrategy);
  if (m.merge(false, mergeTip, originalCommit)) {
    ObjectId tree = m.getResultTreeId();

    CommitBuilder mergeCommit = new CommitBuilder();
    mergeCommit.setTreeId(tree);
    mergeCommit.setParentIds(mergeTip, originalCommit);
    mergeCommit.setAuthor(committerIndent);
    mergeCommit.setCommitter(committerIndent);
    mergeCommit.setMessage(commitMsg);
    return rw.parseCommit(inserter.insert(mergeCommit));
  }
  List<String> conflicts = ImmutableList.of();
  if (m instanceof ResolveMerger) {
    conflicts = ((ResolveMerger) m).getUnmergedPaths();
  }
  throw new MergeConflictException(createConflictMessage(conflicts));
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:36,代碼來源:MergeUtil.java

示例4: newThreeWayMerger

import org.eclipse.jgit.merge.Merger; //導入依賴的package包/類
public static ThreeWayMerger newThreeWayMerger(
    ObjectInserter inserter, Config repoConfig, String strategyName) {
  Merger m = newMerger(inserter, repoConfig, strategyName);
  checkArgument(
      m instanceof ThreeWayMerger,
      "merge strategy %s does not support three-way merging",
      strategyName);
  return (ThreeWayMerger) m;
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:10,代碼來源:MergeUtil.java

示例5: apply

import org.eclipse.jgit.merge.Merger; //導入依賴的package包/類
@Override
public MergeableInfo apply(BranchResource resource)
    throws IOException, BadRequestException, ResourceNotFoundException {
  if (!(submitType.equals(SubmitType.MERGE_ALWAYS)
      || submitType.equals(SubmitType.MERGE_IF_NECESSARY))) {
    throw new BadRequestException("Submit type: " + submitType + " is not supported");
  }

  MergeableInfo result = new MergeableInfo();
  result.submitType = submitType;
  result.strategy = strategy;
  try (Repository git = gitManager.openRepository(resource.getNameKey());
      RevWalk rw = new RevWalk(git);
      ObjectInserter inserter = new InMemoryInserter(git)) {
    Merger m = MergeUtil.newMerger(inserter, git.getConfig(), strategy);

    Ref destRef = git.getRefDatabase().exactRef(resource.getRef());
    if (destRef == null) {
      throw new ResourceNotFoundException(resource.getRef());
    }

    RevCommit targetCommit = rw.parseCommit(destRef.getObjectId());
    RevCommit sourceCommit = MergeUtil.resolveCommit(git, rw, source);

    if (!commits.canRead(resource.getProjectState(), git, sourceCommit)) {
      throw new BadRequestException("do not have read permission for: " + source);
    }

    if (rw.isMergedInto(sourceCommit, targetCommit)) {
      result.mergeable = true;
      result.commitMerged = true;
      result.contentMerged = true;
      return result;
    }

    if (m.merge(false, targetCommit, sourceCommit)) {
      result.mergeable = true;
      result.commitMerged = false;
      result.contentMerged = m.getResultTreeId().equals(targetCommit.getTree());
    } else {
      result.mergeable = false;
      if (m instanceof ResolveMerger) {
        result.conflicts = ((ResolveMerger) m).getUnmergedPaths();
      }
    }
  } catch (IllegalArgumentException e) {
    throw new BadRequestException(e.getMessage());
  }
  return result;
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:51,代碼來源:CheckMergeability.java


注:本文中的org.eclipse.jgit.merge.Merger類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。