function Branch() { var _id = Math.round(Math.random() * 10); this.getId = function () { return _id; }; Branch.branches.push(this); } Branch.branches = []; Branch.getIds = function () { var ids = []; for (var i in Branch.branches) ids.push(Branch.branches[i].getId()); return ids; }; // test code for (var i = 0; i < 7; i++) { new Branch(); } console.log("Branch IDs:\n" + Branch.getIds());
public JsonResult GetBranch() { var branch = new Branch(); var branchs = new List<Branch>(); var branchId = "Branch01"; //If only your branch id datatype is string branch.branchId = branchId; var branchName = "Name of Branch";//Name you want to give for your branch branch.branchName = branchName; branchs.Add(branch); return Json(branchs.Select(t => new {Text = t.branchName, Value = t.branchId}), JsonRequestBehavior.AllowGet); }
Branch branch = new Branch(...); branch.setCompany(company); // mandatory company.getBranches().add(branch); // not mandatory, but advised to have a consistent graph em.persist(branch);
protected List<Branch> parseRefList(List<Ref> refList) { List<Branch> result = new ArrayList<Branch>(); if (CollectionUtils.isNotEmpty(refList)) { for (Ref ref : refList) { Branch buildBranch = new Branch(ref); result.add(buildBranch); listener.getLogger().println(Messages.GitAPI_Branch_BranchInRepoMsg(buildBranch.getName())); } } return result; }
private Revision objectId2Revision(String singleBranch, ObjectId sha1) { Revision revision = new Revision(sha1); revision.getBranches().add(new Branch(singleBranch, sha1)); return revision; }
private List<Branch> parseBranches(String fos) throws GitException { // TODO: git branch -a -v --abbrev=0 would do this in one shot.. List<Branch> tags = new ArrayList<Branch>(); BufferedReader rdr = new BufferedReader(new StringReader(fos)); String line; try { while ((line = rdr.readLine()) != null) { // Ignore the 1st line = line.substring(2); // Ignore '(no branch)' or anything with " -> ", since I think // that's just noise if ((!line.startsWith("(")) && (line.indexOf(" -> ") == -1)) { tags.add(new Branch(line, revParse(line))); } } } catch (IOException e) { throw new GitException("Error parsing branches", e); } return tags; }
private List<Branch> parseBranches(String fos) throws GitException { // TODO: git branch -a -v --abbrev=0 would do this in one shot.. List<Branch> tags = new ArrayList<Branch>(); BufferedReader rdr = new BufferedReader(new StringReader(fos)); String line; try { while ((line = rdr.readLine()) != null) { // Ignore the 1st line = line.substring(2); // Ignore '(no branch)' or anything with " -> ", since I think // that's just noise if ((!line.startsWith("(")) && (line.indexOf(" -> ") == -1)) { tags.add(new Branch(line, revParse(line))); } } } catch (IOException e) { throw new GitException("Error parsing branches", e); } return tags; }
public List<Branch> getRemoteBranches() throws GitException, IOException { Repository db = getRepository(); Map<String, Ref> refs = db.getAllRefs(); List<Branch> branches = new ArrayList<Branch>(); for (Ref candidate : refs.values()) { if (candidate.getName().startsWith(Constants.R_REMOTES)) { Branch buildBranch = new Branch(candidate); listener.getLogger().println("Seen branch in repository " + buildBranch.getName()); branches.add(buildBranch); } } return branches; }
/** * This method is aimed to normalize all the branches to the same naming * convention, as {@link GitClient#getBranchesContaining(String, boolean)} * returns branches with "remotes/" prefix. * @param branches branches, retrieved from git client * @return list of branches without the "remote/" prefix. */ private List<Branch> normalizeBranches(List<Branch> branches) { final List<Branch> normalBranches = new ArrayList<>(branches.size()); final String remotesPrefix = "remotes/"; for (Branch initialBranch : branches) { final String initialBranchName = initialBranch.getName(); final Branch normalBranch; if (initialBranchName.startsWith(remotesPrefix)) { final String normalName = initialBranchName.substring(remotesPrefix.length()); normalBranch = new Branch(normalName, initialBranch.getSHA1()); } else { normalBranch = initialBranch; } normalBranches.add(normalBranch); } return normalBranches; }
public SpecificRevisionBuildChooser(SCMRevisionImpl revision) { ObjectId sha1 = ObjectId.fromString(revision.getHash()); String name = revision.getHead().getName(); this.revision = new Revision(sha1, Collections.singleton(new Branch(name, sha1))); }
public Revision toRevision(IGitAPI git) { ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1)); return revision; }
public Revision toRevision(IGitAPI git) { ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1)); return revision; }
branches.add(new Branch(branchVerboseOutput[0], ObjectId.fromString(branchVerboseOutput[1])));
/** * Returns the remote branches defined in this repository. * * @return {@link java.util.Set} of remote branches in this repository * @throws hudson.plugins.git.GitException if underlying git operation fails * @throws java.lang.InterruptedException if interrupted */ public Set<Branch> getRemoteBranches() throws GitException, InterruptedException { try (Repository db = getRepository()) { Map<String, Ref> refs = db.getAllRefs(); Set<Branch> branches = new HashSet<>(); for(Ref candidate : refs.values()) { if(candidate.getName().startsWith(Constants.R_REMOTES)) { Branch buildBranch = new Branch(candidate); if (!GitClient.quietRemoteBranches) { listener.getLogger().println("Seen branch in repository " + buildBranch.getName()); } branches.add(buildBranch); } } if (branches.size() == 1) { listener.getLogger().println("Seen 1 remote branch"); } else { listener.getLogger().println(MessageFormat.format("Seen {0} remote branches", branches.size())); } return branches; } }
public Set<Branch> getBranchesInternal(ListBranchCommand.ListMode mode) throws GitException { try (Repository repo = getRepository()) { List<Ref> refs = git(repo).branchList().setListMode(mode).call(); Set<Branch> branches = new HashSet<>(refs.size()); for (Ref ref : refs) { branches.add(new Branch(ref)); } return branches; } catch (GitAPIException e) { throw new GitException(e); } }
/** * Return a list of "Revisions" - where a revision knows about all the branch names that refer to * a SHA1. * @return list of revisions * @throws IOException on input or output error * @throws GitException on git error * @throws InterruptedException when interrupted */ public Collection<Revision> getAllBranchRevisions() throws GitException, IOException, InterruptedException { Map<ObjectId, Revision> revisions = new HashMap<>(); for (Branch b : git.getRemoteBranches()) { Revision r = revisions.get(b.getSHA1()); if (r == null) { r = new Revision(b.getSHA1()); revisions.put(b.getSHA1(), r); } r.getBranches().add(b); } for (String tag : git.getTagNames(null)) { String tagRef = Constants.R_TAGS + tag; ObjectId objectId = git.revParse(tagRef); Revision r = revisions.get(objectId); if (r == null) { r = new Revision(objectId); revisions.put(objectId, r); } r.getBranches().add(new Branch(tagRef, objectId)); } return revisions.values(); }
revision.getBranches().add(new Branch(singleBranch, sha1)); return Collections.singletonList(revision);
revision.getBranches().add(new Branch(refspec, sha1));
@Override public Build prevBuildForChangelog(String singleBranch, BuildData data, GitClient git, BuildChooserContext context) throws InterruptedException, IOException { if (data != null) { ObjectId sha1 = git.revParse("FETCH_HEAD"); // Now we cheat and add the parent as the last build on the branch, so we can // get the changelog working properly-ish. ObjectId parentSha1 = getFirstParent(sha1, git); Revision parentRev = new Revision(parentSha1); parentRev.getBranches().add(new Branch(singleBranch, parentSha1)); int prevBuildNum = 0; Result r = null; Build lastBuild = data.getLastBuildOfBranch(singleBranch); if (lastBuild != null) { prevBuildNum = lastBuild.getBuildNumber(); r = lastBuild.getBuildResult(); } return new Build(parentRev, prevBuildNum, r); } else { //Hmm no sure what to do here, but the git plugin can handle us returning null here return null; } }