[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [egit-dev] Query on getting information of the list of files commited
|
The RevCommit is calculated by the getCommit() method i posted from a SHA-1 checksum string representation. You can also get RevCommit objects from a RevWalk, something like this:
Repository repo = new FileRepository("/path/to/my-repo/.git");
RevWalk walk = new RevWalk(repo);
try {
walk.setRevFilter(RevFilter.NO_MERGES);
walk.sort(RevSort.COMMIT_TIME_DESC, true);
walk.markStart(getCommit(Constants.HEAD));
RevCommit walked;
while ((walked = walk.next()) != null) {
// do something with "walked", like call getChangedFiles(walked)
}
} finally {
walk.release();
}
HTH, Markus
On 07/10/2012 11:59 AM, Rahul Chandrashekar (RBEI/EMT2) wrote:
>
>
> Hi Markus,
> I had a look at your post
> _http://dev.eclipse.org/mhonarc/lists/egit-dev/msg02839.html_
> regarding eGit notification.
> I have a query……How do I get the information of the following:
>
> /**
> * Retrieve a list of all changed files in a commit (based on a event).
> */
> public Map<String, FileMode getChangedFiles(*String commit*) {
> Map<String, FileMode result = new TreeMap<String, FileMode();
> try {
> TreeWalk walk = createTreeWalk(getCommit(commit));
>
> while (walk.next()) {
> result.put(walk.getPathString(), walk.getFileMode(1));
> }
> } catch (Exception ex) {
> log.error("failed to get files for " + e, ex);
> }
> return result;
> }
>
> /**
> * Create a new TreeWalk which can be used to find file-related info for a given commit
> */
> public TreeWalk createTreeWalk(*RevCommit commit*) throws Exception {
> if (commit.getParentCount() != 1) {
> throw new IllegalStateException("commit " + commit + " has not exactly one parent!");
> }
>
> // since the actual commit is added as second tree, from now on, index '1' refers to the
> // actual commit.
> TreeWalk walk = new TreeWalk(repo);
> walk.setFilter(TreeFilter.ANY_DIFF);
> walk.reset(commit.getParent(0).getTree(), commit.getTree());
> walk.setRecursive(true);
> return walk;
> }
>
> /**
> * Retrieves the commit object for the given rev string.
> */
> public RevCommit getCommit(String rev) {
> try {
> RevCommit ours = walk.parseCommit(getOidForRev(rev));
>
> // and as an extension, parse direct parents too. this is so the message is accessible later.
> for (RevCommit c : ours.getParents()) {
> walk.parseCommit(c);
> }
>
> return ours;
> } catch (Exception ex) {
> log.error("cannot find commit with id " + rev, ex);
> return null;
> }
> }
>
>
> 1. *String Commit*
> 2. *RevCommit *
>
> *Are there any means to get the same.*
> Mit freundlichen Grüßen / Best Regards,
> *Rahul Chandrashekar*
>
> Robert Bosch Engineering and Business Solutions Limited
> Engineering Methods and Tools (RBEI\EMT2)
> 123, Industrial Layout, Hosur Road, Koramangala,
> Bangalore – 560 095
> INDIA
> _www.bosch.com_ <http://www.bosch.com/>
>
> Tel. +91 80 6657 1661
> VoIp. +49(711)811-3615170
> Mobile +91 9886944213
> _rahul.chandrashekar@in.bosch.com_ <mailto:rahul.chandrashekar@xxxxxxxxxxxx>
>
>
>
> Mit freundlichen Grüßen / Best Regards,
> *Rahul Chandrashekar*
>
> Robert Bosch Engineering and Business Solutions Limited
> Engineering Methods and Tools (RBEI\EMT2)
> 123, Industrial Layout, Hosur Road, Koramangala,
> Bangalore – 560 095
> INDIA
> _www.bosch.com_ <http://www.bosch.com/>
>
> Tel. +91 80 6657 1661
> VoIp. +49(711)811-3615170
> Mobile +91 9886944213
> _rahul.chandrashekar@in.bosch.com_
>
>
> _____________________________________________
> *From:* Rahul Chandrashekar (RBEI/EMT2)
> *Sent:* Monday, 9. July 2012 6:18 PM
> *To:* 'egit-dev@xxxxxxxxxxx'
> *Subject:* Query on getting information of the list of files commited
>
>
> Dear All,
>
> I have a query, how do i get the list of files from eGit which are commited into the GIT repository.
>
> Please let know your feedback for the same.
>
> Mit freundlichen Grüßen / Best Regards,
> *Rahul Chandrashekar*
>
> Robert Bosch Engineering and Business Solutions Limited
> Engineering Methods and Tools (RBEI\EMT2)
> 123, Industrial Layout, Hosur Road, Koramangala,
> Bangalore – 560 095
> INDIA
> _www.bosch.com_ <http://www.bosch.com/>
>
> Tel. +91 80 6657 1661
> VoIp. +49(711)811-3615170
> Mobile +91 9886944213
> _rahul.chandrashekar@in.bosch.com_ <mailto:rahul.chandrashekar@xxxxxxxxxxxx>
>
>
>
>
>
> _______________________________________________
> egit-dev mailing list
> egit-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/egit-dev
>