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


Java PathChangeModel.from方法代码示例

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


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

示例1: getFilesInRange

import com.gitblit.models.PathModel.PathChangeModel; //导入方法依赖的package包/类
/**
 * Returns the list of files changed in a specified commit. If the repository does not exist or is empty, an empty list is returned.
 * 
 * @param repository
 * @param startCommit
 *            earliest commit
 * @param endCommit
 *            most recent commit. if null, HEAD is assumed.
 * @return list of files changed in a commit range
 */
public static List<PathChangeModel> getFilesInRange(Repository repository, RevCommit startCommit, RevCommit endCommit) {
	List<PathChangeModel> list = new ArrayList<PathChangeModel>();
	if (!hasCommits(repository)) {
		return list;
	}
	try (DiffFormatter df = new DiffFormatter(null)) {
		df.setRepository(repository);
		df.setDiffComparator(RawTextComparator.DEFAULT);
		df.setDetectRenames(true);

		List<DiffEntry> diffEntries = df.scan(startCommit.getTree(), endCommit.getTree());
		for (DiffEntry diff : diffEntries) {
			PathChangeModel pcm = PathChangeModel.from(diff, endCommit.getName());
			list.add(pcm);
		}
		Collections.sort(list);
	} catch (Throwable t) {
		error(t, repository, "{0} failed to determine files in range {1}..{2}!", startCommit, endCommit);
	}
	return list;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:32,代码来源:JGitUtils.java

示例2: getFilesInCommit

import com.gitblit.models.PathModel.PathChangeModel; //导入方法依赖的package包/类
/**
 * Returns the list of files changed in a specified commit. If the repository does not exist or is empty, an empty list is returned.
 * 
 * @param repository
 * @param commit
 *            if null, HEAD is assumed.
 * @param calculateDiffStat
 *            if true, each PathChangeModel will have insertions/deletions
 * @return list of files changed in a commit
 */
public static List<PathChangeModel> getFilesInCommit(Repository repository, RevCommit commit, boolean calculateDiffStat) {
	List<PathChangeModel> list = new ArrayList<PathChangeModel>();
	if (!hasCommits(repository)) {
		return list;
	}
	RevWalk rw = new RevWalk(repository);
	try {
		if (commit == null) {
			ObjectId object = getDefaultBranch(repository);
			commit = rw.parseCommit(object);
		}

		if (commit.getParentCount() == 0) {
			try (TreeWalk tw = new TreeWalk(repository)) {
				tw.reset();
				tw.setRecursive(true);
				tw.addTree(commit.getTree());
				while (tw.next()) {
					list.add(new PathChangeModel(tw.getPathString(), tw.getPathString(), 0, tw.getRawMode(0), tw.getObjectId(0).getName(), commit
							.getId().getName(), ChangeType.ADD));
				}
			}
		} else {
			RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
			try (DiffStatFormatter df = new DiffStatFormatter(commit.getName())) {
				df.setRepository(repository);
				df.setDiffComparator(RawTextComparator.DEFAULT);
				df.setDetectRenames(true);
				List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
				for (DiffEntry diff : diffs) {
					// create the path change model
					PathChangeModel pcm = PathChangeModel.from(diff, commit.getName());

					if (calculateDiffStat) {
						// update file diffstats
						df.format(diff);
						PathChangeModel pathStat = df.getDiffStat().getPath(pcm.path);
						if (pathStat != null) {
							pcm.insertions = pathStat.insertions;
							pcm.deletions = pathStat.deletions;
						}
					}
					list.add(pcm);
				}
			}
		}
	} catch (Throwable t) {
		error(t, repository, "{0} failed to determine files in commit!");
	} finally {
		rw.close();
		rw.dispose();
	}
	return list;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:65,代码来源:JGitUtils.java

示例3: addPath

import com.gitblit.models.PathModel.PathChangeModel; //导入方法依赖的package包/类
public PathChangeModel addPath(DiffEntry entry) {
	PathChangeModel pcm = PathChangeModel.from(entry, commitId);
	paths.add(pcm);
	return pcm;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:6,代码来源:DiffUtils.java


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