Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
Cédric Le Ninivin
jio
Commits
32ee4fb8
Commit
32ee4fb8
authored
Dec 26, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revisionstorage.js private methods improved or added
parent
f0fb37f9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
11 deletions
+47
-11
src/jio.storage/revisionstorage.js
src/jio.storage/revisionstorage.js
+47
-11
No files found.
src/jio.storage/revisionstorage.js
View file @
32ee4fb8
...
@@ -92,7 +92,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -92,7 +92,7 @@ jIO.addStorageType('revision', function (spec, my) {
* @return {boolean} True if ok, else false
* @return {boolean} True if ok, else false
*/
*/
priv
.
checkRevisionFormat
=
function
(
revision
)
{
priv
.
checkRevisionFormat
=
function
(
revision
)
{
return
/^
[
0-9
]
+-
[
0-9a-zA-Z
]
+$/
.
test
(
revision
);
return
(
/^
[
0-9
]
+-
[
0-9a-zA-Z
]
+$/
.
test
(
revision
)
);
};
};
/**
/**
...
@@ -122,19 +122,36 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -122,19 +122,36 @@ jIO.addStorageType('revision', function (spec, my) {
* The winner is the deeper revision on the left.
* The winner is the deeper revision on the left.
* @method getWinnerRevisionFromDocumentTree
* @method getWinnerRevisionFromDocumentTree
* @param {object} document_tree The document tree
* @param {object} document_tree The document tree
* @return {string} The winner revision
* @return {array} The winner revs info array
*/
/**
* Gets the winner revision from a document tree.
* The winner is the deeper revision on the left.
* @method getWinnerRevisionFromDocumentTree
* @param {object} document_tree The document tree
* @return {array} The winner revs info array
*/
*/
priv
.
getWinnerRevisionFromDocumentTree
=
function
(
document_tree
)
{
priv
.
getWinnerRevisionFromDocumentTree
=
function
(
document_tree
)
{
var
i
,
result
,
search
;
var
i
,
result
,
search
,
revs_info
=
[]
;
result
=
{
"
deep
"
:
-
1
,
"
revision
"
:
''
}
;
result
=
[]
;
// search method fills "result" with the winner rev
ision
// search method fills "result" with the winner rev
s info
search
=
function
(
document_tree
,
deep
)
{
search
=
function
(
document_tree
,
deep
)
{
var
i
;
var
i
;
if
(
typeof
document_tree
.
rev
!==
"
undefined
"
)
{
// node is not root
revs_info
.
unshift
({
"
rev
"
:
document_tree
.
rev
,
"
status
"
:
document_tree
.
status
});
}
if
(
document_tree
.
children
.
length
===
0
)
{
if
(
document_tree
.
children
.
length
===
0
)
{
// This node is a leaf
// This node is a leaf
if
(
result
.
deep
<
deep
)
{
if
(
result
.
length
<
deep
)
{
// The leaf is deeper than result
// The leaf is deeper than result
result
=
{
"
deep
"
:
deep
,
"
revision
"
:
document_tree
.
rev
};
result
=
[];
for
(
i
=
0
;
i
<
revs_info
.
length
;
i
+=
1
)
{
result
.
push
(
revs_info
[
i
]);
}
}
}
return
;
return
;
}
}
...
@@ -142,10 +159,11 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -142,10 +159,11 @@ jIO.addStorageType('revision', function (spec, my) {
for
(
i
=
0
;
i
<
document_tree
.
children
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
document_tree
.
children
.
length
;
i
+=
1
)
{
// searching deeper to find the deeper leaf
// searching deeper to find the deeper leaf
search
(
document_tree
.
children
[
i
],
deep
+
1
);
search
(
document_tree
.
children
[
i
],
deep
+
1
);
revs_info
.
shift
();
}
}
};
};
search
(
document_tree
,
0
);
search
(
document_tree
,
0
);
return
result
.
rev
;
return
result
;
};
};
/**
/**
...
@@ -197,9 +215,7 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -197,9 +215,7 @@ jIO.addStorageType('revision', function (spec, my) {
doc
.
_rev
||
0
,
JSON
.
stringify
(
doc
)
+
JSON
.
stringify
(
revs_info
));
doc
.
_rev
||
0
,
JSON
.
stringify
(
doc
)
+
JSON
.
stringify
(
revs_info
));
next_rev_str
=
next_rev
.
join
(
"
-
"
);
next_rev_str
=
next_rev
.
join
(
"
-
"
);
// don't add if the next rev already exists
// don't add if the next rev already exists
console
.
log
(
JSON
.
stringify
(
revs_info
));
for
(
i
=
0
;
i
<
selected_node
.
children
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
selected_node
.
children
.
length
;
i
+=
1
)
{
console
.
log
(
selected_node
.
children
[
i
].
rev
);
if
(
selected_node
.
children
[
i
].
rev
===
next_rev_str
)
{
if
(
selected_node
.
children
[
i
].
rev
===
next_rev_str
)
{
revs_info
.
unshift
({
revs_info
.
unshift
({
"
rev
"
:
next_rev_str
,
"
rev
"
:
next_rev_str
,
...
@@ -227,9 +243,10 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -227,9 +243,10 @@ jIO.addStorageType('revision', function (spec, my) {
* Gets an array of leaves revisions from document tree
* Gets an array of leaves revisions from document tree
* @method getLeavesFromDocumentTree
* @method getLeavesFromDocumentTree
* @param {object} document_tree The document tree
* @param {object} document_tree The document tree
* @param {string} except The revision to except
* @return {array} The array of leaves revisions
* @return {array} The array of leaves revisions
*/
*/
priv
.
getLeavesFromDocumentTree
=
function
(
document_tree
)
{
priv
.
getLeavesFromDocumentTree
=
function
(
document_tree
,
except
)
{
var
i
,
result
,
search
;
var
i
,
result
,
search
;
result
=
[];
result
=
[];
// search method fills [result] with the winner revision
// search method fills [result] with the winner revision
...
@@ -237,6 +254,9 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -237,6 +254,9 @@ jIO.addStorageType('revision', function (spec, my) {
var
i
;
var
i
;
if
(
document_tree
.
children
.
length
===
0
)
{
if
(
document_tree
.
children
.
length
===
0
)
{
// This node is a leaf
// This node is a leaf
if
(
except
!==
undefined
&&
except
===
document_tree
.
rev
)
{
return
;
}
result
.
push
(
document_tree
.
rev
);
result
.
push
(
document_tree
.
rev
);
return
;
return
;
}
}
...
@@ -250,6 +270,22 @@ jIO.addStorageType('revision', function (spec, my) {
...
@@ -250,6 +270,22 @@ jIO.addStorageType('revision', function (spec, my) {
return
result
;
return
result
;
};
};
/**
* Convert revs_info to a simple revisions history
* @method revsInfoToHistory
* @param {array} revs_info The revs info
* @return {object} The revisions history
*/
priv
.
revsInfoToHistory
=
function
(
revs_info
)
{
var
revisions
=
{
"
start
"
:
0
,
"
ids
"
:[]},
i
;
if
(
revs_info
.
length
>
0
)
{
revisions
.
start
=
revs_info
[
0
].
rev
.
split
(
'
-
'
)[
0
];
}
for
(
i
=
0
;
i
<
revs_info
.
length
;
i
+=
1
)
{
revisions
.
ids
.
push
(
revs_info
[
i
].
rev
.
split
(
'
-
'
)[
1
]);
}
return
revisions
;
};
/**
/**
* Post the document metadata and create or update a document tree.
* Post the document metadata and create or update a document tree.
...
...
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