Newbie questions regarding jgit
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.
Signature · 4 lines
Regards, Farrukh Najmi Web: http://www.wellfleetsoftware.com
Quoted 1 line · Farrukh Najmi
Hi all,
Hello,
Quoted 1 line
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.
Quoted 2 lines
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.
Quoted 7 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.
Quoted 3 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.
Signature · 1 line
Jonas Fonseca
Quoted 5 lines · Jonas Fonseca
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?
Signature · 1 line
Shawn.
Quoted 9 lines · Shawn O. Pearce
Quoted 4 lines · Jonas Fonseca
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 ...
Quoted 4 lines
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.
Signature · 1 line
Jonas Fonseca
Quoted 5 lines · Jonas Fonseca
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.
Quoted 8 lines
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.
Signature · 1 line
Shawn.
PATCH 1/1 Add maven distribution management info for the new snapshot repository
--- jgit-maven/jgit/pom.xml | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
Shawn O. Pearce <[email protected]> wrote Tue, Nov 11, 2008:
Quoted 6 lines
Quoted 3 lines · Jonas Fonseca
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
jgit-maven/jgit/pom.xml +8 -0
@@ -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>
Signature · 4 lines
1.6.0.3.866.gc189b -- Jonas Fonseca
Re: [PATCH] Add maven distribution management info for the new snapshot repository
Quoted 15 lines · Jonas Fonseca
Shawn O. Pearce <[email protected]> wrote Tue, Nov 11, 2008:
Quoted 6 lines
Quoted 3 lines · Jonas Fonseca
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
jgit-maven/jgit/pom.xml +0
-0
jgit-maven/jgit/pom.xml ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. · line 192
Quoted 8 lines
jgit-maven/jgit/pom.xml +5
-0@@ -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?
Signature · 1 line
Shawn.
Re: [PATCH] Add maven distribution management info for the new snapshot repository
Quoted 8 lines · Shawn O. Pearce
jgit-maven/jgit/pom.xml ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. · line 192
Quoted 5 lines · Jonas Fonseca
jgit-maven/jgit/pom.xml +5
-0+ <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.
Signature · 1 line
Shawn.
Quoted 9 lines · Shawn O. Pearce
Quoted 8 lines · Jonas Fonseca
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:
Quoted 8 lines
Quoted 5 lines
- 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!
Quoted 7 lines
--
Shawn.
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 7 lines
Imran M Yousuf Entrepreneur & Software Engineer Smart IT Engineering Dhaka, Bangladesh Email: [email protected] Blog: http://imyousuf-tech.blogs.smartitengineering.com/ Mobile: +880-1711402557
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:
...
Quoted 9 lines · Shawn O. Pearce
Quoted 8 lines
Quoted 5 lines · Jonas Fonseca
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.
...
Signature · 4 lines
Regards, Farrukh Najmi Web: http://www.wellfleetsoftware.com
Jonas Fonseca wrote:
...
Quoted 10 lines
Quoted 9 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
Quoted 6 lines
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.
Quoted 9 lines
Quoted 5 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.
Quoted 7 lines
- 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.
Signature · 4 lines
Regards, Farrukh Najmi Web: http://www.wellfleetsoftware.com
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 {
...}
}
Quoted 46 lines · Farrukh Najmi
Jonas Fonseca wrote:
...Quoted 10 lines
Quoted 9 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 fileQuoted 6 lines
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.
Quoted 9 lines
Quoted 5 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.
Quoted 7 lines
- 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.
Signature · 4 lines
Regards, Farrukh Najmi Web: http://www.wellfleetsoftware.com
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:
....
Quoted 92 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 fordesired 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 { ...}
}
Quoted 46 lines · Farrukh Najmi
Jonas Fonseca wrote:
...Quoted 10 lines
Quoted 9 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 fileQuoted 6 lines
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.
Quoted 9 lines
Quoted 5 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.
Quoted 7 lines
- 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.
Signature · 4 lines
Regards, Farrukh Najmi Web: http://www.wellfleetsoftware.com
Quoted 24 lines · Farrukh Najmi
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 DataHandlerget(String relativePath, String versionName)throwsRepositoryException { ObjectId retrieveStart = repository.resolve(versionName); RevWalk revWalk = new RevWalk(repository); RevCommit entry = revWalk.parseCommit(retrieveStart); RevTree revTree = entry.getTree(); TreeWalk treeWalk = TreeWalk.forPath(repository,
Quoted 3 lines
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
}Signature · 1 line
Shawn.
Quoted 4 lines · Farrukh Najmi
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.
Signature · 1 line
Jonas Fonseca
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.
Quoted 32 lines · Farrukh Najmi
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.xmlFor 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 fileI 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.
Signature · 4 lines
Regards, Farrukh Najmi Web: http://www.wellfleetsoftware.com