From d0a46c3a3d92c8853a28a86578e8b6cbdd007c0f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 29 Jan 2010 10:56:13 -0800 Subject: [PATCH] Update JGit to 0.5.1.140-g660fd39 This is very close to what will eventually be the 0.7.0 release from the Eclipse.org domain. It resolves both issues 304 and 399 for us. Issue 304 was about not reporting "git not found" during replication when git was not in the remote user's $PATH. Issue 399 was about JGit rejecting older format annotated tag objects, where the tagger was missing. The Linux kernel is one such project with old tags like this, which made it hard to work with the kernel in Gerrit. Bug: issue 304 Bug: issue 399 Change-Id: Icb6252fa549a1814c0334332750552d531fdc0bf Signed-off-by: Shawn O. Pearce Reviewed-by: Nico Sallembien --- .../gerrit/httpd/rpc/project/ListBranches.java | 17 ++++++++--------- .../httpd/rpc/project/ListBranchesTest.java | 16 ++++++++++------ .../com/google/gerrit/server/git/PushOp.java | 8 ++------ .../sshd/commands/AdminCreateProject.java | 7 ++++++- pom.xml | 2 +- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ListBranches.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ListBranches.java index c0b091cfb9..bc4d870819 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ListBranches.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ListBranches.java @@ -70,14 +70,14 @@ class ListBranches extends Handler> { final Map all = db.getAllRefs(); if (!all.containsKey(Constants.HEAD)) { - // The branch pointed to by HEAD doesn't exist yet. Fake - // that it exists by returning a Ref with no ObjectId. + // The branch pointed to by HEAD doesn't exist yet, so getAllRefs + // filtered it out. If we ask for it individually we can find the + // underlying target and put it into the map anyway. // try { - final String head = db.getFullBranch(); - if (head != null && head.startsWith(Constants.R_REFS)) { - all.put(Constants.HEAD, new Ref(Ref.Storage.LOOSE, Constants.HEAD, - head, null)); + Ref head = db.getRef(Constants.HEAD); + if (head != null) { + all.put(Constants.HEAD, head); } } catch (IOException e) { // Ignore the failure reading HEAD. @@ -85,13 +85,12 @@ class ListBranches extends Handler> { } for (final Ref ref : all.values()) { - if (Constants.HEAD.equals(ref.getOrigName()) - && !ref.getOrigName().equals(ref.getName())) { + if (Constants.HEAD.equals(ref.getName()) && ref.isSymbolic()) { // HEAD is a symbolic reference to another branch, instead of // showing the resolved value, show the name it references. // headBranch = createBranch(Constants.HEAD); - String target = ref.getName(); + String target = ref.getTarget().getName(); if (target.startsWith(Constants.R_HEADS)) { target = target.substring(Constants.R_HEADS.length()); } diff --git a/gerrit-httpd/src/test/java/com/google/gerrit/httpd/rpc/project/ListBranchesTest.java b/gerrit-httpd/src/test/java/com/google/gerrit/httpd/rpc/project/ListBranchesTest.java index 032a9315bf..5c83767437 100644 --- a/gerrit-httpd/src/test/java/com/google/gerrit/httpd/rpc/project/ListBranchesTest.java +++ b/gerrit-httpd/src/test/java/com/google/gerrit/httpd/rpc/project/ListBranchesTest.java @@ -22,6 +22,7 @@ import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.verify; import static org.eclipse.jgit.lib.Constants.HEAD; import static org.eclipse.jgit.lib.Constants.R_HEADS; +import static org.eclipse.jgit.lib.Ref.Storage.LOOSE; import com.google.gerrit.reviewdb.Branch; import com.google.gerrit.reviewdb.Project; @@ -34,9 +35,11 @@ import com.google.gwtorm.server.StandardKeyEncoder; import org.easymock.IExpectationSetters; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.SymbolicRef; import java.io.IOException; import java.util.LinkedHashMap; @@ -112,13 +115,13 @@ public class ListBranchesTest extends LocalDiskRepositoryTestCase { } - private List permitted(boolean getFullBranch) + private List permitted(boolean getHead) throws NoSuchProjectException, IOException { validate().andReturn(pc); expect(grm.openRepository(eq(name.get()))).andReturn(mockDb); expect(mockDb.getAllRefs()).andDelegateTo(realDb); - if (getFullBranch) { - expect(mockDb.getFullBranch()).andDelegateTo(realDb); + if (getHead) { + expect(mockDb.getRef(HEAD)).andDelegateTo(realDb); } mockDb.close(); expectLastCall(); @@ -216,9 +219,10 @@ public class ListBranchesTest extends LocalDiskRepositoryTestCase { public void testSortByName() throws Exception { Map u = new LinkedHashMap(); - u.put("foo", new Ref(Ref.Storage.LOOSE, R_HEADS + "foo", idA)); - u.put("bar", new Ref(Ref.Storage.LOOSE, R_HEADS + "bar", idA)); - u.put(HEAD, new Ref(Ref.Storage.LOOSE, HEAD, R_HEADS + "master", null)); + u.put("foo", new ObjectIdRef.Unpeeled(LOOSE, R_HEADS + "foo", idA)); + u.put("bar", new ObjectIdRef.Unpeeled(LOOSE, R_HEADS + "bar", idA)); + u.put(HEAD, new SymbolicRef(HEAD, new ObjectIdRef.Unpeeled(LOOSE, R_HEADS + + "master", null))); validate().andReturn(pc); expect(grm.openRepository(eq(name.get()))).andReturn(mockDb); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/PushOp.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/PushOp.java index ddc4bea8ee..e1baf95e7b 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/PushOp.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/PushOp.java @@ -202,7 +202,7 @@ class PushOp implements Runnable { final Map remote = listRemote(tn); for (final Ref src : local.values()) { - final RefSpec spec = matchSrc(src.getOrigName()); + final RefSpec spec = matchSrc(src.getName()); if (spec != null) { final Ref dst = remote.get(spec.getDestination()); if (dst == null || !src.getObjectId().equals(dst.getObjectId())) { @@ -214,7 +214,7 @@ class PushOp implements Runnable { } for (final Ref ref : remote.values()) { - if (!isHEAD(ref)) { + if (!Constants.HEAD.equals(ref.getName())) { final RefSpec spec = matchDst(ref.getName()); if (spec != null && !local.containsKey(spec.getSource())) { // No longer on local side, request removal. @@ -284,8 +284,4 @@ class PushOp implements Runnable { final boolean force = spec.isForceUpdate(); cmds.add(new RemoteRefUpdate(db, null, dst, force, null, null)); } - - private static boolean isHEAD(final Ref ref) { - return Constants.HEAD.equals(ref.getOrigName()); - } } diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/AdminCreateProject.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/AdminCreateProject.java index 2562f8ab36..373249b512 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/AdminCreateProject.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/AdminCreateProject.java @@ -30,6 +30,7 @@ import com.google.inject.Inject; import org.apache.sshd.server.Environment; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.Repository; import org.kohsuke.args4j.Option; @@ -90,7 +91,11 @@ final class AdminCreateProject extends BaseCommand { Repository repo = repoManager.createRepository(projectName); repo.create(true); - repo.writeSymref(Constants.HEAD, branch); + + RefUpdate u = repo.updateRef(Constants.HEAD); + u.disableRefLog(); + u.link(branch); + repoManager.setProjectDescription(projectName, projectDescription); createProject(); diff --git a/pom.xml b/pom.xml index d64a7e8dc8..ce42daf53d 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ limitations under the License. - 0.5.1.106-g10a3391 + 0.5.1.140-g660fd39 1.1.4-SNAPSHOT 1.2.1 1.2.0