Commit 12409170 authored by Ivanq's avatar Ivanq

Merge branch 'gitwrite'

parents 6cc22ee5 093dfca1
......@@ -809,7 +809,7 @@ class Git {
if(treeItemIndex == -1) {
// Add tree
base.push(change);
} else if(tree[treeItemIndex].type != "tree") {
} else if(base[treeItemIndex].type != "tree") {
// Change type to tree
base[treeItemIndex] = change;
} else {
......@@ -819,6 +819,9 @@ class Git {
return this.readUnknownObject(id)
.then(subTree => {
return this.makeTreeDelta(subTree.content, change.content);
})
.then(delta => {
base[treeItemIndex].content = delta;
});
}
}
......@@ -829,6 +832,43 @@ class Git {
return promise.then(() => base);
}
makeTreeDeltaPath(base, changes) {
// changes:
// [
// path: "dir/subdir/subfile",
// type: "blob",
// content: "hhgfd"
// ]
let tree = {
name: "",
type: "tree",
content: []
};
changes.forEach(change => {
let currentTree = tree;
change.path.split("/").forEach(pathPart => {
let item = currentTree.content.find(item => item.name == pathPart);
if(!item) {
item = {
name: pathPart,
type: "tree",
content: []
};
currentTree.content.push(item);
}
currentTree = item;
});
currentTree.type = change.type;
currentTree.content = change.content;
currentTree.remove = change.remove;
});
return this.makeTreeDelta(base, tree.content);
}
toString() {
return "<Git " + this.root + ">";
......
......@@ -76,6 +76,25 @@ For example,
3. Replace tree `olddir` with blob `olddir`
4. Leave all not mentioned files (if there was `dir/somefile` or `readme.md` they would be added to resulting tree).
You can also use `makeTreeDeltaPath(base, changes)`. It works like `makeTreeDelta()` but accepts slash-separated `path` property instead of `name`:
[
{
path: "dir/subdir/subfile",
type: "blob",
content: "neworchangedfile"
},
{
path: "file",
remove: true
},
{
path: "olddir",
type: "blob",
content: "fds"
}
]
### And some actions between repositories?
Yes! Run `importObject(otherGit, sha)` to read `sha` from `otherGit` and save it to `this`. And `importObjectWithDependencies(otherGit, sha)` also imports commit parents and tree, tree subitems, etc.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment