List of usage examples for org.eclipse.jgit.lib Constants R_HEADS
String R_HEADS
To view the source code for org.eclipse.jgit.lib Constants R_HEADS.
Click Source Link
From source file:org.kuali.student.git.model.TestSvnRevisionMapper.java
License:Educational Community License
private boolean testRevisionHead(long revision, List<Ref> branchHeads) throws IOException { for (Ref ref : branchHeads) { ObjectId head = revisionMapper.getRevisionBranchHead(revision, ref.getName().replaceFirst(Constants.R_HEADS, "")); if (head == null) return false; }// ww w . ja v a 2 s . c o m return true; }
From source file:org.kuali.student.git.model.TestSvnRevisionMapper.java
License:Educational Community License
private void testRevision(long revision, List<Ref> branchHeads) throws IOException { for (Ref ref : branchHeads) { ObjectId head = revisionMapper.getRevisionBranchHead(revision, ref.getName().replaceFirst(Constants.R_HEADS, "")); Assert.assertNotNull("head should never be null", head); Assert.assertEquals(ref.getObjectId(), head); }/* w w w .ja v a 2s . c o m*/ }
From source file:org.kuali.student.git.model.utils.GitTestUtils.java
License:Educational Community License
public static void assertPathsExist(Repository repository, String branchName, List<String> pathList) throws IOException { Ref ref = repository.getRef(Constants.R_HEADS + branchName); Assert.assertNotNull(ref);/* w w w .jav a2s.com*/ RevWalk rw = new RevWalk(repository); RevCommit commit = rw.parseCommit(ref.getObjectId()); TreeWalk tw = new TreeWalk(repository); tw.addTree(commit.getTree().getId()); tw.setRecursive(true); Set<String> unmatchedPaths = new HashSet<>(); unmatchedPaths.addAll(pathList); while (tw.next()) { String path = tw.getPathString(); Iterator<String> it = unmatchedPaths.iterator(); while (it.hasNext()) { String um = it.next(); if (path.startsWith(um)) it.remove(); } } Assert.assertEquals(0, unmatchedPaths.size()); tw.release(); rw.release(); }
From source file:org.kuali.student.git.model.utils.GitTestUtils.java
License:Educational Community License
/** * Ensure that the paths given to not exist in the current branch HEAD. * //from w w w. j a v a2 s .com * @param repository * @param branchName * @param pathList * @throws IOException */ public static void assertPathsDontExist(Repository repository, String branchName, List<String> pathList) throws IOException { Ref ref = repository.getRef(Constants.R_HEADS + branchName); Assert.assertNotNull(ref); RevWalk rw = new RevWalk(repository); RevCommit commit = rw.parseCommit(ref.getObjectId()); TreeWalk tw = new TreeWalk(repository); tw.addTree(commit.getTree().getId()); tw.setRecursive(true); Set<String> unmatchedPaths = new HashSet<>(); unmatchedPaths.addAll(pathList); int originalSize = unmatchedPaths.size(); while (tw.next()) { String path = tw.getPathString(); Iterator<String> it = unmatchedPaths.iterator(); while (it.hasNext()) { String um = it.next(); if (path.startsWith(um)) it.remove(); } } Assert.assertEquals(originalSize, unmatchedPaths.size()); tw.release(); rw.release(); }
From source file:org.kuali.student.repository.viewer.ViewerMain.java
License:Educational Community License
/** * @param args/*from w w w. j a va 2 s. co m*/ */ public static void main(String[] args) { if (args.length != 1 && args.length != 2 && args.length != 3) { System.err.println("USAGE: <git meta directory> [--simplify] [--report]"); System.exit(-1); } String gitDirectory = args[0]; File gitDir = new File(gitDirectory); if (!gitDir.exists()) { System.err.println(gitDirectory + " does not exist"); System.exit(-1); } boolean simplify = false; boolean report = false; if (args.length >= 2) { if (args[1].toLowerCase().equals("--simplify")) simplify = true; else if (args[1].toLowerCase().equals("--report")) report = true; } if (args.length == 3) { if (args[2].toLowerCase().equals("--simplify")) simplify = true; else if (args[2].toLowerCase().equals("--report")) report = true; } try { Repository repo = GitRepositoryUtils.buildFileRepository(gitDir, false, true); Graph<RevCommit, String> graph = new DirectedSparseMultigraph<RevCommit, String>(); RevWalk rw = new RevWalk(repo); Map<String, Ref> branchHeads = repo.getRefDatabase().getRefs(Constants.R_HEADS); Map<RevCommit, String> branchHeadCommitToBranchNameMap = new HashMap<RevCommit, String>(); for (Map.Entry<String, Ref> entry : branchHeads.entrySet()) { RevCommit branchHeadCommit = rw.parseCommit(entry.getValue().getObjectId()); rw.markStart(branchHeadCommit); branchHeadCommitToBranchNameMap.put(branchHeadCommit, entry.getValue().getName()); } // tags Map<String, Ref> tags = repo.getRefDatabase().getRefs(Constants.R_TAGS); for (Map.Entry<String, Ref> entry : tags.entrySet()) { RevTag tag = rw.parseTag(entry.getValue().getObjectId()); RevCommit branchHeadCommit = rw.parseCommit(tag.getObject().getId()); rw.markStart(branchHeadCommit); branchHeadCommitToBranchNameMap.put(branchHeadCommit, entry.getValue().getName()); } rw.sort(RevSort.TOPO); rw.sort(RevSort.REVERSE, true); RevCommit currentCommit = null; Set<RevCommit> commits = new HashSet<RevCommit>(); while ((currentCommit = rw.next()) != null) { commits.add(currentCommit); } for (RevCommit commit : commits) { if (simplify) { /* * The only vertexes will be the parentless commits, multi-parent commits and branch head commits. * * For each commit we need to walk the available parents backwards so that we find the candidate vertex to associate with. * */ if (RevCommitVertexUtils.isSimplifiedVertex(branchHeadCommitToBranchNameMap, commit)) { for (RevCommit parentCommit : commit.getParents()) { // find the parent commit that is a simplified vertex RevCommit currentVertex = RevCommitVertexUtils .findSimplifiedVertex(branchHeadCommitToBranchNameMap, parentCommit); graph.addEdge(commit.getId().name() + " to " + currentVertex.getId().name(), commit, currentVertex); } } } else { /* * For non-simplified mode we an edge between each commit and its parent commit. */ for (RevCommit parentCommit : commit.getParents()) { graph.addEdge(commit.getId().name() + " to " + parentCommit.getId().name(), commit, parentCommit); } } } if (report) { PrintWriter reporter = new PrintWriter(new File("vertex-report.txt")); List<RevCommitVertexCount> vertexes = new ArrayList<RevCommitVertexCount>(); for (RevCommit vertex : graph.getVertices()) { Collection<String> inEdges = graph.getInEdges(vertex); int size = inEdges.size(); if (size > 1) vertexes.add(new RevCommitVertexCount(vertex, size)); } Collections.sort(vertexes, new Comparator<RevCommitVertexCount>() { /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @Override public int compare(RevCommitVertexCount o1, RevCommitVertexCount o2) { // descending return new Integer(o2.getCount()).compareTo(new Integer(o1.getCount())); } }); reporter.println("Object Id:child count"); for (RevCommitVertexCount vertexCount : vertexes) { reporter.println(vertexCount.getVertex().getId().name() + ":" + vertexCount.getCount()); } reporter.close(); } new GitGraphFrame(gitDir, graph, branchHeadCommitToBranchNameMap, simplify); } catch (Exception e) { log.error("viewing failed", e); } }
From source file:org.kuali.student.svn.model.AbstractGitRespositoryTestCase.java
License:Educational Community License
protected Result createBranch(ObjectId objectId, String branchName) throws IOException { RefUpdate update = repo.updateRef(Constants.R_HEADS + branchName); update.setNewObjectId(objectId);// w ww . jav a2 s . c o m update.setForceUpdate(true); return update.update(); }
From source file:org.nbgit.ui.clone.CloneAction.java
License:Open Source License
public static void doInit(Repository repo, URIish uri, OutputLogger logger) throws IOException, URISyntaxException { repo.create();/* ww w . j av a2 s. co m*/ repo.getConfig().setBoolean("core", null, "bare", false); repo.getConfig().save(); logger.output("Initialized empty Git repository in " + repo.getWorkDir().getAbsolutePath()); logger.flushLog(); // save remote final RemoteConfig rc = new RemoteConfig(repo.getConfig(), "origin"); rc.addURI(uri); rc.addFetchRefSpec(new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*", Constants.R_REMOTES + "origin" + "/*")); rc.update(repo.getConfig()); repo.getConfig().save(); }
From source file:org.openengsb.connector.git.internal.GitServiceImpl.java
License:Apache License
protected void doCheckout(FetchResult fetchResult) throws IOException { final Ref head = fetchResult.getAdvertisedRef(Constants.R_HEADS + watchBranch); final RevWalk rw = new RevWalk(repository); final RevCommit mapCommit; try {/* w w w. j a va2 s. co m*/ LOGGER.debug("Mapping received reference to respective commit."); mapCommit = rw.parseCommit(head.getObjectId()); } finally { rw.release(); } final RefUpdate u; boolean detached = !head.getName().startsWith(Constants.R_HEADS); LOGGER.debug("Updating HEAD reference to revision [{}]", mapCommit.getId().name()); u = repository.updateRef(Constants.HEAD, detached); u.setNewObjectId(mapCommit.getId()); u.forceUpdate(); DirCacheCheckout dirCacheCheckout = new DirCacheCheckout(repository, null, repository.lockDirCache(), mapCommit.getTree()); dirCacheCheckout.setFailOnConflict(true); boolean checkoutResult = dirCacheCheckout.checkout(); LOGGER.debug("Checked out new repository revision to working directory"); if (!checkoutResult) { throw new IOException("Internal error occured on checking out files"); } }
From source file:org.sonatype.m2e.egit.internal.EgitScmHandler.java
License:Open Source License
protected String getRefName(MavenProjectScmInfo info) { String branch = info.getBranch(); if (branch == null || branch.trim().length() == 0) { branch = Constants.MASTER;// w w w .j a va 2 s .c o m } if (!branch.startsWith(Constants.R_REFS)) { branch = Constants.R_HEADS + branch; } return branch; }
From source file:org.uberfire.java.nio.fs.jgit.util.commands.RefTreeUpdateCommand.java
License:Apache License
public void execute() throws java.io.IOException, ConcurrentRefUpdateException { update(git.getRepository(), Constants.R_HEADS + name, commit); //this `initialization` aims to be temporary // -> without this cgit can't find master when cloning repos if (name.equals(MASTER) && !git.isHEADInitialized()) { synchronized (git.getRepository()) { symRef(git, HEAD, Constants.R_HEADS + name); git.setHeadAsInitialized();// w w w.j a va 2 s. com } } }