use of org.eclipse.jgit.lib.AbbreviatedObjectId in project egit by eclipse.
the class RebaseInteractiveView method createPartControl.
@Override
public void createPartControl(Composite parent) {
GridLayoutFactory.fillDefaults().applyTo(parent);
final FormToolkit toolkit = new FormToolkit(parent.getDisplay());
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
toolkit.dispose();
}
});
form = createForm(parent, toolkit);
createCommandToolBar(form, toolkit);
planTreeViewer = createPlanTreeViewer(form.getBody(), toolkit);
planLayout = new PlanLayout();
planTreeViewer.getTree().getParent().setLayout(planLayout);
createColumns(planLayout);
createStepActionToolBar(toolkit);
createPopupMenu(planTreeViewer);
setupListeners();
createLocalDragandDrop();
planTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
PlanElement element = (PlanElement) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (element == null)
return;
RepositoryCommit commit = loadCommit(element.getCommit());
if (commit != null)
CommitEditor.openQuiet(commit);
}
private RepositoryCommit loadCommit(AbbreviatedObjectId abbreviatedObjectId) {
if (abbreviatedObjectId != null) {
try (RevWalk walk = new RevWalk(RebaseInteractiveView.this.currentRepository)) {
Collection<ObjectId> resolved = walk.getObjectReader().resolve(abbreviatedObjectId);
if (resolved.size() == 1) {
RevCommit commit = walk.parseCommit(resolved.iterator().next());
return new RepositoryCommit(RebaseInteractiveView.this.currentRepository, commit);
}
} catch (IOException e) {
return null;
}
}
return null;
}
});
prefListener = new IPreferenceChangeListener() {
@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (!RepositoryUtil.PREFS_DIRECTORIES_REL.equals(event.getKey())) {
return;
}
final Repository repo = currentRepository;
if (repo == null)
return;
if (Activator.getDefault().getRepositoryUtil().contains(repo))
return;
// Unselect repository as it has been removed
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
currentRepository = null;
showRepository(null);
}
});
}
};
InstanceScope.INSTANCE.getNode(org.eclipse.egit.core.Activator.getPluginId()).addPreferenceChangeListener(prefListener);
uiPrefsListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property) || UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(property)) {
refresh();
}
}
};
Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolbar = actionBars.getToolBarManager();
listenOnRepositoryViewSelection = RebaseInteractivePreferences.isReactOnSelection();
// link with selection
Action linkSelectionAction = new BooleanPrefAction((IPersistentPreferenceStore) Activator.getDefault().getPreferenceStore(), UIPreferences.REBASE_INTERACTIVE_SYNC_SELECTION, UIText.InteractiveRebaseView_LinkSelection) {
@Override
public void apply(boolean value) {
listenOnRepositoryViewSelection = value;
}
};
linkSelectionAction.setImageDescriptor(UIIcons.ELCL16_SYNCED);
toolbar.add(linkSelectionAction);
switchRepositoriesAction = new RepositoryToolbarAction(false, () -> currentRepository, repo -> setInput(new StructuredSelection(repo)));
toolbar.add(switchRepositoriesAction);
UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, getSite());
getSite().setSelectionProvider(new RepositorySelectionProvider(planTreeViewer, () -> currentRepository));
}
use of org.eclipse.jgit.lib.AbbreviatedObjectId in project fuse-karaf by jboss-fuse.
the class GitConflictResolutionIT method reportingDiffs.
@Test
public void reportingDiffs() throws Exception {
prepareChanges();
ObjectReader reader = git.getRepository().newObjectReader();
RevWalk rw = new RevWalk(git.getRepository());
CanonicalTreeParser ctp1 = new CanonicalTreeParser();
CanonicalTreeParser ctp2 = new CanonicalTreeParser();
CanonicalTreeParser ctp3 = new CanonicalTreeParser();
ctp1.reset(reader, rw.parseCommit(git.getRepository().resolve("master")).getTree());
ctp2.reset(reader, rw.parseCommit(git.getRepository().resolve("custom")).getTree());
ctp3.reset(reader, rw.parseCommit(git.getRepository().resolve("patched")).getTree());
TreeWalk walk = new TreeWalk(reader);
walk.addTree(ctp1);
walk.addTree(ctp3);
walk.setRecursive(true);
List<DiffEntry> diffs = DiffEntry.scan(walk);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DiffFormatter df = new DiffFormatter(baos);
df.setDiffAlgorithm(DiffAlgorithm.getAlgorithm(DiffAlgorithm.SupportedAlgorithm.HISTOGRAM));
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setRepository(git.getRepository());
df.format(diffs.get(0));
// System.out.println(new String(baos.toByteArray()));
AbbreviatedObjectId id1 = diffs.get(0).getOldId();
AbbreviatedObjectId id2 = diffs.get(0).getNewId();
byte[] bytes1 = reader.open(id1.toObjectId()).getBytes();
byte[] bytes2 = reader.open(id2.toObjectId()).getBytes();
RawText rt1 = new RawText(bytes1);
RawText rt2 = new RawText(bytes2);
EditList edits = DiffAlgorithm.getAlgorithm(DiffAlgorithm.SupportedAlgorithm.HISTOGRAM).diff(RawTextComparator.DEFAULT, rt1, rt2);
int aCur = 0;
for (Edit curEdit : edits) {
boolean prolog = aCur < curEdit.getBeginA();
if (prolog) {
System.out.print("<div class=\"edit unchanged\">");
}
while (aCur < curEdit.getBeginA()) {
System.out.println(rt1.getString(aCur++));
}
if (prolog) {
System.out.print("</div>");
}
if (curEdit.getType() == Edit.Type.INSERT) {
System.out.print("<div class=\"edit added\">");
for (int i = curEdit.getBeginB(); i < curEdit.getEndB(); i++) {
System.out.println(rt2.getString(i));
}
System.out.print("</div>");
}
if (curEdit.getType() == Edit.Type.REPLACE) {
System.out.print("<div class=\"edit changed\"><div class=\"edit removed\">");
for (int i = curEdit.getBeginA(); i < curEdit.getEndA(); i++) {
System.out.println(rt1.getString(i));
}
System.out.print("</div><div class=\"edit added\">");
for (int i = curEdit.getBeginB(); i < curEdit.getEndB(); i++) {
System.out.println(rt2.getString(i));
}
aCur = curEdit.getEndA();
System.out.print("</div></div>");
}
}
boolean prolog = aCur < rt1.size();
if (prolog) {
System.out.print("<div class=\"edit unchanged\">");
}
while (aCur < rt1.size()) {
System.out.println(rt1.getString(aCur++));
}
if (prolog) {
System.out.print("</div>");
}
}
use of org.eclipse.jgit.lib.AbbreviatedObjectId in project fabric8 by jboss-fuse.
the class GitConflictResolutionIT method reportingDiffs.
@Test
public void reportingDiffs() throws Exception {
prepareChanges();
ObjectReader reader = git.getRepository().newObjectReader();
RevWalk rw = new RevWalk(git.getRepository());
CanonicalTreeParser ctp1 = new CanonicalTreeParser();
CanonicalTreeParser ctp2 = new CanonicalTreeParser();
CanonicalTreeParser ctp3 = new CanonicalTreeParser();
ctp1.reset(reader, rw.parseCommit(git.getRepository().resolve("master")).getTree());
ctp2.reset(reader, rw.parseCommit(git.getRepository().resolve("custom")).getTree());
ctp3.reset(reader, rw.parseCommit(git.getRepository().resolve("patched")).getTree());
TreeWalk walk = new TreeWalk(reader);
walk.addTree(ctp1);
walk.addTree(ctp3);
walk.setRecursive(true);
List<DiffEntry> diffs = DiffEntry.scan(walk);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DiffFormatter df = new DiffFormatter(baos);
df.setDiffAlgorithm(DiffAlgorithm.getAlgorithm(DiffAlgorithm.SupportedAlgorithm.HISTOGRAM));
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setRepository(git.getRepository());
df.format(diffs.get(0));
// System.out.println(new String(baos.toByteArray()));
AbbreviatedObjectId id1 = diffs.get(0).getOldId();
AbbreviatedObjectId id2 = diffs.get(0).getNewId();
byte[] bytes1 = reader.open(id1.toObjectId()).getBytes();
byte[] bytes2 = reader.open(id2.toObjectId()).getBytes();
RawText rt1 = new RawText(bytes1);
RawText rt2 = new RawText(bytes2);
EditList edits = DiffAlgorithm.getAlgorithm(DiffAlgorithm.SupportedAlgorithm.HISTOGRAM).diff(RawTextComparator.DEFAULT, rt1, rt2);
int aCur = 0;
for (Edit curEdit : edits) {
boolean prolog = aCur < curEdit.getBeginA();
if (prolog) {
System.out.print("<div class=\"edit unchanged\">");
}
while (aCur < curEdit.getBeginA()) {
System.out.println(rt1.getString(aCur++));
}
if (prolog) {
System.out.print("</div>");
}
if (curEdit.getType() == Edit.Type.INSERT) {
System.out.print("<div class=\"edit added\">");
for (int i = curEdit.getBeginB(); i < curEdit.getEndB(); i++) {
System.out.println(rt2.getString(i));
}
System.out.print("</div>");
}
if (curEdit.getType() == Edit.Type.REPLACE) {
System.out.print("<div class=\"edit changed\"><div class=\"edit removed\">");
for (int i = curEdit.getBeginA(); i < curEdit.getEndA(); i++) {
System.out.println(rt1.getString(i));
}
System.out.print("</div><div class=\"edit added\">");
for (int i = curEdit.getBeginB(); i < curEdit.getEndB(); i++) {
System.out.println(rt2.getString(i));
}
aCur = curEdit.getEndA();
System.out.print("</div></div>");
}
}
boolean prolog = aCur < rt1.size();
if (prolog) {
System.out.print("<div class=\"edit unchanged\">");
}
while (aCur < rt1.size()) {
System.out.println(rt1.getString(aCur++));
}
if (prolog) {
System.out.print("</div>");
}
}
use of org.eclipse.jgit.lib.AbbreviatedObjectId in project egit by eclipse.
the class StagedChangeCache method build.
/**
* @param repo
* repository which should be scanned
* @return list of changes in git staging area
*/
public static Map<String, Change> build(Repository repo) {
try (TreeWalk tw = new TreeWalk(repo)) {
tw.addTree(new DirCacheIterator(repo.readDirCache()));
ObjectId headId = repo.resolve(HEAD);
RevCommit headCommit = null;
if (headId != null) {
try (RevWalk rw = new RevWalk(repo)) {
headCommit = rw.parseCommit(headId);
}
}
AbbreviatedObjectId commitId;
if (headCommit != null) {
tw.addTree(headCommit.getTree());
commitId = AbbreviatedObjectId.fromObjectId(headCommit);
} else {
tw.addTree(new EmptyTreeIterator());
commitId = AbbreviatedObjectId.fromObjectId(zeroId());
}
tw.setRecursive(true);
headCommit = null;
MutableObjectId idBuf = new MutableObjectId();
Map<String, Change> result = new HashMap<String, Change>();
while (tw.next()) {
if (!shouldIncludeEntry(tw))
continue;
Change change = new Change();
change.name = tw.getNameString();
change.remoteCommitId = commitId;
tw.getObjectId(idBuf, 0);
change.objectId = AbbreviatedObjectId.fromObjectId(idBuf);
tw.getObjectId(idBuf, 1);
change.remoteObjectId = AbbreviatedObjectId.fromObjectId(idBuf);
calculateAndSetChangeKind(RIGHT, change);
result.put(tw.getPathString(), change);
}
return result;
} catch (IOException e) {
Activator.logError(e.getMessage(), e);
return new HashMap<String, Change>(0);
}
}
use of org.eclipse.jgit.lib.AbbreviatedObjectId in project egit by eclipse.
the class SquashCommitsOperation method execute.
@Override
public void execute(IProgressMonitor m) throws CoreException {
IWorkspaceRunnable action = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor pm) throws CoreException {
SubMonitor progress = SubMonitor.convert(pm, 2);
progress.subTask(MessageFormat.format(CoreText.SquashCommitsOperation_squashing, Integer.valueOf(commits.size())));
InteractiveHandler handler = new InteractiveHandler() {
@Override
public void prepareSteps(List<RebaseTodoLine> steps) {
RevCommit firstCommit = commits.get(0);
for (RebaseTodoLine step : steps) {
if (isRelevant(step.getCommit())) {
try {
if (step.getCommit().prefixCompare(firstCommit) == 0)
step.setAction(RebaseTodoLine.Action.PICK);
else
step.setAction(RebaseTodoLine.Action.SQUASH);
} catch (IllegalTodoFileModification e) {
// shouldn't happen
}
}
}
}
private boolean isRelevant(AbbreviatedObjectId id) {
for (RevCommit commit : commits) {
if (id.prefixCompare(commit) == 0)
return true;
}
return false;
}
@Override
public String modifyCommitMessage(String oldMessage) {
return messageHandler.modifyCommitMessage(oldMessage);
}
};
try (Git git = new Git(repository)) {
RebaseCommand command = git.rebase().setUpstream(commits.get(0).getParent(0)).runInteractively(handler).setOperation(RebaseCommand.Operation.BEGIN);
MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
if (strategy != null) {
command.setStrategy(strategy);
}
command.call();
} catch (GitAPIException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
}
progress.worked(1);
ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(repository), progress.newChild(1));
}
};
ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, m);
}
Aggregations