Update to latest JGit to get AdvertiseRefsHook
Convert VisibleRefFilter and ReceiveCommitsRefFilter to be AdvertiseRefsHooks. For now, the basic functionality remains the same. Change-Id: I415c54c8a5ee657f41e5ff2ca4a8f9c7b7a16c1b
This commit is contained in:
@@ -215,7 +215,7 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
}
|
||||
|
||||
if (!pc.allRefsAreVisible()) {
|
||||
up.setRefFilter(new VisibleRefFilter(tagCache, repo, pc, db.get(), true));
|
||||
up.setAdvertiseRefsHook(new VisibleRefFilter(tagCache, repo, pc, db.get(), true));
|
||||
}
|
||||
|
||||
next.doFilter(request, response);
|
||||
|
@@ -207,9 +207,9 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
|
||||
if (!projectControl.allRefsAreVisible()) {
|
||||
rp.setCheckReferencedObjectsAreReachable(true);
|
||||
rp.setRefFilter(new VisibleRefFilter(tagCache, repo, projectControl, db, false));
|
||||
rp.setAdvertiseRefsHook(new VisibleRefFilter(tagCache, repo, projectControl, db, false));
|
||||
}
|
||||
rp.setRefFilter(new ReceiveCommitsRefFilter(rp.getRefFilter()));
|
||||
rp.setAdvertiseRefsHook(new ReceiveCommitsAdvertiseRefsHook(rp.getAdvertiseRefsHook()));
|
||||
|
||||
rp.setPreReceiveHook(this);
|
||||
rp.setPostReceiveHook(this);
|
||||
|
@@ -15,27 +15,40 @@
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.transport.RefFilter;
|
||||
import org.eclipse.jgit.transport.AdvertiseRefsHook;
|
||||
import org.eclipse.jgit.transport.ReceivePack;
|
||||
import org.eclipse.jgit.transport.ServiceMayNotContinueException;
|
||||
import org.eclipse.jgit.transport.UploadPack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** Exposes only the non refs/changes/ reference names. */
|
||||
class ReceiveCommitsRefFilter implements RefFilter {
|
||||
private final RefFilter base;
|
||||
class ReceiveCommitsAdvertiseRefsHook implements AdvertiseRefsHook {
|
||||
private final AdvertiseRefsHook base;
|
||||
|
||||
public ReceiveCommitsRefFilter(RefFilter base) {
|
||||
this.base = base != null ? base : RefFilter.DEFAULT;
|
||||
public ReceiveCommitsAdvertiseRefsHook(AdvertiseRefsHook base) {
|
||||
this.base = base != null ? base : AdvertiseRefsHook.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Ref> filter(Map<String, Ref> refs) {
|
||||
public void advertiseRefs(UploadPack us) {
|
||||
throw new UnsupportedOperationException(
|
||||
"ReceiveCommitsAdvertiseRefsHook cannot be used for UploadPack");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void advertiseRefs(ReceivePack rp) {
|
||||
Map<String, Ref> oldRefs = rp.getAdvertisedRefs();
|
||||
if (oldRefs == null) {
|
||||
oldRefs = rp.getRepository().getAllRefs();
|
||||
}
|
||||
HashMap<String, Ref> r = new HashMap<String, Ref>();
|
||||
for (Map.Entry<String, Ref> e : refs.entrySet()) {
|
||||
for (Map.Entry<String, Ref> e : oldRefs.entrySet()) {
|
||||
if (!e.getKey().startsWith("refs/changes/")) {
|
||||
r.put(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
return base.filter(r);
|
||||
rp.setAdvertisedRefs(r, rp.getAdvertisedObjects());
|
||||
}
|
||||
}
|
@@ -24,7 +24,8 @@ import com.google.gwtorm.server.OrmException;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.transport.RefFilter;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.transport.AbstractAdvertiseRefsHook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -36,7 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class VisibleRefFilter implements RefFilter {
|
||||
public class VisibleRefFilter extends AbstractAdvertiseRefsHook {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(VisibleRefFilter.class);
|
||||
|
||||
@@ -58,11 +59,6 @@ public class VisibleRefFilter implements RefFilter {
|
||||
this.showChanges = showChanges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Ref> filter(Map<String, Ref> refs) {
|
||||
return filter(refs, false);
|
||||
}
|
||||
|
||||
public Map<String, Ref> filter(Map<String, Ref> refs, boolean filterTagsSeperately) {
|
||||
final Set<Change.Id> visibleChanges = visibleChanges();
|
||||
final Map<String, Ref> result = new HashMap<String, Ref>();
|
||||
@@ -108,6 +104,16 @@ public class VisibleRefFilter implements RefFilter {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Ref> getAdvertisedRefs(
|
||||
Repository repository, RevWalk revWalk) {
|
||||
return filter(repository.getAllRefs());
|
||||
}
|
||||
|
||||
private Map<String, Ref> filter(Map<String, Ref> refs) {
|
||||
return filter(refs, false);
|
||||
}
|
||||
|
||||
private Set<Change.Id> visibleChanges() {
|
||||
if (!showChanges) {
|
||||
return Collections.emptySet();
|
||||
|
@@ -25,8 +25,8 @@ import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.errors.UnpackException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.transport.AdvertiseRefsHook;
|
||||
import org.eclipse.jgit.transport.ReceivePack;
|
||||
import org.eclipse.jgit.transport.RefFilter;
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -97,17 +97,17 @@ final class Receive extends AbstractGitCommand {
|
||||
msg.append("Unpack error on project \""
|
||||
+ projectControl.getProject().getName() + "\":\n");
|
||||
|
||||
msg.append(" RefFilter: " + rp.getRefFilter());
|
||||
if (rp.getRefFilter() == RefFilter.DEFAULT) {
|
||||
msg.append(" AdvertiseRefsHook: " + rp.getAdvertiseRefsHook());
|
||||
if (rp.getAdvertiseRefsHook() == AdvertiseRefsHook.DEFAULT) {
|
||||
msg.append("DEFAULT");
|
||||
} else if (rp.getRefFilter() instanceof VisibleRefFilter) {
|
||||
} else if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) {
|
||||
msg.append("VisibleRefFilter");
|
||||
} else {
|
||||
msg.append(rp.getRefFilter().getClass());
|
||||
msg.append(rp.getAdvertiseRefsHook().getClass());
|
||||
}
|
||||
msg.append("\n");
|
||||
|
||||
if (rp.getRefFilter() instanceof VisibleRefFilter) {
|
||||
if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) {
|
||||
Map<String, Ref> adv = rp.getAdvertisedRefs();
|
||||
msg.append(" Visible references (" + adv.size() + "):\n");
|
||||
for (Ref ref : adv.values()) {
|
||||
|
@@ -45,8 +45,8 @@ final class Upload extends AbstractGitCommand {
|
||||
|
||||
final UploadPack up = new UploadPack(repo);
|
||||
if (!projectControl.allRefsAreVisible()) {
|
||||
up.setRefFilter(new VisibleRefFilter(tagCache, repo, projectControl,
|
||||
db.get(), true));
|
||||
up.setAdvertiseRefsHook(new VisibleRefFilter(tagCache, repo,
|
||||
projectControl, db.get(), true));
|
||||
}
|
||||
up.setPackConfig(config.getPackConfig());
|
||||
up.setTimeout(config.getTimeout());
|
||||
|
2
pom.xml
2
pom.xml
@@ -46,7 +46,7 @@ limitations under the License.
|
||||
</issueManagement>
|
||||
|
||||
<properties>
|
||||
<jgitVersion>1.3.0.201202151440-r</jgitVersion>
|
||||
<jgitVersion>1.3.0.201202151440-r.54-gd725ecb</jgitVersion>
|
||||
<gwtormVersion>1.4</gwtormVersion>
|
||||
<gwtjsonrpcVersion>1.2.5</gwtjsonrpcVersion>
|
||||
<gwtexpuiVersion>1.2.5</gwtexpuiVersion>
|
||||
|
Reference in New Issue
Block a user