Permalink
Browse files

[test] make unpack tests pass again

  • Loading branch information...
1 parent 8a8f415 commit 7071c27ea1c806487e9994150522c22b46f3d914 @tmpvar tmpvar committed Nov 7, 2012
Showing with 22 additions and 21 deletions.
  1. +2 −1 git.js
  2. +17 −17 lib/data-utils.js
  3. +3 −3 lib/pack/unpack.js
View
@@ -36,10 +36,11 @@ Git.prototype.end = function(data) {
};
Git.prototype.remote = require('./lib/remote');
-
+/*
Git.prototype.Diff = require('./lib/diff');
Git.prototype.push = require('./lib/push');
Git.prototype.pull = require('./lib/pull');
Git.prototype.add = require('./lib/add');
Git.prototype.commit = require('./lib/commit');
+*/
View
@@ -3,7 +3,7 @@
// data utilities
//
-var utils = exports = {};
+module.exports = utils = {};
utils.applyDelta = (function() {
@@ -15,7 +15,7 @@ utils.applyDelta = (function() {
var currentShift = 0
var _byte = 128
var maskedByte, shiftedByte
-
+
while ((_byte & 128) != 0) {
_byte = data[offset]
offset += 1
@@ -27,21 +27,21 @@ utils.applyDelta = (function() {
stream.offset = offset
return result
}
-
+
return function(baseDataString, delta) {
var baseData = this.stringToBytes(baseDataString)
var stream = {data: delta, offset: 0, length: delta.length}
-
+
var baseLength = matchLength(stream)
if (baseLength != baseData.length) {
throw (Error("Delta Error: base length not equal to length of given base data"))
}
-
+
var resultLength = matchLength(stream)
var resultData = ""
-
+
var copyOffset
var copyLength
var opcode
@@ -80,20 +80,20 @@ utils.applyDelta = (function() {
if (copyLength == 0) {
copyLength = (1<<16)
}
-
+
//
// TODO: check if this is a version 2 packfile and apply copyFromResult if so
//
copyFromResult = (opcode & 0x01);
resultData += this.bytesToString(baseData.slice(copyOffset, copyOffset + copyLength));
-
- }
+
+ }
else if ((opcode & 0x80) == 0) {
resultData += this.bytesToString(stream.data.slice(stream.offset, stream.offset + opcode));
stream.offset += opcode;
}
}
-
+
if (resultLength != resultData.length) {
throw (Error("Delta Error: got result length " + resultData.length + ", expected " + resultLength))
}
@@ -113,14 +113,14 @@ utils.bytesToString = function(bytes) {
}
return result;
};
-
+
//
//
//
utils.stringToBytes = function(string) {
- var bytes = [];
- var i;
+ var bytes = [];
+ var i;
for(i = 0; i < string.length; i++) {
bytes.push(string.charCodeAt(i) & 0xff);
}
@@ -131,24 +131,24 @@ utils.stringToBytes = function(string) {
//
//
utils.toBinaryString = function(binary) {
-
+
if (Array.isArray(binary)) {
return utils.bytesToString(binary)
}
else {
return binary
}
};
-
+
//
// returns the next pkt-line
//
utils.nextPktLine = function(data) {
-
+
var length = parseInt(data.substring(0, 4), 16);
return data.substring(4, length);
};
-
+
//
// zlib files contain a two byte header. (RFC 1950)
//
View
@@ -5,7 +5,7 @@
var Buffer = require('buffer').Buffer,
getType = require('../../common/pack').getType,
rawInflate = require('../../common/rawinflate'),
- git = new (require('../../git'))(),
+ utils = require('../data-utils'),
objects = require('../objects');
// TODO: I really want to use this, but there is no way to get the
@@ -81,13 +81,13 @@ module.exports = function unpack(buffer, fn, make) {
fwd(20);
}
- var inflated = rawInflate(git.bytesToString(buffer.slice(fwd(2))));
+ var inflated = rawInflate(utils.bytesToString(buffer.slice(fwd(2))));
// TODO: WARNING!! the compressed length returned by this function is incorrect
fwd(inflated.compressedLength + 4);
// TODO: sha
- obj.objects.push(make(type, new Buffer(git.stringToBytes(inflated.toString()))));
+ obj.objects.push(make(type, new Buffer(utils.stringToBytes(inflated.toString()))));
process.nextTick(function() {
objectIndex++;

0 comments on commit 7071c27

Please sign in to comment.