From 112d70ce450e8f6151f921b102f9b1a41e4ea280 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 9 Jan 2010 19:06:06 -0800 Subject: [PATCH] Update EGit to match ref API changes JGit changed the way some ref updates are exposed to applications: * getOrigName() is now just getName() * Ref is an abstract class, use getRef instead to find HEAD. * writeSymref() has been replaced by RefUpdate This commit depends upon the following JGit changes: * I1093e1ec2970147978a786cfdd0a75d0aebf8010 * I26b9287c45a4b2d2be35ba2849daa316f5eec85d Change-Id: Iae4c99b142de74e278876ff086f8eab6e9fde4a4 Signed-off-by: Shawn O. Pearce --- .../org/eclipse/egit/core/op/BranchOperation.java | 26 +++++++++------------- .../org/eclipse/egit/core/op/CloneOperation.java | 5 ++++- .../egit/ui/internal/components/RefSpecPanel.java | 5 +---- .../egit/ui/internal/history/SWTPlotRenderer.java | 2 +- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/BranchOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/BranchOperation.java index 6ee9a552..9f174036 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/BranchOperation.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/BranchOperation.java @@ -24,7 +24,7 @@ import org.eclipse.jgit.errors.CheckoutConflictException; import org.eclipse.jgit.lib.Commit; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.GitIndex; -import org.eclipse.jgit.lib.RefLogWriter; +import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Tree; import org.eclipse.jgit.lib.WorkDirCheckout; @@ -77,9 +77,6 @@ public class BranchOperation implements IWorkspaceRunnable { updateHeadRef(); monitor.worked(1); - writeHeadReflog(); - monitor.worked(1); - refreshProjects(); monitor.worked(1); @@ -103,19 +100,18 @@ public class BranchOperation implements IWorkspaceRunnable { } } - private void writeHeadReflog() throws TeamException { - try { - RefLogWriter.writeReflog(repository, oldCommit.getCommitId(), - newCommit.getCommitId(), "checkout: moving to " + refName, - Constants.HEAD); - } catch (IOException e) { - throw new TeamException("Writing HEAD's reflog", e); - } - } - private void updateHeadRef() throws TeamException { try { - repository.writeSymref(Constants.HEAD, refName); + RefUpdate u = repository.updateRef(Constants.HEAD); + u.setRefLogMessage("checkout: moving to " + refName, false); + switch (u.link(refName)) { + case NEW: + case FORCED: + case NO_CHANGE: + break; + default: + throw new IOException(u.getResult().name()); + } } catch (IOException e) { throw new TeamException("Updating HEAD to ref: " + refName, e); } diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CloneOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CloneOperation.java index 9860c019..7bb35d1c 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CloneOperation.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CloneOperation.java @@ -138,7 +138,10 @@ public class CloneOperation implements IRunnableWithProgress { final File gitdir = new File(workdir, ".git"); local = new Repository(gitdir); local.create(); - local.writeSymref(Constants.HEAD, branch); + + final RefUpdate head = local.updateRef(Constants.HEAD); + head.disableRefLog(); + head.link(branch); remoteConfig = new RemoteConfig(local.getConfig(), remoteName); remoteConfig.addURI(uri); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java index c4634a73..789e24c9 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java @@ -80,7 +80,6 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.Ref.Storage; import org.eclipse.jgit.transport.FetchConnection; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteConfig; @@ -383,9 +382,7 @@ public class RefSpecPanel { Ref HEAD = null; try { - final ObjectId id = localDb.resolve(Constants.HEAD); - if (id != null) - HEAD = new Ref(Storage.LOOSE, Constants.HEAD, id); + HEAD = localDb.getRef(Constants.HEAD); } catch (IOException e) { Activator.logError("Couldn't read HEAD from local repository", e); //$NON-NLS-1$ } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/SWTPlotRenderer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/SWTPlotRenderer.java index f15e3e68..6f00905d 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/SWTPlotRenderer.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/SWTPlotRenderer.java @@ -108,7 +108,7 @@ class SWTPlotRenderer extends AbstractPlotRenderer { @Override protected int drawLabel(int x, int y, Ref ref) { String txt; - String name = ref.getOrigName(); + String name = ref.getName(); if (name.startsWith(Constants.R_HEADS)) { g.setBackground(sys_green); txt = name.substring(Constants.R_HEADS.length()); -- 2.11.4.GIT