List of usage examples for org.eclipse.jgit.lib ObjectId toString
public static final String toString(ObjectId i)
From source file:com.mortardata.project.EmbeddedMortarProject.java
License:Apache License
String syncEmbeddedProjectWithMirror(Git gitMirror, CredentialsProvider cp, String targetBranch, String committer) throws GitAPIException, IOException { // checkout the target branch gitUtil.checkout(gitMirror, targetBranch); // clear out the mirror directory contents (except .git and .gitkeep) File localBackingGitRepoPath = gitMirror.getRepository().getWorkTree(); for (File f : FileUtils.listFilesAndDirs(localBackingGitRepoPath, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".gitkeep")), FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".git")))) { if (!f.equals(localBackingGitRepoPath)) { logger.debug("Deleting existing mirror file" + f.getAbsolutePath()); FileUtils.deleteQuietly(f);//from w w w . j a v a 2 s . c o m } } // copy everything from the embedded project List<File> manifestFiles = getFilesAndDirsInManifest(); for (File fileToCopy : manifestFiles) { if (!fileToCopy.exists()) { logger.warn("Can't find file or directory " + fileToCopy.getCanonicalPath() + " referenced in manifest file. Ignoring."); } else if (fileToCopy.isDirectory()) { FileUtils.copyDirectoryToDirectory(fileToCopy, localBackingGitRepoPath); } else { FileUtils.copyFileToDirectory(fileToCopy, localBackingGitRepoPath); } } // add everything logger.debug("git add ."); gitMirror.add().addFilepattern(".").call(); // remove missing files (deletes) logger.debug("git add -u ."); gitMirror.add().setUpdate(true).addFilepattern(".").call(); // commit it logger.debug("git commit"); RevCommit revCommit = gitMirror.commit().setCommitter(committer, committer) .setMessage("mortar development snapshot commit").call(); return ObjectId.toString(revCommit); }
From source file:com.rimerosolutions.ant.git.tasks.CommitTask.java
License:Apache License
@Override protected void doExecute() throws BuildException { try {/*w w w . j a v a2 s .co m*/ setFailOnError(true); CommitCommand cmd = git.commit(); if (!GitTaskUtils.isNullOrBlankString(message)) { cmd.setMessage(brandedMessage ? GitTaskUtils.BRANDING_MESSAGE + " " : "" + message); } else { cmd.setMessage(GitTaskUtils.BRANDING_MESSAGE); } String prefix = getDirectory().getCanonicalPath(); String[] allFiles = getPath().list(); if (!GitTaskUtils.isNullOrBlankString(only)) { cmd.setOnly(only); } else if (allFiles.length > 0) { for (String file : allFiles) { String modifiedFile = translateFilePathUsingPrefix(file, prefix); log("Will commit " + modifiedFile); cmd.setOnly(modifiedFile); } } else { cmd.setAll(true); } GitSettings gitSettings = lookupSettings(); if (gitSettings == null) { throw new MissingRequiredGitSettingsException(); } cmd.setAmend(amend).setAuthor(gitSettings.getIdentity()).setCommitter(gitSettings.getIdentity()); if (reflogComment != null) { cmd.setReflogComment(reflogComment); } RevCommit revCommit = cmd.call(); if (revCommitIdProperty != null) { String revisionId = ObjectId.toString(revCommit.getId()); getProject().setProperty(revCommitIdProperty, revisionId); } log(revCommit.getFullMessage()); } catch (IOException ioe) { throw new GitBuildException(MESSAGE_COMMIT_FAILED, ioe); } catch (GitAPIException ex) { throw new GitBuildException(MESSAGE_COMMIT_FAILED, ex); } }
From source file:com.smartitengineering.version.impl.jgit.JGitImpl.java
License:Open Source License
public VersionedResource getVersionedResource(final String resourceId) { try {/* w w w. ja v a 2 s .c o m*/ String trimmedResourceId = VersionAPI.trimToProperResourceId(resourceId); if (StringUtils.isBlank(trimmedResourceId)) { throw new IllegalArgumentException("Invalid resource id!"); } Set<ObjectId> revisionIds = getGraphForResourceId(trimmedResourceId); if (revisionIds == null || revisionIds.isEmpty()) { throw new IllegalArgumentException("Resource id doesn't exist!"); } Revision[] revisions = new Revision[revisionIds.size()]; int i = 0; for (ObjectId revisionId : revisionIds) { String revisionIdStr = ObjectId.toString(revisionId); String content = new String(readObject(revisionIdStr)); revisions[i++] = VersionAPI.createRevision(VersionAPI.createResource(trimmedResourceId, content), revisionIdStr); } return VersionAPI.createVersionedResource(Arrays.asList(revisions)); } catch (Throwable ex) { throw new RuntimeException(ex); } }
From source file:com.smartitengineering.version.impl.jgit.JGitImpl.java
License:Open Source License
public Resource getResource(final String resourceId) { try {/*from w w w . j av a 2 s . c o m*/ String trimmedResourceId = VersionAPI.trimToProperResourceId(resourceId); if (StringUtils.isBlank(trimmedResourceId)) { throw new IllegalArgumentException("Invalid resource id!"); } ObjectId resourceObjectId; Tree head = getHeadTree(getReadRepository()); if (!head.existsBlob(trimmedResourceId)) { throw new IllegalArgumentException("Resource id doesn't exist!"); } TreeEntry treeEntry = head.findBlobMember(trimmedResourceId); resourceObjectId = treeEntry.getId(); return VersionAPI.createResource(trimmedResourceId, new String(readObject(ObjectId.toString(resourceObjectId)))); } catch (Throwable ex) { throw new RuntimeException(ex); } }
From source file:com.smartitengineering.version.impl.jgit.JGitImpl.java
License:Open Source License
public Resource getResourceByRevision(final String revisionId, final String resourceId) { try {// w w w .j av a 2 s . c o m String trimmedResourceId = VersionAPI.trimToProperResourceId(resourceId); if (StringUtils.isBlank(trimmedResourceId)) { throw new IllegalArgumentException("Invalid resource id!"); } ObjectId resourceObjectId; resourceObjectId = ObjectId.fromString(revisionId); return VersionAPI.createResource(trimmedResourceId, new String(readObject(ObjectId.toString(resourceObjectId)))); } catch (Throwable ex) { throw new RuntimeException(ex); } }
From source file:com.smartitengineering.version.impl.jgit.JGitImpl.java
License:Open Source License
protected ObjectId addOrUpdateToHead(final Commit commit, final Tree head) throws IOException { for (Revision revision : commit.getRevisions()) { String objectPath = revision.getResource().getId(); FileTreeEntry treeEntry;//from w w w .j a va 2 s. c o m boolean newEntry = false; if (head.existsBlob(objectPath)) { treeEntry = (FileTreeEntry) head.findBlobMember(objectPath); } else { treeEntry = head.addFile(objectPath); newEntry = true; } treeEntry.setExecutable(false); if (!revision.getResource().isDeleted()) { if (revision instanceof MutableRevision) { ObjectId revisionId = getObjectWriter().writeBlob(revision.getResource().getContentSize(), revision.getResource().getContentAsStream()); MutableRevision mutableRevision = (MutableRevision) revision; mutableRevision.setRevisionId(ObjectId.toString(revisionId)); treeEntry.setId(revisionId); } else { throw new IllegalArgumentException("SPI not implemented by API!"); } } else if (!newEntry) { if (revision instanceof MutableRevision) { ObjectId revisionId = treeEntry.getId(); MutableRevision mutableRevision = (MutableRevision) revision; mutableRevision.setRevisionId(ObjectId.toString(revisionId)); treeEntry.delete(); } else { throw new IllegalArgumentException("SPI not implemented by API!"); } } } GitIndex index = getWriteRepository().getIndex(); index.readTree(head); index.write(); ObjectId newHeadId = index.writeTree(); head.setId(newHeadId); return newHeadId; }
From source file:com.smartitengineering.version.impl.jgit.JGitImpl.java
License:Open Source License
protected void performCommit(final Commit newCommit, final Tree head) throws IOException { ObjectId[] parentIds;/*from w w w .ja v a2s. c o m*/ ObjectId currentHeadId = getWriteRepository().resolve(Constants.HEAD); if (currentHeadId != null) { parentIds = new ObjectId[] { currentHeadId }; } else { parentIds = new ObjectId[0]; } org.eclipse.jgit.lib.Commit commit = new org.eclipse.jgit.lib.Commit(getWriteRepository(), parentIds); commit.setTree(head); commit.setTreeId(head.getId()); PersonIdent person = new PersonIdent(newCommit.getAuthor().getName(), newCommit.getAuthor().getEmail()); commit.setAuthor(person); commit.setCommitter(person); commit.setMessage(newCommit.getCommitMessage()); ObjectId newCommitId = getObjectWriter().writeCommit(commit); if (newCommit instanceof MutableCommit) { MutableCommit mutableCommit = (MutableCommit) newCommit; mutableCommit.setCommitId(ObjectId.toString(newCommitId)); mutableCommit.setCommitTime(commit.getCommitter().getWhen()); commit.setCommitId(newCommitId); if (commit.getParentIds().length > 0) { mutableCommit.setParentCommitId(ObjectId.toString(commit.getParentIds()[0])); } else { mutableCommit.setParentCommitId(ObjectId.toString(ObjectId.zeroId())); } } else { throw new IllegalArgumentException("SPI not implemented by API!"); } RefUpdate refUpdate = getWriteRepository().updateRef(Constants.HEAD); refUpdate.setNewObjectId(commit.getCommitId()); refUpdate.setRefLogMessage(commit.getMessage(), false); refUpdate.forceUpdate(); }
From source file:hudson.plugins.git.RevisionParameterAction.java
License:Open Source License
public Revision toRevision(GitClient git) throws InterruptedException { if (revision != null) { return revision; }//from w ww.ja v a2 s . c o m ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); // Here we do not have any local branches, containing the commit. So... // we are to get all the remote branches, and show them to users, as // they are local final List<Branch> branches = normalizeBranches(git.getBranchesContaining(ObjectId.toString(sha1), true)); revision.getBranches().addAll(branches); return revision; }
From source file:jbenchmarker.trace.git.GitExtraction.java
License:Open Source License
Commit parseRepository(String path) throws IOException { HashMap<String, String> paths = new HashMap<String, String>(); HashMapSet<String, Integer> identifiers = new HashMapSet<String, Integer>(); HashMapSet<String, String> children = new HashMapSet<String, String>(); int freeId = 2; Commit head = null;/*w w w . j a v a 2s. co m*/ RevWalk revwalk = new RevWalk(repository); revwalk.sort(RevSort.TOPO); if (path != null) { revwalk.setTreeFilter(AndTreeFilter.create(PathFilter.create(path), TreeFilter.ANY_DIFF)); } revwalk.markStart(revwalk.parseCommit(repository.resolve("HEAD"))); Iterator<RevCommit> it = revwalk.iterator(); while (it.hasNext()) { RevCommit commit = it.next(); Commit co = new Commit(commit, children.getAll(ObjectId.toString(commit))); if (head == null) { // Head commit co.setId("HEAD"); head = co; if (path != null) { paths.put("HEAD", path); } identifiers.put("HEAD", 1); } co.setReplica(Collections.min(identifiers.getAll(co.getId()))); if (GitTrace.DEBUG || commit.getParentCount() > 1) { // Merge case -> store state List<String> mpaths = new LinkedList<String>(); List<byte[]> mraws = new LinkedList<byte[]>(); TreeWalk twalk = walker(commit, path); // paths.get(co.getId())); while (twalk.next()) { ObjectId id = twalk.getObjectId(0); mpaths.add(twalk.getPathString()); mraws.add(open(twalk.getPathString(), id)); } patchCrud.add(new Patch(co, mpaths, mraws)); } if (commit.getParentCount() > 1) { ++nbrMergeBefore; } if (commit.getParentCount() == 0) { // Final case : patch without parent List<FileEdition> edits = new LinkedList<FileEdition>(); TreeWalk walk = walker(commit, path); // paths.get(co.getId())); while (walk.next()) { ObjectId id = walk.getObjectId(0); edits.add(new FileEdition(walk.getPathString(), diff(new byte[0], open(walk.getPathString(), id)))); } patchCrud.add(new Patch(co, edits)); } else { detectRevert(commit); // Computes replica identifiers Iterator<Integer> itid = identifiers.getAll(co.getId()).iterator(); for (int p = 0; p < commit.getParentCount(); ++p) { RevCommit parent = commit.getParent(p); String parentId = ObjectId.toString(parent); children.put(parentId, co.getId()); // compute diff if (commit.getParentCount() == 1) { List<FileEdition> edits = new LinkedList<FileEdition>(); TreeWalk walk = walker(commit, parent, path); // paths.get(co.getId())); for (DiffEntry entry : DiffEntry.scan(walk)) { edits.add(createDiffResult(entry)); if (path != null) { paths.put(parentId, entry.getOldPath()); } } patchCrud.add(new Patch(co, parent, edits)); } if (itid.hasNext()) { identifiers.put(parentId, itid.next()); } else if (!identifiers.containsKey(ObjectId.toString(parent))) { identifiers.put(parentId, freeId); ++freeId; } } int i = 0; while (itid.hasNext()) { identifiers.put(ObjectId.toString(commit.getParent(i)), itid.next()); i = (i + 1) % commit.getParentCount(); } } commitCrud.add(co); } return head; }
From source file:jbenchmarker.trace.git.model.Commit.java
License:Open Source License
public Commit(String id, RevCommit co, Set<String> children) { this.id = id; this.author = new Person(co.getAuthorIdent()); this.committer = new Person(co.getCommitterIdent()); this.encoding = co.getEncoding().name(); this.message = co.getFullMessage(); this.parentsIds = new LinkedList<String>(); for (RevCommit p : co.getParents()) { parentsIds.add(ObjectId.toString(p)); }//from ww w .java 2 s . c o m this.childrenIds = (children == null) ? new LinkedList<String>() : new LinkedList<String>(children); }