private Set<PatchSet.Id> parsePatchSetId(final String patchIdentity) throws UnloggedFailure, OrmException { // By commit? // if (patchIdentity.matches("^([0-9a-fA-F]{4," + RevId.LEN + "})$")) { final RevId id = new RevId(patchIdentity); final ResultSet<PatchSet> patches; if (id.isComplete()) { patches = db.patchSets().byRevision(id); } else { patches = db.patchSets().byRevisionRange(id, id.max()); } final Set<PatchSet.Id> matches = new HashSet<PatchSet.Id>(); for (final PatchSet ps : patches) { final Change change = db.changes().get(ps.getId().getParentKey()); if (inProject(change)) { matches.add(ps.getId()); } } switch (matches.size()) { case 1: return matches; case 0: throw error("\"" + patchIdentity + "\" no such patch set"); default: throw error("\"" + patchIdentity + "\" matches multiple patch sets"); } } // By older style change,patchset? // if (patchIdentity.matches("^[1-9][0-9]*,[1-9][0-9]*$")) { final PatchSet.Id patchSetId; try { patchSetId = PatchSet.Id.parse(patchIdentity); } catch (IllegalArgumentException e) { throw error("\"" + patchIdentity + "\" is not a valid patch set"); } if (db.patchSets().get(patchSetId) == null) { throw error("\"" + patchIdentity + "\" no such patch set"); } if (projectControl != null) { final Change change = db.changes().get(patchSetId.getParentKey()); if (!inProject(change)) { throw error( "change " + change.getId() + " not in project " + projectControl.getProject().getName()); } } return Collections.singleton(patchSetId); } throw error("\"" + patchIdentity + "\" is not a valid patch set"); }
/** Setup the message headers and envelope (TO, CC, BCC). */ protected void init() throws EmailException { if (args.projectCache != null) { projectState = args.projectCache.get(change.getProject()); } else { projectState = null; } if (patchSet == null) { try { patchSet = args.db.get().patchSets().get(change.currentPatchSetId()); } catch (OrmException err) { patchSet = null; } } if (patchSet != null && patchSetInfo == null) { try { patchSetInfo = args.patchSetInfoFactory.get(patchSet.getId()); } catch (PatchSetInfoNotAvailableException err) { patchSetInfo = null; } } authors = getAuthors(); super.init(); if (changeMessage != null && changeMessage.getWrittenOn() != null) { setHeader("Date", new Date(changeMessage.getWrittenOn().getTime())); } setChangeSubjectHeader(); setHeader("X-Gerrit-Change-Id", "" + change.getKey().get()); setListIdHeader(); setChangeUrlHeader(); setCommitIdHeader(); }