Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes commit

  • Loading branch information...
commit ee3da976da86ded0b2ae86adaa2e16ccaf446008 1 parent 5f904c0
@gierschv gierschv authored
View
40 lib/git/git_index.js
@@ -1,4 +1,5 @@
var util = require('util'),
+ async = require('async'),
Tree = require('./tree').Tree,
Config = require('./config').Config;
@@ -101,7 +102,7 @@ var to_bin = function(sha1o) {
var sha1 = '';
for(var i = 0; i < sha1o.length; i = i + 2) {
sha1 = sha1 + String.fromCharCode(parseInt(sha1o.substr(i, 2), 16));
- }
+ }
return sha1;
}
@@ -131,39 +132,42 @@ GitIndex.prototype.write_tree = function(tree, now_tree, callback) {
}
// overwrite with the new tree contents
- Object.keys(tree).forEach(function(key) {
+ async.each(Object.keys(tree), function(key, callback) {
var value = tree[key];
if(value.constructor == String) {
- var sha = self.write_blob(value);
- sha = to_bin(sha);
- tree_contents[key] = "" + '100644' + " " + key + '\0' + sha;
+ self.write_blob(value, function (sha) {
+ sha = to_bin(sha);
+ tree_contents[key] = "" + '100644' + " " + key + '\0' + sha;
+ callback();
+ });
} else if(Object.prototype.toString.call(value) === '[object Object]') {
var ctree = now_tree ? (now_tree.find(key)) : null;
// Write the next level
self.write_tree(value, ctree, function(err, sha) {
var sha = to_bin(sha);
- tree_contents[key + '/'] = "" + '040000' + " " + key + '\0' + sha;
+ tree_contents[key + '/'] = "" + '040000' + " " + key + '\0' + sha;
+ callback();
});
}
- })
-
- var tr = Object.keys(tree_contents).sort().map(function(key) {
- return tree_contents[key];
- }).join('');
-
- // Return the object sha
- this.repo.git.put_raw_object(tr, 'tree', function (sha1) {
- callback(null, sha1);
- })
+ }, function () {
+ var tr = Object.keys(tree_contents).sort().map(function(key) {
+ return tree_contents[key];
+ }).join('');
+
+ // Return the object sha
+ this.repo.git.put_raw_object(tr, 'tree', function (sha1) {
+ callback(null, sha1);
+ });
+ }.bind(this));
}
// Write the blob to the index
// +data+ is the data to write
//
// Returns the SHA1 String of the blob
-GitIndex.prototype.write_blob = function(data) {
- return this.repo.git.put_raw_object(data, 'blob');
+GitIndex.prototype.write_blob = function(data, callback) {
+ this.repo.git.put_raw_object(data, 'blob', callback);
}
View
32 lib/git/loose_storage.js
@@ -1,4 +1,5 @@
var util = require('util'),
+ buffer = require('buffer'),
fs = require('fs'),
BinaryParser = require('./binary_parser').BinaryParser,
Zlib = require('../zlib/zlib').Zlib,
@@ -121,33 +122,24 @@ LooseStorage.prototype.put_raw_object = function(content, type, callback) {
var header = "" + type + " " + size + "\0";
var store = header + content;
// Use node crypto library to create sha1 hash
- var hash = crypto.createHash("sha1");
- hash.update(store);
+ var hash = crypto.createHash('sha1');
+ hash.update(store, 'binary');
// Return the hash digest
var sha1 = hash.digest('hex');
// Create path
- var path = this.directory + "/" + sha1.substr(0, 2) + '/' + sha1.substr(2);
-
+ var path = this.directory + '/' + sha1.substr(0, 2) + '/' + sha1.substr(2);
try {
fs.statSync(path);
- } catch(err) {
+ } catch(err) {
// Deflate the data
- var data = zlib.gunzip(store, function (err, buffer) {
- if (err) {
- throw err;
- }
-
+ var buffStore = new Buffer(store, 'ascii');
+ var data = zlib.deflate(buffStore, function (err, buffer) {
+ if (err) { throw err; }
// File does not exist create the directory
- fs.mkdir(self.directory + "/" + sha1.substr(0, 2), 16877, function (err) {
- if (err) {
- throw err;
- }
-
- fs.writeFile(path, data, 'binary', function (err) {
- if (err) {
- throw err;
- }
-
+ fs.mkdir(self.directory + '/' + sha1.substr(0, 2), 16877, function (err) {
+ if (err) { throw err; }
+ fs.writeFile(path, buffer, 'binary', function (err) {
+ if (err) { throw err; }
callback(sha1);
});
});
View
3  lib/git/repository.js
@@ -745,7 +745,8 @@ var add_file = function(dir, name, content) {
// writes a raw object into the git repo
Repository.prototype.put_raw_object = function(content, type, callback) {
- return this.loose[0].put_raw_object(content, type, callback);
+ if(!this.loose) initloose(this);
+ this.loose[0].put_raw_object(content, type, callback);
}
View
5 package.json
@@ -10,7 +10,10 @@
, "main": "./lib/git/index"
, "directories" : { "lib" : "./lib/git" }
, "engines" : { "node" : ">=0.4.0" }
-, "dependencies": { "mime": "1.2.9" }
+, "dependencies": {
+ "mime": "1.2.9",
+ "async": "0.2.9"
+}
, "devDependencies":{ "nodeunit" : ">=0.5.1" }
, "licenses" : [ { "type" : "Apache License, Version 2.0"
, "url" : "http://www.apache.org/licenses/LICENSE-2.0" } ]
Please sign in to comment.
Something went wrong with that request. Please try again.