Source:
<code>private void readAdvertisedRefsImpl() throws IOException { final LinkedHashMap<String, Ref> avail = new LinkedHashMap<>(); for (;;) { String line; try { line = pckIn.readString(); } catch (EOFException eof) { if (avail.isEmpty()) throw noRepository(); throw eof; } if (line == PacketLineIn.END) break; if (line.startsWith("ERR ")) { throw new RemoteRepositoryException(uri, line.substring(4)); } if (avail.isEmpty()) { final int nul = line.indexOf('\0'); if (nul >= 0) { for (String c : line.substring(nul + 1).split(" ")) remoteCapablities.add(c); line = line.substring(0, nul); } } <START> Matcher matcher = ADVERTISED_REF_PATTERN.matcher(line); <END> if (!matcher.matches()) { continue; } String name = matcher.group(2); if (avail.isEmpty() && name.equals("capabilities^{}")) { continue; } final ObjectId id = ObjectId.fromString(matcher.group(1)); if (name.equals(".have")) { additionalHaves.add(id); } else if (name.endsWith("^{}")) { name = name.substring(0, name.length() - 3); final Ref prior = avail.get(name); if (prior == null) throw new PackProtocolException(uri, MessageFormat.format( JGitText.get().advertisementCameBefore, name, name)); if (prior.getPeeledObjectId() != null) throw duplicateAdvertisement(name + "^{}"); avail.put(name, new ObjectIdRef.PeeledTag( Ref.Storage.NETWORK, name, prior.getObjectId(), id)); } else { final Ref prior = avail.put(name, new ObjectIdRef.PeeledNonTag( Ref.Storage.NETWORK, name, id)); if (prior != null) throw duplicateAdvertisement(name); } } available(avail); }</code><technical_language>Is specific reason regex? painful experience debugging regexes. Regex matching overkill here. > other parts of client code behave properly v2. elaborate? RuntimeException get handled properly caller</technical_language>

Target:
private void readAdvertisedRefsImpl() throws IOException { final LinkedHashMap<String, Ref> avail = new LinkedHashMap<>(); for (;;) { String line; try { line = pckIn.readString(); } catch (EOFException eof) { if (avail.isEmpty()) throw noRepository(); throw eof; } if (line == PacketLineIn.END) break; if (line.startsWith("ERR ")) { throw new RemoteRepositoryException(uri, line.substring(4)); } if (avail.isEmpty()) { final int nul = line.indexOf('\0'); if (nul >= 0) { for (String c : line.substring(nul + 1).split(" ")) remoteCapablities.add(c); line = line.substring(0, nul); } } if (line.length() < 41 || line.charAt(40) != ' ') { throw invalidRefAdvertisementLine(line); } String name = line.substring(41, line.length()); if (avail.isEmpty() && name.equals("capabilities^{}")) { continue; } final ObjectId id; try { id = ObjectId.fromString(line.substring(0, 40)); } catch (InvalidObjectIdException e) { throw invalidRefAdvertisementLine(line); } if (name.equals(".have")) { additionalHaves.add(id); } else if (name.endsWith("^{}")) { name = name.substring(0, name.length() - 3); final Ref prior = avail.get(name); if (prior == null) throw new PackProtocolException(uri, MessageFormat.format( JGitText.get().advertisementCameBefore, name, name)); if (prior.getPeeledObjectId() != null) throw duplicateAdvertisement(name + "^{}"); avail.put(name, new ObjectIdRef.PeeledTag( Ref.Storage.NETWORK, name, prior.getObjectId(), id)); } else { final Ref prior = avail.put(name, new ObjectIdRef.PeeledNonTag( Ref.Storage.NETWORK, name, id)); if (prior != null) throw duplicateAdvertisement(name); } } available(avail); }