patch-to-current feature.
| | |
| | | }
|
| | |
|
| | | public static String getCommitPatch(Repository r, RevCommit commit, String path) {
|
| | | return getCommitPatch(r, null, commit, path);
|
| | | }
|
| | | |
| | | public static String getCommitPatch(Repository r, RevCommit baseCommit, RevCommit commit, String path) {
|
| | | try {
|
| | | final RevWalk rw = new RevWalk(r);
|
| | | RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
|
| | | RevTree parentTree = parent.getTree();
|
| | | RevTree baseTree;
|
| | | if (baseCommit == null) {
|
| | | final RevWalk rw = new RevWalk(r);
|
| | | RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
|
| | | baseTree = parent.getTree();
|
| | | } else {
|
| | | baseTree = baseCommit.getTree();
|
| | | }
|
| | | RevTree commitTree = commit.getTree();
|
| | |
|
| | | final TreeWalk walk = new TreeWalk(r);
|
| | | walk.reset();
|
| | | walk.setRecursive(true);
|
| | | walk.addTree(parentTree);
|
| | | walk.addTree(baseTree);
|
| | | walk.addTree(commitTree);
|
| | | walk.setFilter(TreeFilter.ANY_DIFF);
|
| | |
|
| | |
| | | df.setRepository(r);
|
| | | df.setDiffComparator(cmp);
|
| | | df.setDetectRenames(true);
|
| | | List<DiffEntry> diffs = df.scan(parentTree, commitTree);
|
| | | List<DiffEntry> diffs = df.scan(baseTree, commitTree);
|
| | | if (path != null && path.length() > 0) {
|
| | | for (DiffEntry diff : diffs) {
|
| | | if (diff.getNewPath().equalsIgnoreCase(path)) {
|
| | |
| | | if (StringUtils.isEmpty(baseObjectId)) {
|
| | | // use first parent
|
| | | diff = JGitUtils.getCommitDiff(r, commit, blobPath, true);
|
| | | add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
|
| | | } else {
|
| | | // base commit specified
|
| | | RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
|
| | | diff = JGitUtils.getCommitDiff(r, baseCommit, commit, blobPath, true);
|
| | | add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId, blobPath)));
|
| | | }
|
| | |
|
| | | add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
|
| | | add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
|
| | | add(new BookmarkablePageLink<Void>("commitDiffLink", CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
|
| | |
|
| | |
| | |
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | |
|
| | | public class PatchPage extends WebPage {
|
| | |
| | | redirectToInterceptPage(new RepositoriesPage());
|
| | | }
|
| | | final String repositoryName = WicketUtils.getRepositoryName(params);
|
| | | final String baseObjectId = WicketUtils.getBaseObjectId(params);
|
| | | final String objectId = WicketUtils.getObject(params);
|
| | | final String blobPath = WicketUtils.getPath(params);
|
| | |
|
| | |
| | | }
|
| | |
|
| | | RevCommit commit = JGitUtils.getCommit(r, objectId);
|
| | | String patch = JGitUtils.getCommitPatch(r, commit, blobPath);
|
| | | String patch;
|
| | | if (StringUtils.isEmpty(baseObjectId)) {
|
| | | patch = JGitUtils.getCommitPatch(r, commit, blobPath);
|
| | | } else {
|
| | | RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
|
| | | patch = JGitUtils.getCommitPatch(r, baseCommit, commit, blobPath); |
| | | }
|
| | | add(new Label("patchText", patch));
|
| | | r.close();
|
| | | }
|