Skip to main content

[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

ah yeah, you should call walk.release() when finished :)

On 07/09/2012 02:54 PM, Markus Duft wrote:
> i use something like that (copy & pasted together, so it won't compile, i'm sure ;)):
> 
>     /**
>      * 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;
>         }
>     }
> 
> i'm sure i missed something, but that should give an idea ;) (and: all you real experts, please feel free to correct my code :D)
> 
> Regards,
> Markus
> 
> On 07/09/2012 02:47 PM, Rahul Chandrashekar (RBEI/EMT2) wrote:
>> 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_
>>  
>>  
>>  
>>
>>
>> _______________________________________________
>> egit-dev mailing list
>> egit-dev@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/egit-dev
>>
> 
> _______________________________________________
> egit-dev mailing list
> egit-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/egit-dev
> 



Back to the top