|
|
@@ -276,47 +276,18 @@ public class RefDirectory extends RefDatabase { |
|
|
|
/** {@inheritDoc} */ |
|
|
|
@Override |
|
|
|
public boolean isNameConflicting(String name) throws IOException { |
|
|
|
RefList<Ref> packed = getPackedRefs(); |
|
|
|
RefList<LooseRef> loose = getLooseRefs(); |
|
|
|
|
|
|
|
// Cannot be nested within an existing reference. |
|
|
|
int lastSlash = name.lastIndexOf('/'); |
|
|
|
while (0 < lastSlash) { |
|
|
|
String needle = name.substring(0, lastSlash); |
|
|
|
if (loose.contains(needle) || packed.contains(needle)) |
|
|
|
if (exactRef(needle) != null) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
lastSlash = name.lastIndexOf('/', lastSlash - 1); |
|
|
|
} |
|
|
|
|
|
|
|
// Cannot be the container of an existing reference. |
|
|
|
String prefix = name + '/'; |
|
|
|
int idx; |
|
|
|
|
|
|
|
idx = -(packed.find(prefix) + 1); |
|
|
|
if (idx < packed.size() && packed.get(idx).getName().startsWith(prefix)) |
|
|
|
return true; |
|
|
|
|
|
|
|
idx = -(loose.find(prefix) + 1); |
|
|
|
if (idx < loose.size() && loose.get(idx).getName().startsWith(prefix)) |
|
|
|
return true; |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private RefList<LooseRef> getLooseRefs() { |
|
|
|
final RefList<LooseRef> oldLoose = looseRefs.get(); |
|
|
|
|
|
|
|
LooseScanner scan = new LooseScanner(oldLoose); |
|
|
|
scan.scan(ALL); |
|
|
|
|
|
|
|
RefList<LooseRef> loose; |
|
|
|
if (scan.newLoose != null) { |
|
|
|
loose = scan.newLoose.toRefList(); |
|
|
|
if (looseRefs.compareAndSet(oldLoose, loose)) |
|
|
|
modCnt.incrementAndGet(); |
|
|
|
} else |
|
|
|
loose = oldLoose; |
|
|
|
return loose; |
|
|
|
return !getRefsByPrefix(name + '/').isEmpty(); |
|
|
|
} |
|
|
|
|
|
|
|
/** {@inheritDoc} */ |