Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Guillaume Royer
jio
Commits
c1a40dc3
Commit
c1a40dc3
authored
Jan 28, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revisionstorage.js improved to update branches with revision history objects
parent
c3aae0e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
src/jio.storage/revisionstorage.js
src/jio.storage/revisionstorage.js
+36
-2
test/jiotests.js
test/jiotests.js
+2
-1
No files found.
src/jio.storage/revisionstorage.js
View file @
c1a40dc3
...
...
@@ -25,6 +25,20 @@ jIO.addStorageType('revision', function (spec, my) {
return
o
;
};
/**
* Clones an object in deep (without functions)
* @method clone
* @param {any} object The object to clone
* @return {any} The cloned object
*/
priv
.
clone
=
function
(
object
)
{
var
tmp
=
JSON
.
stringify
(
object
);
if
(
tmp
===
undefined
)
{
return
undefined
;
}
return
JSON
.
parse
(
tmp
);
};
/**
* Generate a new uuid
* @method generateUuid
...
...
@@ -69,6 +83,20 @@ jIO.addStorageType('revision', function (spec, my) {
return
revision
;
};
/**
* Convert the revision history object to an array of revisions.
* @method revisionHistoryToArray
* @param {object} revs The revision history
* @return {array} The revision array
*/
priv
.
revisionHistoryToArray
=
function
(
revs
)
{
var
i
,
start
=
revs
.
start
,
newlist
=
[];
for
(
i
=
0
;
i
<
revs
.
ids
.
length
;
i
+=
1
,
start
-=
1
)
{
newlist
.
push
(
start
+
"
-
"
+
revs
.
ids
[
i
]);
}
return
newlist
;
};
/**
* Generates the next revision of [previous_revision]. [string] helps us
* to generate a hash code.
...
...
@@ -214,14 +242,20 @@ jIO.addStorageType('revision', function (spec, my) {
* Add a document revision branch to the document tree
* @method updateDocumentTree
* @param {object} doctree The document tree object
* @param {
array} revs The revisions
array
* @param {
object|array} revs The revision history object or a revision
array
* @param {boolean} deleted The deleted flag
* @param {array} The document revs_info
*/
priv
.
updateDocumentTree
=
function
(
doctree
,
revs
,
deleted
)
{
var
revs_info
,
doctree_iterator
,
flag
;
revs_info
=
[];
revs
=
JSON
.
parse
(
JSON
.
stringify
(
revs
));
if
(
revs
.
ids
)
{
// revs is a revision history object
revs
=
priv
.
revisionHistoryToArray
(
revs
);
}
else
{
// revs is an array of revisions
revs
=
priv
.
clone
(
revs
);
}
doctree_iterator
=
doctree
;
while
(
revs
.
length
>
0
)
{
var
i
,
rev
=
revs
.
pop
(
0
);
...
...
test/jiotests.js
View file @
c1a40dc3
...
...
@@ -1361,7 +1361,8 @@ test ("Put", function(){
// put + revision history
o
.
doc
=
{
"
_id
"
:
"
put1
"
,
"
_revs
"
:
[
"
3-rh3
"
,
"
2-rh2
"
,
"
1-rh1
"
],
//"_revs": ["3-rh3", "2-rh2", "1-rh1"], // same as below
"
_revs
"
:
{
"
start
"
:
3
,
"
ids
"
:
[
"
rh3
"
,
"
rh2
"
,
"
rh1
"
]},
"
title
"
:
"
myPut3
"
};
o
.
spy
(
o
,
"
value
"
,
{
"
id
"
:
"
put1
"
,
"
ok
"
:
true
,
"
rev
"
:
"
3-rh3
"
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment