当前位置: 首页>>代码示例>>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;未经允许,请勿转载。