git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Newbie questions regarding jgit

From
Shawn O. Pearce <spearce@spearce.org>
Date
Nov 12, 2008, 19:29 UTC
Message-ID
<20081112192905.GW2932@spearce.org>
In-Reply-To
<491B18C4.2070000@wellfleetsoftware.com>
Farrukh Najmi <farrukh@wellfleetsoftware.com> wrote:
Show 27 quoted lines
>
> So far I have figured out how to get the treeWalk for the path filter as  
> shown below.
> Now I am lost as to how to get the blob associated with the treeWalk.  
> TIA for your help.
>
>   /**
>    * Gets the content of specified file in git Repo.
>    *
>    * @parameter relativePath the relative path in jitRepo for  desired  
> file to get
>    * @parameter versionName the versionName for the desired file. It  
> will be unmarshalled from String to ObjectId.
>    * @return the content of the desired file version packaged as a  
> DataHandler.
>    */
>   public DataHandler get(String relativePath, String versionName) throws 
> RepositoryException {
>            ObjectId retrieveStart = repository.resolve(versionName);
>            RevWalk revWalk = new RevWalk(repository);
>            RevCommit entry = revWalk.parseCommit(retrieveStart);
>            RevTree revTree = entry.getTree();
>
>            TreeWalk treeWalk = TreeWalk.forPath(repository,  
> relativePath, revTree);
>
>            //Not sure how to get the blob next
	if (treeWalk.next()) {
		// Path exists
		if (treeWalk.getFileMode(0).getObjectType() == Constants.OBJ_BLOB) {
			ObjectId blob = treeWalk.getObjectId(0);
		} else {
			// Not a blob, its something else (tree, gitlink)
		}
	} else {
		// Path not found
	}
-- 
Shawn.
Previous: Jonas Fonseca
Message 16 of 16 in “Newbie questions regarding jgit”
  1. Farrukh NajmiNov 11, 2008
  2. Farrukh NajmiNov 11, 2008
  3. Jonas FonsecaNov 11, 2008
  4. Shawn O. PearceNov 11, 2008
  5. Jonas FonsecaNov 11, 2008
  6. Shawn O. PearceNov 11, 2008
  7. Add maven distribution management info for the new snapshot repositoryJonas Fonseca, Nov 11, 2008
  8. Shawn O. PearceNov 12, 2008
  9. Shawn O. PearceNov 12, 2008
  10. Imran M YousufNov 12, 2008
  11. Farrukh NajmiNov 12, 2008
  12. Farrukh NajmiNov 12, 2008
  13. Farrukh NajmiNov 12, 2008
  14. Farrukh NajmiNov 12, 2008
  15. Jonas FonsecaNov 12, 2008
  16. Shawn O. PearceNov 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.