Browse Source

UploadPack: set RefFilter from TransportConfig

Teach TransportConfig to respect uploadpack.hiderefs, which is new in
C git 1.8.2.

Change-Id: Id12e7f00b9a60258e996410f67fa10616459f53f
stable-3.1
Dave Borowitz 12 years ago
parent
commit
e74751769e
  1. 40
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
  2. 6
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

40
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java

@ -43,8 +43,12 @@
package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Config.SectionParser; import org.eclipse.jgit.lib.Config.SectionParser;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
/** /**
@ -61,6 +65,7 @@ public class TransferConfig {
private final boolean fsckObjects; private final boolean fsckObjects;
private final boolean allowTipSha1InWant; private final boolean allowTipSha1InWant;
private final String[] hideRefs;
TransferConfig(final Repository db) { TransferConfig(final Repository db) {
this(db.getConfig()); this(db.getConfig());
@ -68,8 +73,9 @@ public class TransferConfig {
private TransferConfig(final Config rc) { private TransferConfig(final Config rc) {
fsckObjects = rc.getBoolean("receive", "fsckobjects", false); //$NON-NLS-1$ //$NON-NLS-2$ fsckObjects = rc.getBoolean("receive", "fsckobjects", false); //$NON-NLS-1$ //$NON-NLS-2$
allowTipSha1InWant = allowTipSha1InWant = rc.getBoolean(
rc.getBoolean("uploadpack", "allowtipsha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$ "uploadpack", "allowtipsha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$
hideRefs = rc.getStringList("uploadpack", null, "hiderefs"); //$NON-NLS-1$ //$NON-NLS-2$
} }
/** /**
@ -85,4 +91,34 @@ public class TransferConfig {
public boolean isAllowTipSha1InWant() { public boolean isAllowTipSha1InWant() {
return allowTipSha1InWant; return allowTipSha1InWant;
} }
/**
* @return {@link RefFilter} respecting configured hidden refs.
*/
public RefFilter getRefFilter() {
if (hideRefs.length == 0)
return RefFilter.DEFAULT;
return new RefFilter() {
public Map<String, Ref> filter(Map<String, Ref> refs) {
Map<String, Ref> result = new HashMap<String, Ref>();
for (Map.Entry<String, Ref> e : refs.entrySet()) {
boolean add = true;
for (String hide : hideRefs) {
if (e.getKey().equals(hide) || prefixMatch(hide, e.getKey())) {
add = false;
break;
}
}
if (add)
result.put(e.getKey(), e.getValue());
}
return result;
}
private boolean prefixMatch(String p, String s) {
return p.charAt(p.length() - 1) == '/' && s.startsWith(p);
}
};
}
} }

6
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

@ -351,6 +351,9 @@ public class UploadPack {
refs = allRefs; refs = allRefs;
else else
refs = db.getAllRefs(); refs = db.getAllRefs();
if (refFilter == RefFilter.DEFAULT)
refs = transferConfig.getRefFilter().filter(refs);
else
refs = refFilter.filter(refs); refs = refFilter.filter(refs);
} }
@ -444,7 +447,8 @@ public class UploadPack {
* <p> * <p>
* Only refs allowed by this filter will be sent to the client. * Only refs allowed by this filter will be sent to the client.
* The filter is run against the refs specified by the * The filter is run against the refs specified by the
* {@link AdvertiseRefsHook} (if applicable). * {@link AdvertiseRefsHook} (if applicable). If null or not set, uses the
* filter implied by the {@link TransferConfig}.
* *
* @param refFilter * @param refFilter
* the filter; may be null to show all refs. * the filter; may be null to show all refs.

Loading…
Cancel
Save