Skip to content

Incorrect commit oid's when aggregated from commit.history() #81

@djrenren

Description

@djrenren

If we take the example code that mirrors git log. And have it run on the aggregated commits rather than on each commit event like so:

var git = require('nodegit'),
    async = require('async');

// Open the repository in the current directory.
git.repo('.git', function(error, repository) {
  if (error) {
    throw error;
  }

  // Use the master branch.
  repository.branch('master', function(error, branch) {
    if (error) {
      throw error;
    }

    branch.history().on('end', function(err, commits){
        commits.forEach(function(commit){
                 // Print out `git log` emulation.
            async.series([
                function(callback) {
                    commit.sha(callback);
                },
                function(callback) {
                    commit.time(callback);
                },
                function(callback) {
                    commit.author(function(error, author) {
                        author.name(callback);
                    });
                },
                function(callback) {
                    commit.author(function(error, author) {
                        author.email(callback);
                    });
                },
                function(callback) {
                    commit.message(callback);
                }
            ], function printCommit(error, results) {
                console.log('SHA ' + results[0]);
                console.log(new Date(results[1] * 1000));
                console.log(results[2] + ' <' + results[3] + '>');
                console.log(results[4]);
            });
        });
    });
  });
});

Then all the commit sha's are wrong. And most if not all of them point to nonexistant commits. Compare the outputs of the two versions of the program:
(I edited out the emails)

Original in README.md:

SHA a581e81d0205f27ede6a5557431a7ad16b4d4c60
Mon Jan 03 45538 18:06:40 GMT-0500 (EST)
ademoss <------------------------>
Initial commit

SHA 38e52f3dea8aac939168b4968f7f2688b9ce5a2e
Wed Jul 04 45551 06:20:00 GMT-0400 (EDT)
Anthony De Moss <------------------------>
- initial commit

SHA 9976fc4546bca7d152453be2c0c9ca59ca9bad7a
Sat Mar 01 45552 11:03:20 GMT-0500 (EST)
John renner <------------------------>
Initial implementation

SHA 700636e2d84f29a4ca8cfcc9b1c003c3c018fc7f
Thu Mar 13 45552 10:10:00 GMT-0400 (EDT)
John renner <------------------------>
Fixed silly naming conventions

Modified aggregating version:

SHA 0000000046bca7d1f01d00d4607f0000d0c92101
Mon Jan 03 45538 18:06:40 GMT-0500 (EST)
ademoss <------------------------>
Initial commit

SHA 0000000046bca7d1f01d00d4607f0000d0c92101
Wed Jul 04 45551 06:20:00 GMT-0400 (EDT)
Anthony De Moss <------------------------>
- initial commit

SHA 0000000046bca7d1f01d00d4607f0000d0c92101
Sat Mar 01 45552 11:03:20 GMT-0500 (EST)
John renner <------------------------>
Initial implementation

SHA 48fcde000000000070cd21010000000020fcde00
Thu Mar 13 45552 10:10:00 GMT-0400 (EDT)
John renner <------------------------>
Fixed silly naming conventions

The original matches the git log perfectly. The same thing happens if I try to manually aggregate them instead of using the aggregate provided in history().on('end').

I'm guessing this issue is due to some variable being reused improperly when creating the commits/oid's.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions