diff --git a/lib/git/loose_storage.js b/lib/git/loose_storage.js index ddcde51..eebbc13 100644 --- a/lib/git/loose_storage.js +++ b/lib/git/loose_storage.js @@ -159,10 +159,10 @@ LooseStorage.prototype.put_raw_object = function(content, type) { // Create gzip stream var gzip = new compress.Gzip; // Init the gzip stream - gzip.init(); + // gzip.init(); // Deflate the data var data = gzip.deflate(store); - var data = data + gzip.end(); + // var data = data + gzip.end(); // // sys.puts("================= compressed_size: " + gz_data.length) // File does not exist create the directory diff --git a/lib/git/tree.js b/lib/git/tree.js index a0864f6..e5fb81d 100644 --- a/lib/git/tree.js +++ b/lib/git/tree.js @@ -10,7 +10,38 @@ var Tree = exports.Tree = function(repo, id, mode, name, contents) { Object.defineProperty(this, "id", { get: function() { return _id; }, set: function(value) { _id = value; }, enumerable: true}); Object.defineProperty(this, "mode", { get: function() { return _mode; }, set: function(value) { _mode = value; }, enumerable: true}); Object.defineProperty(this, "name", { get: function() { return _name; }, set: function(value) { _name = value; }, enumerable: true}); - Object.defineProperty(this, "contents", { get: function() { return _contents; }, set: function(value) { _contents = value; }, enumerable: true}); + // Object.defineProperty(this, "contents", { get: function() { return _contents; }, set: function(value) { _contents = value; }, enumerable: true}); + + Object.defineProperty(this, "contents", { get: function() { + _contents = lazy_reader(_repo, _id, 'contents', _contents); + return _contents; + }, enumerable: true}); +} + +var lazy_reader = function(repo, id, type, variable) { + if(variable) return variable; + // Control the flow + var done = false; + var value = []; + + // Fetch the content + repo.git.ls_tree(id, [], {}, function(err, text) { + if(err) return done = true; + // Split the output + var lines = text.split("\n"); + // Create objects for all the entries + for(var i = 0; i < lines.length; i++) { + content_from_string(repo, lines[i], function(err, entry) { + if(err) return callback(err, entry); + value.push(entry); + }); + } + + done = true; + }) + + while(!done) {}; + return value; } // Construct the contents of the tree diff --git a/test/test_git_index.js b/test/test_git_index.js index 9830758..6909c22 100644 --- a/test/test_git_index.js +++ b/test/test_git_index.js @@ -59,16 +59,11 @@ suite.addTests({ create_tmp_directory(base_repo, function(err, target_path) { new Repo(target_path + "/dot_git_iv2", {is_bare:true}, function(err, repo) { - // try { var repository = repo.git.repository; var user = Actor.from_string("Tom Werner "); // Fetch the commits repo.commits(function(err, commits) { - sys.puts("=============================================================== commits") - // sys.puts(sys.inspect(commits)) - - var sha = commits[0].tree.id; repo.index(function(err, index) { @@ -78,17 +73,17 @@ suite.addTests({ index.add('atester.rb', 'test stuff'); index.commit('message', [commits[0]], user, null, 'master', function(err, result) { repo.commits(function(err, _commits) { - - sys.puts(sys.inspect(_commits)) + var c = _commits[0].tree.find('atester.rb'); + assert.equal('f80c3b68482d5e1c8d24c9b8139340f0d0a928d0', c.id) // Destory directory and cleanup - // destroy_directory(target_path, function(err, result) { - // finished(); - // }); - }) - }) + destroy_directory(target_path, function(err, result) { + finished(); + }); + }); + }); }); }); - }) + }); }); }); }