threads / discuss / 16275

Newbie questions regarding jgit

Subject: Newbie questions regarding jgit

## tl;dr

16 messages between Nov 11, 2008 and Nov 12, 2008.

replies: 15people: 5as markdown or json

Farrukh Najmi· Nov 11, 2008, 20:44 UTC · lore
Hi all,
I am git newbie and looking to use jgit in a servlet endpoint.

Where can I find a public maven repo for gjit? It seems there is one somewhere because of the following file in src tree:

jgit-maven/jgit/pom.xml

For now I have built the jar using /make_jgit.sh and installed the pom manually using m

mvn install:install-file -DpomFile=jgit-maven/jgit/pom.xml -Dfile=jgit.jar
I have added the following dependency to my maven project's pom.xml:
   <dependency>
     <groupId>org.spearce</groupId>
     <artifactId>jgit</artifactId>
     <version>0.4-SNAPSHOT</version>
   </dependency>

Now I am wondering where to begin to learn how to do the equivalent of the following commands via the gjit Java API:

    * git add /file/
    * git rm /file/
    * git mv /file
    * Whatever is the git way to get a specific version of a file

I am hoping that there aremore docs, samples, tutorials etc. somewhere that I am missing. Thanks for any help you can provide. Some pointers or code fragments would be terrific.

-- 
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com
Farrukh Najmi· Nov 11, 2008, 21:12 UTC · re: Farrukh Najmi · lore

Re: Newbie questions regarding jgit

I should clarify that I am not using eclipse nor am I using any GUI. My objective is to have Java API access to git from within a servlet using jgit. At present, all I have to go on is javadoc and its not clear where to begin if I simply wish to create, read and update files in a git repo from within the servlet java code.

TIA for your help.
Farrukh Najmi wrote:
Show 37 quoted lines
>
> Hi all,
>
> I am git newbie and looking to use jgit in a servlet endpoint.
>
> Where can I find a public maven repo for gjit? It seems there is one 
> somewhere because of the following file in src tree:
>
> jgit-maven/jgit/pom.xml
>
> For now I have built the jar using /make_jgit.sh and installed the pom 
> manually using m
>
> mvn install:install-file -DpomFile=jgit-maven/jgit/pom.xml 
> -Dfile=jgit.jar
>
> I have added the following dependency to my maven project's pom.xml:
>
>   <dependency>
>     <groupId>org.spearce</groupId>
>     <artifactId>jgit</artifactId>
>     <version>0.4-SNAPSHOT</version>
>   </dependency>
>
> Now I am wondering where to begin to learn how to do the equivalent of 
> the following commands via the gjit Java API:
>
>    * git add /file/
>    * git rm /file/
>    * git mv /file
>    * Whatever is the git way to get a specific version of a file
>
>
> I am hoping that there aremore docs, samples, tutorials etc. somewhere 
> that I am missing. Thanks for any help you can provide. Some pointers 
> or code fragments would be terrific.
>
-- 
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com
Jonas Fonseca· Nov 11, 2008, 21:37 UTC · re: Farrukh Najmi · lore

Re: Newbie questions regarding jgit

On Tue, Nov 11, 2008 at 21:44, Farrukh Najmi <farrukh@wellfleetsoftware.com> wrote:

> Hi all,
Hello,
> I am git newbie and looking to use jgit in a servlet endpoint.

Sounds interesting. I have been thinking about how hard it would be to write a very simpe jgitweb kind of thing and am very interested to hear more about your experiences.

> Where can I find a public maven repo for gjit? It seems there is one
> somewhere because of the following file in src tree:

I would also like to have a public available maven repository for JGit. If Shawn or Robin acks, I can look into hosting one in the SVN area of the Google Code project page. Given the lack of a real release cycle it probably only makes sense to have a snapshot repository.

Show 7 quoted lines
> Now I am wondering where to begin to learn how to do the equivalent of the
> following commands via the gjit Java API:
>
>   * git add /file/
>   * git rm /file/
>   * git mv /file
>   * Whatever is the git way to get a specific version of a file

JGit currently has two APIs for working with the index, which will allow you to add, remove and move data around in the tree. In nbgit I ended up using GitIndex, which I found easier to figure out. As I understand it, in the long run you want to use the DirCache API, but it is still a work in progress.

> I am hoping that there aremore docs, samples, tutorials etc. somewhere that
> I am missing. Thanks for any help you can provide. Some pointers or code
> fragments would be terrific.

I started working on a tutorial for JGit, but didn't get very far so it mostly consists of stub pages.

 - http://code.google.com/docreader/#p=egit&s=egit&t=JGitTutorial

I have been working on moving the tutorial to maven project before starting to write the more code heavy topics. This would make it possible to include code snippets in the tutorial, while also allowing to compile and test the examples.

-- 
Jonas Fonseca
Shawn O. Pearce· Nov 11, 2008, 21:44 UTC · re: Jonas Fonseca · lore

Re: Newbie questions regarding jgit

Jonas Fonseca <jonas.fonseca@gmail.com> wrote:
Show 5 quoted lines
> 
> I would also like to have a public available maven repository for
> JGit. If Shawn or Robin acks, I can look into hosting one in the SVN
> area of the Google Code project page. Given the lack of a real release
> cycle it probably only makes sense to have a snapshot repository.

I have an account on kernel.org and was planning on hosting snapshots there, but I haven't had time to think about setting up a jgit area and pushing something into it. ;-)

We could also just host it in SVN in Google Code. I can give you admin rights on the egit project if you want to set it up and maintain it there. The downside is you need to use svn or git-svn to upload files to it, right?

-- 
Shawn.
Jonas Fonseca· Nov 11, 2008, 22:01 UTC · re: Shawn O. Pearce · lore

Re: Newbie questions regarding jgit

On Tue, Nov 11, 2008 at 22:44, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 9 quoted lines
> Jonas Fonseca <jonas.fonseca@gmail.com> wrote:
>> I would also like to have a public available maven repository for
>> JGit. If Shawn or Robin acks, I can look into hosting one in the SVN
>> area of the Google Code project page. Given the lack of a real release
>> cycle it probably only makes sense to have a snapshot repository.
>
> I have an account on kernel.org and was planning on hosting snapshots
> there, but I haven't had time to think about setting up a jgit area
> and pushing something into it.  ;-)
If you prefer that ...
> We could also just host it in SVN in Google Code.  I can give
> you admin rights on the egit project if you want to set it up and
> maintain it there.  The downside is you need to use svn or git-svn
> to upload files to it, right?

I don't think admin rights are necessary as long as I have "commit"/webdav access. And no svn or git-svn interaction should be needed to upload to the maven repository.

Take a look at the distributionManagement section of the google-maven-repository:

 - http://google-maven-repository.googlecode.com/svn/repository/com/google/google/1/google-1.pom

Looks pretty easy to set up. About maintaining it, I don't mind doing "mvn deploy" once in a while, but some kind of update policy should probably be worked out in any case.

-- 
Jonas Fonseca
Shawn O. Pearce· Nov 11, 2008, 23:11 UTC · re: Jonas Fonseca · lore

Re: Newbie questions regarding jgit

Jonas Fonseca <jonas.fonseca@gmail.com> wrote:
Show 13 quoted lines
> 
> I don't think admin rights are necessary as long as I have
> "commit"/webdav access. And no svn or git-svn interaction should be
> needed to upload to the maven repository.
> 
> Take a look at the distributionManagement section of the
> google-maven-repository:
> 
>  - http://google-maven-repository.googlecode.com/svn/repository/com/google/google/1/google-1.pom
> 
> Looks pretty easy to set up. About maintaining it, I don't mind doing
> "mvn deploy" once in a while, but some kind of update policy should
> probably be worked out in any case.
Then have at it.  It sounds like it would be worthwhile setting up.
-- 
Shawn.
Jonas Fonseca· Nov 11, 2008, 23:48 UTC · re: Shawn O. Pearce · lore

[PATCH] Add maven distribution management info for the new snapshot repository

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
 jgit-maven/jgit/pom.xml |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
 Shawn O. Pearce <spearce@spearce.org> wrote Tue, Nov 11, 2008:
 > Jonas Fonseca <jonas.fonseca@gmail.com> wrote:
 > > I don't think admin rights are necessary as long as I have
 > > "commit"/webdav access. And no svn or git-svn interaction should be
 > > needed to upload to the maven repository.
 > 
 > Then have at it.  It sounds like it would be worthwhile setting up.
 Instructions at http://code.google.com/p/egit/wiki/ConfiguringMaven
diff --git a/jgit-maven/jgit/pom.xml b/jgit-maven/jgit/pom.xml
index a123470..c370783 100644
--- a/jgit-maven/jgit/pom.xml
+++ b/jgit-maven/jgit/pom.xml
@@ -185,4 +185,12 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
             <scope>compile</scope>
         </dependency>
     </dependencies>
+    <distributionManagement>
+        <snapshotRepository>
+            <id>jgit-maven-snapshot-repository</id>
+            <name>JGit Maven Snapshot Repository</name>
+            <url>dav:https://egit.googlecode.com/svn/maven/snapshot-repository/</url>
+            <uniqueVersion>true</uniqueVersion>
+        </snapshotRepository>
+    </distributionManagement>
 </project>
-- 
1.6.0.3.866.gc189b

-- 
Jonas Fonseca
Shawn O. Pearce· Nov 12, 2008, 00:58 UTC · re: Jonas Fonseca · lore

Re: [PATCH] Add maven distribution management info for the new snapshot repository

Jonas Fonseca <fonseca@diku.dk> wrote:
Show 23 quoted lines
>  Shawn O. Pearce <spearce@spearce.org> wrote Tue, Nov 11, 2008:
>  > Jonas Fonseca <jonas.fonseca@gmail.com> wrote:
>  > > I don't think admin rights are necessary as long as I have
>  > > "commit"/webdav access. And no svn or git-svn interaction should be
>  > > needed to upload to the maven repository.
>  > 
>  > Then have at it.  It sounds like it would be worthwhile setting up.
> 
>  Instructions at http://code.google.com/p/egit/wiki/ConfiguringMaven
> 
> diff --git a/jgit-maven/jgit/pom.xml b/jgit-maven/jgit/pom.xml
> index a123470..c370783 100644
> --- a/jgit-maven/jgit/pom.xml
> +++ b/jgit-maven/jgit/pom.xml
> @@ -185,4 +185,12 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>              <scope>compile</scope>
>          </dependency>
>      </dependencies>
> +    <distributionManagement>
> +        <snapshotRepository>
> +            <id>jgit-maven-snapshot-repository</id>
> +            <name>JGit Maven Snapshot Repository</name>
> +            <url>dav:https://egit.googlecode.com/svn/maven/snapshot-repository/</url>
Shouldn't that be http:// and not https:// ?

The https interface asked me for a username/password, the http:// one doesn't. We want this to be public, don't we?

-- 
Shawn.
Shawn O. Pearce· Nov 12, 2008, 01:01 UTC · re: Shawn O. Pearce · lore

Re: [PATCH] Add maven distribution management info for the new snapshot repository

"Shawn O. Pearce" <spearce@spearce.org> wrote:
Show 8 quoted lines
> Jonas Fonseca <fonseca@diku.dk> wrote:
> > +    <distributionManagement>
> > +        <snapshotRepository>
> > +            <id>jgit-maven-snapshot-repository</id>
> > +            <name>JGit Maven Snapshot Repository</name>
> > +            <url>dav:https://egit.googlecode.com/svn/maven/snapshot-repository/</url>
> 
> Shouldn't that be http:// and not https:// ?
Oh, wait, never mind me.

I guess this makes sense; https:// for the distribution upload, but the wiki page you added uses plain http:// for download.

Patch applied.
 
-- 
Shawn.
Imran M Yousuf· Nov 12, 2008, 02:24 UTC · re: Shawn O. Pearce · lore

Re: Newbie questions regarding jgit

On Wed, Nov 12, 2008 at 5:11 AM, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 17 quoted lines
> Jonas Fonseca <jonas.fonseca@gmail.com> wrote:
>>
>> I don't think admin rights are necessary as long as I have
>> "commit"/webdav access. And no svn or git-svn interaction should be
>> needed to upload to the maven repository.
>>
>> Take a look at the distributionManagement section of the
>> google-maven-repository:
>>
>>  - http://google-maven-repository.googlecode.com/svn/repository/com/google/google/1/google-1.pom
>>
>> Looks pretty easy to set up. About maintaining it, I don't mind doing
>> "mvn deploy" once in a while, but some kind of update policy should
>> probably be worked out in any case.
>
> Then have at it.  It sounds like it would be worthwhile setting up.
>
This idea is cool!
Show 7 quoted lines
> --
> Shawn.
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
-- 
Imran M Yousuf
Entrepreneur & Software Engineer
Smart IT Engineering
Dhaka, Bangladesh
Email: imran@smartitengineering.com
Blog: http://imyousuf-tech.blogs.smartitengineering.com/
Mobile: +880-1711402557
Farrukh Najmi· Nov 12, 2008, 12:51 UTC · re: Jonas Fonseca · lore

Re: Newbie questions regarding jgit

The jgit team, rocks! You guys are simply awesome in your responsiveness. Thanks for a great project.

Please let me know if I can help with any maven related issues. Here is a couple of links I use to evangelize use of maven in OS projects:

Why Maven Rocks: <http://farrukhnajmi.blogspot.com/2008/02/why-maven-rocks-in-beginning-there-was.html>

Why Maven - Wiki Page: <http://ebxmlrr.wiki.sourceforge.net/whymaven>

Here are the main resources I use as reference for maven:

Maven Official Docs: <http://maven.apache.org/guides/index.html>

Better Builds With Maven: <http://www.topazproject.org/trac/attachment/wiki/MavenInfo/BetterBuildsWithMaven.pdf?format=raw>

I think it is great that the project supports maven at least partially today. I would suggest the project consider maven for all its build/configuration management at some point in future. It takes a little learning curve initially (most for dev team members not users) but pays off handsomely very quickly.

Jonas Fonseca wrote: ...

Show 9 quoted lines
> On Tue, Nov 11, 2008 at 22:44, Shawn O. Pearce <spearce@spearce.org> wrote:
>   
>> Jonas Fonseca <jonas.fonseca@gmail.com> wrote:
>>     
>>> I would also like to have a public available maven repository for
>>> JGit. If Shawn or Robin acks, I can look into hosting one in the SVN
>>> area of the Google Code project page. Given the lack of a real release
>>> cycle it probably only makes sense to have a snapshot repository.
>>>       
...
-- 
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com
Farrukh Najmi· Nov 12, 2008, 14:05 UTC · re: Jonas Fonseca · lore

Re: Newbie questions regarding jgit

Jonas Fonseca wrote: ...

Show 16 quoted lines
>   
>> Now I am wondering where to begin to learn how to do the equivalent of the
>> following commands via the gjit Java API:
>>
>>   * git add /file/
>>   * git rm /file/
>>   * git mv /file
>>   * Whatever is the git way to get a specific version of a file
>>     
>
> JGit currently has two APIs for working with the index, which will
> allow you to add, remove and move data around in the tree. In nbgit I
> ended up using GitIndex, which I found easier to figure out. As I
> understand it, in the long run you want to use the DirCache API, but
> it is still a work in progress.
>   

I am happy to use GitIndex now and switch to DirCache API later when it is ready. Can I please get some pseudo-code fragments on how to do the use cases I identified above? The javadoc is still not obvious to me.

Show 16 quoted lines
>   
>> I am hoping that there aremore docs, samples, tutorials etc. somewhere that
>> I am missing. Thanks for any help you can provide. Some pointers or code
>> fragments would be terrific.
>>     
>
> I started working on a tutorial for JGit, but didn't get very far so
> it mostly consists of stub pages.
>
>  - http://code.google.com/docreader/#p=egit&s=egit&t=JGitTutorial
>
> I have been working on moving the tutorial to maven project before
> starting to write the more code heavy topics. This would make it
> possible to include code snippets in the tutorial, while also allowing
> to compile and test the examples.
>   

The wiki is an awesome resource even in its current state. Thank you. I would be glad to help contribute improvements to wiki if you give me write privilege. What I could do is take the help I get from the list and then update wiki carefully as appropriate if you want me to help.

Thanks again to all of you for helping get me bootstrapped with gjit and git.

-- 
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com
Farrukh Najmi· Nov 12, 2008, 14:33 UTC · re: Farrukh Najmi · lore

Re: Newbie questions regarding jgit

BTW, the context for what I am doing is as follows. I am implementing OASIS ebXML Registry/Repository (RegRep) 4 specs:

<http://www.oasis-open.org/committees/download.php/29972>

I would like to use git for the Repository part of the RegRep while a relational database will hold the registry part which contains extensive metadata about repository files. Later I will also evaluate if I can somehow use git for the Registry part so I can leverage versioning features of git. I would still need to have the Registry content duplicated in relational database to support querying of the metadata. The standard eventually needs to support CheckIn/Checkout and I think a distributed VCS like git would be very helpful in an implementation.

For those unfamiliar with RegRep as a technology think of it as providing added value on top of a generic VCS, database or Content Management system.

For my immediate needs, I need to implement a GitRepository class with two methods using gjit as shown below. I would appreciate any guidance and pseudo-code examples on how to implement these methods. Please keep in mind that I am just getting to know git itself and gjit was key to my considering git over Mercurial and other distributed VCSs.

public class GitRepositoryManager {
    Repository gitRepo;
    ...
    /**
     * 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 {
        DataHandler dh = null;
        ...
       
        return dh;
    }
    /**
     * Creates a new version of specified version of 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.
     * @parameter content the content of the new version for specified 
file packaged as a DataHandler.
     */
    public void update(String relativePath, String versionName, 
DataHandler content) throws RepositoryException {
        ...
    }
}
Farrukh Najmi wrote:
Show 52 quoted lines
> Jonas Fonseca wrote:
> ...
>>  
>>> Now I am wondering where to begin to learn how to do the equivalent 
>>> of the
>>> following commands via the gjit Java API:
>>>
>>>   * git add /file/
>>>   * git rm /file/
>>>   * git mv /file
>>>   * Whatever is the git way to get a specific version of a file
>>>     
>>
>> JGit currently has two APIs for working with the index, which will
>> allow you to add, remove and move data around in the tree. In nbgit I
>> ended up using GitIndex, which I found easier to figure out. As I
>> understand it, in the long run you want to use the DirCache API, but
>> it is still a work in progress.
>>   
>
> I am happy to use GitIndex now and switch to DirCache API later when 
> it is ready.
> Can I please get some pseudo-code fragments on how to do the use cases 
> I identified above?
> The javadoc is still not obvious to me.
>>  
>>> I am hoping that there aremore docs, samples, tutorials etc. 
>>> somewhere that
>>> I am missing. Thanks for any help you can provide. Some pointers or 
>>> code
>>> fragments would be terrific.
>>>     
>>
>> I started working on a tutorial for JGit, but didn't get very far so
>> it mostly consists of stub pages.
>>
>>  - http://code.google.com/docreader/#p=egit&s=egit&t=JGitTutorial
>>
>> I have been working on moving the tutorial to maven project before
>> starting to write the more code heavy topics. This would make it
>> possible to include code snippets in the tutorial, while also allowing
>> to compile and test the examples.
>>   
>
> The wiki is an awesome resource even in its current state. Thank you.
> I would be glad to help contribute improvements to wiki if you give me
> write privilege. What I could do is take the help I get from the list and
> then update wiki carefully as appropriate if you want me to help.
>
> Thanks again to all of you for helping get me bootstrapped with gjit 
> and git.
>
-- 
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com
Farrukh Najmi· Nov 12, 2008, 17:56 UTC · re: Farrukh Najmi · lore

Re: Newbie questions regarding jgit

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
   }

Farrukh Najmi wrote: ....

Show 103 quoted lines
> For my immediate needs, I need to implement a GitRepository class with 
> two methods using gjit as shown below. I would appreciate any guidance 
> and pseudo-code examples on how to implement these methods. Please 
> keep in mind that I am just getting to know git itself and gjit was 
> key to my considering git over Mercurial and other distributed VCSs.
>
> public class GitRepositoryManager {
>
>    Repository gitRepo;
>
>    ...
>
>    /**
>     * 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 {
>        DataHandler dh = null;
>
>        ...
>              return dh;
>    }
>
>    /**
>     * Creates a new version of specified version of 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.
>     * @parameter content the content of the new version for specified 
> file packaged as a DataHandler.
>     */
>    public void update(String relativePath, String versionName, 
> DataHandler content) throws RepositoryException {
>        ...
>    }
>
> }
>
> Farrukh Najmi wrote:
>> Jonas Fonseca wrote:
>> ...
>>>  
>>>> Now I am wondering where to begin to learn how to do the equivalent 
>>>> of the
>>>> following commands via the gjit Java API:
>>>>
>>>>   * git add /file/
>>>>   * git rm /file/
>>>>   * git mv /file
>>>>   * Whatever is the git way to get a specific version of a file
>>>>     
>>>
>>> JGit currently has two APIs for working with the index, which will
>>> allow you to add, remove and move data around in the tree. In nbgit I
>>> ended up using GitIndex, which I found easier to figure out. As I
>>> understand it, in the long run you want to use the DirCache API, but
>>> it is still a work in progress.
>>>   
>>
>> I am happy to use GitIndex now and switch to DirCache API later when 
>> it is ready.
>> Can I please get some pseudo-code fragments on how to do the use 
>> cases I identified above?
>> The javadoc is still not obvious to me.
>>>  
>>>> I am hoping that there aremore docs, samples, tutorials etc. 
>>>> somewhere that
>>>> I am missing. Thanks for any help you can provide. Some pointers or 
>>>> code
>>>> fragments would be terrific.
>>>>     
>>>
>>> I started working on a tutorial for JGit, but didn't get very far so
>>> it mostly consists of stub pages.
>>>
>>>  - http://code.google.com/docreader/#p=egit&s=egit&t=JGitTutorial
>>>
>>> I have been working on moving the tutorial to maven project before
>>> starting to write the more code heavy topics. This would make it
>>> possible to include code snippets in the tutorial, while also allowing
>>> to compile and test the examples.
>>>   
>>
>> The wiki is an awesome resource even in its current state. Thank you.
>> I would be glad to help contribute improvements to wiki if you give me
>> write privilege. What I could do is take the help I get from the list 
>> and
>> then update wiki carefully as appropriate if you want me to help.
>>
>> Thanks again to all of you for helping get me bootstrapped with gjit 
>> and git.
>>
>
>
-- 
Regards,
Farrukh Najmi

Web: http://www.wellfleetsoftware.com
Jonas Fonseca· Nov 12, 2008, 18:30 UTC · re: Farrukh Najmi · lore

Re: Newbie questions regarding jgit

On Wed, Nov 12, 2008 at 18:56, Farrukh Najmi <farrukh@wellfleetsoftware.com> wrote:

> 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.

For ideas take a look at how the NetBeans git plugin accomplishes some of the most common git tasks take a look at the GitCommand.java file. It contains code for adding and removing files, committing updates to the index. There is also some code trying to get "git-status" information, but it is not very smart or clean. Something equivalent to "git cat-file" (getting the blob data) can be seen at line 120:

 - http://github.com/myabc/nbgit/tree/master/src/org/nbgit/util/GitCommand.java#L120
Sorry, I should have suggested this earlier.
-- 
Jonas Fonseca
Shawn O. Pearce· Nov 12, 2008, 19:29 UTC · re: Farrukh Najmi · lore

Re: Newbie questions regarding jgit

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.

← back to recent threads