@Nonnull @Override public Branch getBranch(@Nonnull P project) { BranchProjectProperty property = project.getProperty(BranchProjectProperty.class); /* * Ugly hackish stuff, in the event that the user configures a branch project directly, thereby removing the * BranchProjectProperty. The property must exist and we can't bash the @Nonnull return value restriction! * * Fudge some generic Branch with the expectation that indexing will soon reset the Branch with proper values, * or that it will be converted to Branch.Dead and the guessed values for sourceId and properties won't matter. */ if (property == null) { Branch branch = new Branch("unknown", new SCMHead(project.getDisplayName()), project.getScm(), Collections.<BranchProperty>emptyList()); setBranch(project, branch); return branch; } return property.getBranch(); }
@Override public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException { String hash; try { hash = client.revParse(revision).name(); } catch (GitException x) { // Try prepending remote name in case it was a branch. try { hash = client.revParse(context.remoteName() + "/" + revision).name(); } catch (GitException x2) { listener.getLogger().println(x.getMessage()); listener.getLogger().println(x2.getMessage()); return null; } } return new SCMRevisionImpl(new SCMHead(revision), hash); } },
return null; return new SCMRevisionImpl(new SCMHead(base), revision == -1 ? resolvedRevision : revision); } catch (SVNException e) { throw new IOException(e);
if (request.process(new SCMHead(branchName), new SCMSourceRequest.IntermediateLambda<ObjectId>() { @Nullable
@Override public SCMRevision getTrustedRevision(SCMRevision revision, TaskListener listener) throws IOException, InterruptedException { String branch = revision.getHead().getName(); if (branch.equals("master")) { return revision; } else { listener.getLogger().println("not trusting " + branch); return fetch(new SCMHead("master"), listener); } } @Override public SCMSourceDescriptor getDescriptor() {
@NonNull @Override public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource source) { if (source instanceof MercurialSCMSource) { MercurialSCMSource hg = (MercurialSCMSource) source; String repository = hg.getSource(); if (repository != null) { if (MercurialStatus.looselyMatches(payload.getUrl(), repository)) { SCMHead head = new SCMHead(getPayload().getBranch()); SCMRevision revision = new MercurialSCMSource.MercurialRevision( head, getPayload().getChangesetId() ); return Collections.singletonMap(head, revision); } } } return Collections.emptyMap(); }
SCMHead head = new SCMHead(branch); for (SCMHeadPrefilter filter: ctx.prefilters()) { if (filter.isExcluded(git, head)) {
branchRevision = -1; SCMHead head = new SCMHead(childPath); observer.observe(head, new SCMRevisionImpl(head, branchRevision)); if (!observer.isObserving()) {
return new MercurialRevision(new SCMHead(branch), hash); } finally { hg.close();
@Test public void ofSourceRevision() throws Exception { sampleRepo.init(); sampleRepo.svnkit("copy", "--message=branching", sampleRepo.trunkUrl(), sampleRepo.branchesUrl() + "/dev"); sampleRepo.svnkit("switch", sampleRepo.branchesUrl() + "/dev", sampleRepo.wc()); SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl()); SCMRevision revision = source.fetch(new SCMHead("branches/dev"), null); sampleRepo.write("file", "modified"); sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc()); try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"), revision)) { assertThat(fs, notNullValue()); SCMFile root = fs.getRoot(); assertThat(root, notNullValue()); Iterable<SCMFile> children = root.children(); Iterator<SCMFile> iterator = children.iterator(); assertThat(iterator.hasNext(), is(true)); SCMFile file = iterator.next(); assertThat(iterator.hasNext(), is(false)); assertThat(file.getName(), is("file")); assertThat(file.contentAsString(), is("")); } }
final String name = nodeBranch[1]; count++; if (request.process(new SCMHead(name), new SCMSourceRequest.RevisionLambda<SCMHead, MercurialRevision>() { @Override
sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc()); SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl()); try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"))) { assertThat(fs, notNullValue()); assertThat(fs.getRoot(), notNullValue());
sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc()); SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl()); try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"));) { assertThat(fs, notNullValue()); assertThat(fs.getRoot(), notNullValue());
assertEquals(7, dev2); SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl()); try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("trunk"))) { assertThat(fs, notNullValue()); SCMFile root = fs.getRoot();
@Test public void lastModified_Smokes() throws Exception { long currentTime = isWindows() ? System.currentTimeMillis() / 1000L * 1000L : System.currentTimeMillis(); sampleRepo.init(); sampleRepo.svnkit("copy", "--message=branching", sampleRepo.trunkUrl(), sampleRepo.branchesUrl() + "/dev"); sampleRepo.svnkit("switch", sampleRepo.branchesUrl() + "/dev", sampleRepo.wc()); SCMSource source = new SubversionSCMSource(null, sampleRepo.prjUrl()); SCMRevision revision = source.fetch(new SCMHead("branches/dev"), null); long oneMinute = 60*1000; sampleRepo.write("file", "modified"); sampleRepo.svnkit("commit", "--message=dev1", sampleRepo.wc()); try (SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("branches/dev"), revision);) { long lastModified = fs.lastModified(); //ensure the timestamp is from after we started but not in the distant future assertThat(lastModified, greaterThanOrEqualTo(currentTime)); assertThat(lastModified, lessThanOrEqualTo(currentTime + oneMinute)); SCMFile file = fs.getRoot().child("file"); lastModified = file.lastModified(); assertThat(lastModified, greaterThanOrEqualTo(currentTime)); assertThat(lastModified, lessThanOrEqualTo(currentTime + oneMinute)); } }