Skip to content
This repository has been archived by the owner on Apr 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #888 from dart-lang/fix_push
Browse files Browse the repository at this point in the history
Refactor PackObject, LooseObject
  • Loading branch information
gaurave committed Jan 28, 2014
2 parents b6c901a + f7c9a22 commit b8c152c
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 156 deletions.
2 changes: 1 addition & 1 deletion ide/app/lib/git/commands/checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Checkout {
return Conditions.checkForUncommittedChanges(root, store).then(
(GitConfig config) {
return _cleanWorkingDir(root).then((_) {
return store.retrieveObject(branchSha, ObjectTypes.COMMIT).then(
return store.retrieveObject(branchSha, ObjectTypes.COMMIT_STR).then(
(CommitObject commit) {
return ObjectUtils.expandTree(root, store, commit.treeSha)
.then((_) {
Expand Down
2 changes: 1 addition & 1 deletion ide/app/lib/git/commands/clone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Clone {

Future _createCurrentTreeFromPack(chrome.DirectoryEntry dir, ObjectStore store,
String headSha) {
return store.retrieveObject(headSha, ObjectTypes.COMMIT).then((commit) {
return store.retrieveObject(headSha, ObjectTypes.COMMIT_STR).then((commit) {
return ObjectUtils.expandTree(dir, store, commit.treeSha);
});
}
Expand Down
32 changes: 8 additions & 24 deletions ide/app/lib/git/commands/commit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Commit {
if (parent.isEmpty) {
return null;
} else {
return store.retrieveObject(parent, ObjectTypes.COMMIT).then(
return store.retrieveObject(parent, ObjectTypes.COMMIT_STR).then(
(CommitObject parentCommit) {
String oldTree = parentCommit.treeSha;
if (oldTree == sha) {
Expand Down Expand Up @@ -123,21 +123,10 @@ class Commit {
String refName) {
chrome.DirectoryEntry dir = options.root;
ObjectStore store = options.store;
String name = options.name;
String email = options.email;
String commitMsg = options.commitMessage;

if (name == null) {
name = "";
}

if (email == null) {
email = "";
}

if (commitMsg == null) {
commitMsg = "";
}
String name = options.name == null ? "" : options.name;
String email = options.email == null ? "" : options.email;
String commitMsg = options.commitMessage == null ? ""
: options.commitMessage;

return walkFiles(dir, store).then((String sha) {
return checkTreeChanged(store, parent, sha).then((_) {
Expand All @@ -158,17 +147,12 @@ class Commit {
}
}

commitContent.write('author ${name}');
commitContent.write(' <${email}> ');
commitContent.write(dateString);
commitContent.write('\n');
commitContent.write('committer ${name}');
commitContent.write(' <${email}> ');
commitContent.write(dateString);
commitContent.write('author ${name} <${email}> ${dateString}\n');
commitContent.write('committer ${name} <${email}> ${dateString}');
commitContent.write('\n\n${commitMsg}\n');

return store.writeRawObject(
ObjectTypes.COMMIT, commitContent.toString()).then(
ObjectTypes.COMMIT_STR, commitContent.toString()).then(
(String commitSha) {
return FileOps.createFileWithContent(dir, '.git/${refName}',
commitSha + '\n', 'Text').then((_) {
Expand Down
2 changes: 1 addition & 1 deletion ide/app/lib/git/commands/merge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Merge {
}
});
} else {
return store.retrieveObjectList(shas, ObjectTypes.TREE).then(
return store.retrieveObjectList(shas, ObjectTypes.TREE_STR).then(
(List<TreeObject> trees) {
return mergeTrees(store, trees[0], trees[1], trees[2]).then(
(String mergedSha) {
Expand Down
2 changes: 1 addition & 1 deletion ide/app/lib/git/commands/pull.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Pull {
shaBytesToString(mergeEntry['new'].sha));
} else {
return store.retrieveObjectList([mergeEntry['old'].sha,
mergeEntry['new'].sha], ObjectTypes.TREE).then(
mergeEntry['new'].sha], ObjectTypes.TREE_STR).then(
(List<TreeObject> trees) {
TreeDiffResult treeDiff2 = Merge.diffTree(trees[0], trees[1]);
return dir.createDirectory(mergeEntry['new'].name).then(
Expand Down
47 changes: 22 additions & 25 deletions ide/app/lib/git/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ abstract class GitObject {
static GitObject make(String sha, String type, content,
[LooseObject rawObj]) {
switch (type) {
case ObjectTypes.BLOB:
case ObjectTypes.BLOB_STR:
return new BlobObject(sha, content);
case ObjectTypes.TREE:
case ObjectTypes.TREE_STR:
case "Tree":
return new TreeObject(sha, content, rawObj);
case ObjectTypes.COMMIT:
case ObjectTypes.COMMIT_STR:
return new CommitObject(sha, content, rawObj);
case ObjectTypes.TAG:
case ObjectTypes.TAG_STR:
return new TagObject(sha, content);
default:
throw new ArgumentError("Unsupported git object type: ${type}");
Expand All @@ -43,7 +43,7 @@ abstract class GitObject {
GitObject([this._sha, this.data]);

// The type of git object.
String _type;
String type;
dynamic data;
String _sha;

Expand All @@ -62,8 +62,6 @@ class TreeEntry {
TreeEntry(this.name, this.sha, this.isBlob);
}



/**
* Error thrown for a parse failure.
*/
Expand Down Expand Up @@ -91,7 +89,7 @@ class TreeObject extends GitObject {

TreeObject( [String sha, Uint8List data, LooseObject rawObj])
: super(sha, data) {
this._type = ObjectTypes.TREE;
this.type = ObjectTypes.TREE_STR;
this.rawObj = rawObj;
_parse();
}
Expand Down Expand Up @@ -134,7 +132,7 @@ class TreeObject extends GitObject {
class BlobObject extends GitObject {

BlobObject(String sha, String data) : super(sha, data) {
this._type = ObjectTypes.BLOB;
this.type = ObjectTypes.BLOB_STR;
}
}

Expand Down Expand Up @@ -165,7 +163,7 @@ class CommitObject extends GitObject {
LooseObject rawObj;

CommitObject(String sha, var data, [rawObj]) {
this._type = ObjectTypes.COMMIT;
this.type = ObjectTypes.COMMIT_STR;
this._sha = sha;
this.rawObj = rawObj;

Expand All @@ -177,7 +175,6 @@ class CommitObject extends GitObject {
// TODO: Clarify this exception.
throw "Data is in incompatible format.";
}

_parseData();
}

Expand Down Expand Up @@ -251,26 +248,15 @@ class CommitObject extends GitObject {
*/
class TagObject extends GitObject {
TagObject(String sha, String data) : super(sha, data) {
this._type = ObjectTypes.TAG;
this.type = ObjectTypes.TAG_STR;
}
}

/**
* A loose git object.
*/
class LooseObject {
class LooseObject extends GitObject {
int size;
int type;

static Map<String, int> _typeMap = {
ObjectTypes.COMMIT : 1,
ObjectTypes.TREE : 2,
ObjectTypes.BLOB : 3
};

// Represents either an ArrayBuffer or a string representation of byte
//stream.
dynamic data;

LooseObject(buf) {
_parse(buf);
Expand Down Expand Up @@ -299,7 +285,18 @@ class LooseObject {
this.data = buf.substring(i + 1, buf.length);
}
List<String> parts = header.split(' ');
this.type = _typeMap[parts[0]];
this.type = parts[0];
this.size = int.parse(parts[1]);
}
}

/**
* Encapsulates a git pack object.
*/
class PackedObject extends GitObject {
List<int> sha;
String baseSha;
int crc;
int offset;
int desiredOffset;
}
66 changes: 58 additions & 8 deletions ide/app/lib/git/object_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,58 @@ import 'utils.dart';
*
*/
abstract class ObjectTypes {
static const String BLOB = "blob";
static const String TREE = "tree";
static const String COMMIT = "commit";
static const String TAG = "tag";

static const String BLOB_STR = "blob";
static const String TREE_STR = "tree";
static const String COMMIT_STR = "commit";
static const String TAG_STR = "tag";
static const String OFS_DELTA_STR = "ofs_delta";
static const String REF_DELTA_STR = "ref_delta";

static const int COMMIT = 1;
static const int TREE = 2;
static const int BLOB = 3;
static const int TAG = 4;
static const int OFS_DELTA = 6;
static const int REF_DELTA = 7;

static String getTypeString(int type) {
switch(type) {
case COMMIT:
return COMMIT_STR;
case TREE:
return TREE_STR;
case BLOB:
return BLOB_STR;
case TAG:
return TAG_STR;
case OFS_DELTA:
return OFS_DELTA_STR;
case REF_DELTA:
return REF_DELTA_STR;
default:
throw "unsupported pack type ${type}.";
}
}

static int getType(String type) {
switch(type) {
case COMMIT_STR:
return COMMIT;
case TREE_STR:
return TREE;
case BLOB_STR:
return BLOB;
case TAG_STR:
return TAG;
case OFS_DELTA_STR:
return OFS_DELTA;
case REF_DELTA_STR:
return REF_DELTA;
default:
throw "unsupported pack type ${type}.";
}
}
}

/**
Expand All @@ -32,10 +80,12 @@ abstract class ObjectUtils {
/**
* Expands a git blob object into a file and writes on disc.
*/
static Future<chrome.Entry> expandBlob(chrome.DirectoryEntry dir, ObjectStore store,
String fileName, String blobSha) {
return store.retrieveObject(blobSha, ObjectTypes.BLOB).then((BlobObject blob) {
return FileOps.createFileWithContent(dir, fileName, blob.data, ObjectTypes.BLOB);
static Future<chrome.Entry> expandBlob(chrome.DirectoryEntry dir,
ObjectStore store, String fileName, String blobSha) {
return store.retrieveObject(blobSha, ObjectTypes.BLOB_STR).then(
(BlobObject blob) {
return FileOps.createFileWithContent(dir, fileName, blob.data,
ObjectTypes.BLOB_STR);
});
}

Expand Down
Loading

0 comments on commit b8c152c

Please sign in to comment.