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

[JGIT RFC] How read versions of a specific object

From
Imran M Yousuf <imyousuf@gmail.com>
Date
Jan 7, 2009, 03:44 UTC
Message-ID
<7bfdc29a0901061944x454a9t1d01e6744f08cf78@mail.gmail.com>
Hi,

I am trying to read all or n-th version of an object. Currently to do this I am using the following piece of code, which has to walk to every commit is present and from there prepare a set of its object id, it is definitely expensive if the commit history is huge, is there a faster/better way to achieve it?

for (int i = 0; i < App.OBJECT_COUNT;
            ++i) {
            System.out.println("INDEX: " + i);
            String isbn =
                String.valueOf(Integer.parseInt(App.INIT_ID) + i);
            System.out.println("ISBN: " + isbn);
            ObjectWalk objectWalk = new ObjectWalk(repo);
            /*
             * Checks whether the Commit has the tree or not. It does not
             * check whether it has changed or not.
             */
            objectWalk.setTreeFilter(PathFilter.create(isbn));
            RevObject revObject = null;
            objectWalk.markStart(objectWalk.parseCommit(repo.resolve(
                Constants.HEAD)));
            Set<ObjectId> revisions =
                new HashSet<ObjectId>();
            do {
                if (revObject != null) {
                    Commit revision = repo.mapCommit(revObject.getId());
                    Tree versionTree = repo.mapTree(revision.getTreeId());
                    if (versionTree.existsBlob(isbn)) {
                        revisions.add(versionTree.findBlobMember(isbn).getId());
                    }
                }
                revObject = objectWalk.next();
            }
            while (revObject != null);
            System.out.println("Revisions: " + revisions);
        }

The details source code of the project is available @ http://github.com/imyousuf/jgit-usage/tree/master

Thank you,
-- 
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
Next: Shawn O. Pearce
Message 1 of 3 in “[JGIT RFC] How read versions of a specific object”
  1. Imran M YousufJan 7, 2009
  2. Shawn O. PearceJan 7, 2009
  3. Imran M YousufJan 7, 2009

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.