Skip to content

Commit

Permalink
Adding and commiting file now working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Amor Kvalheim committed Jul 21, 2010
1 parent 692b828 commit f544b75
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/git/loose_storage.js
Expand Up @@ -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
Expand Down
33 changes: 32 additions & 1 deletion lib/git/tree.js
Expand Up @@ -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
Expand Down
21 changes: 8 additions & 13 deletions test/test_git_index.js
Expand Up @@ -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 <tom@example.com>");

// 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) {
Expand All @@ -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();
});
});
});
});
});
})
});
});
});
}
Expand Down

0 comments on commit f544b75

Please sign in to comment.