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
Boris Kocherov
jio
Commits
c8386265
Commit
c8386265
authored
Dec 21, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some method added or modified on storage.js
parent
90df066a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
2 deletions
+66
-2
src/jio/storages/storage.js
src/jio/storages/storage.js
+66
-2
No files found.
src/jio/storages/storage.js
View file @
c8386265
...
...
@@ -46,6 +46,20 @@ var storage = function(spec, my) {
return
hex_sha256
(
string
);
};
/**
* Returns an array version of a revision string
* @method revisionToArray
* @param {string} revision The revision string
* @return {array} Array containing a revision number and a hash
*/
that
.
revisionToArray
=
function
(
revision
)
{
if
(
typeof
revision
===
"
string
"
)
{
return
[
parseInt
(
revision
.
split
(
'
-
'
)[
0
],
10
),
revision
.
split
(
'
-
'
)[
1
]]
}
return
revision
;
};
/**
* Generates the next revision of [previous_revision]. [string] helps us
* to generate a hash code.
...
...
@@ -55,8 +69,21 @@ var storage = function(spec, my) {
* @return {array} 0:The next revision number and 1:the hash code
*/
that
.
generateNextRevision
=
function
(
previous_revision
,
string
)
{
return
[
parseInt
(
previous_revision
.
split
(
'
-
'
)[
0
],
10
)
+
1
,
utilities
.
hashCode
(
previous_revision
+
string
)];
if
(
typeof
previous_revision
===
"
number
"
)
{
return
[
previous_revision
+
1
,
that
.
hashCode
(
string
)];
}
previous_revision
=
that
.
revisionToArray
(
previous_revision
);
return
[
previous_revision
[
0
]
+
1
,
that
.
hashCode
(
string
)];
};
/**
* Checks a revision format
* @method checkRevisionFormat
* @param {string} revision The revision string
* @return {boolean} True if ok, else false
*/
that
.
checkRevisionFormat
=
function
(
revision
)
{
return
/^
[
0-9
]
+-
[
0-9a-zA-Z
]
+$/
.
test
(
revision
);
};
/**
...
...
@@ -158,6 +185,43 @@ var storage = function(spec, my) {
return
result
;
};
that
.
createDocument
=
function
(
doc
,
id
,
prev_rev
)
{
var
hash
,
rev
;
if
(
typeof
prev_rev
===
"
undefined
"
)
{
hash
=
that
.
hashCode
(
doc
);
doc
.
_rev
=
"
1-
"
+
hash
;
doc
.
_id
=
id
;
doc
.
_revisions
=
{
"
start
"
:
1
,
"
ids
"
:
[
hash
]
};
doc
.
_revs_info
=
[{
"
rev
"
:
"
1-
"
+
hash
,
"
status
"
:
"
available
"
}];
return
doc
;
}
else
{
// xxx do not hash _key of doc!
prev_rev
=
that
.
revisionToArray
(
prev_rev
);
rev
=
that
.
generateNextRevision
(
prev_rev
,
doc
);
doc
.
_rev
=
rev
.
join
(
'
-
'
);
doc
.
_id
=
id
;
doc
.
_revisions
=
{
"
start
"
:
rev
[
0
],
"
ids
"
:
[
rev
[
1
],
prev_rev
[
1
]]
};
doc
.
_revs_info
=
[{
"
rev
"
:
rev
.
join
(
'
-
'
),
"
status
"
:
"
available
"
},{
"
rev
"
:
prev_rev
.
join
(
'
-
'
),
"
status
"
:
"
missing
"
}];
return
doc
;
}
};
/**
* Execute the command on this storage.
* @method execute
...
...
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