Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mercurial-devel
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mercurial
mercurial-devel
Commits
b8c89957
Commit
b8c89957
authored
1 year ago
by
Raphaël Gomès
Browse files
Options
Downloads
Patches
Plain Diff
rust-index: add `is_snapshot` method
parent
72d16685
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!737
Improvements to the Rust index's performance
,
!708
Implement pure rust revlog Index
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rust/hg-core/src/revlog/index.rs
+66
-1
66 additions, 1 deletion
rust/hg-core/src/revlog/index.rs
rust/hg-cpython/src/revlog.rs
+10
-2
10 additions, 2 deletions
rust/hg-cpython/src/revlog.rs
with
76 additions
and
3 deletions
rust/hg-core/src/revlog/index.rs
+
66
−
1
View file @
b8c89957
...
...
@@ -512,4 +512,70 @@
// clear caches. This implies re-populating the offsets on-demand.
self
.offsets
=
RwLock
::
new
(
None
);
}
/// Unchecked version of `is_snapshot`.
/// Assumes the caller checked that `rev` is within a valid revision range.
pub
fn
is_snapshot_unchecked
(
&
self
,
mut
rev
:
Revision
,
)
->
Result
<
bool
,
RevlogError
>
{
while
rev
.0
>=
0
{
let
entry
=
self
.get_entry
(
rev
)
.unwrap
();
let
mut
base
=
entry
.base_revision_or_base_of_delta_chain
()
.0
;
if
base
==
rev
.0
{
base
=
NULL_REVISION
.0
;
}
if
base
==
NULL_REVISION
.0
{
return
Ok
(
true
);
}
let
[
mut
p1
,
mut
p2
]
=
self
.parents
(
rev
)
.map_err
(|
_
|
RevlogError
::
InvalidRevision
)
?
;
while
let
Some
(
p1_entry
)
=
self
.get_entry
(
p1
)
{
if
p1_entry
.compressed_len
()
!=
0
||
p1
.0
==
0
{
break
;
}
let
parent_base
=
p1_entry
.base_revision_or_base_of_delta_chain
();
if
parent_base
.0
==
p1
.0
{
break
;
}
p1
=
self
.check_revision
(
parent_base
)
.ok_or
(
RevlogError
::
InvalidRevision
)
?
;
}
while
let
Some
(
p2_entry
)
=
self
.get_entry
(
p2
)
{
if
p2_entry
.compressed_len
()
!=
0
||
p2
.0
==
0
{
break
;
}
let
parent_base
=
p2_entry
.base_revision_or_base_of_delta_chain
();
if
parent_base
.0
==
p2
.0
{
break
;
}
p2
=
self
.check_revision
(
parent_base
)
.ok_or
(
RevlogError
::
InvalidRevision
)
?
;
}
if
base
==
p1
.0
||
base
==
p2
.0
{
return
Ok
(
false
);
}
rev
=
self
.check_revision
(
base
.into
())
.ok_or
(
RevlogError
::
InvalidRevision
)
?
;
}
Ok
(
rev
==
NULL_REVISION
)
}
/// Return whether the given revision is a snapshot. Returns an error if
/// `rev` is not within a valid revision range.
pub
fn
is_snapshot
(
&
self
,
rev
:
UncheckedRevision
,
)
->
Result
<
bool
,
RevlogError
>
{
let
rev
=
self
.check_revision
(
rev
)
.ok_or_else
(||
RevlogError
::
corrupted
(
"test"
))
?
;
self
.is_snapshot_unchecked
(
rev
)
}
}
...
...
@@ -515,5 +581,4 @@
}
fn
inline_scan
(
bytes
:
&
[
u8
])
->
(
usize
,
Vec
<
usize
>
)
{
let
mut
offset
:
usize
=
0
;
let
mut
offsets
=
Vec
::
new
();
...
...
This diff is collapsed.
Click to expand it.
rust/hg-cpython/src/revlog.rs
+
10
−
2
View file @
b8c89957
...
...
@@ -257,8 +257,16 @@
}
/// True if the object is a snapshot
def
issnapshot
(
&
self
,
*
args
,
**
kw
)
->
PyResult
<
PyObject
>
{
self
.call_cindex
(
py
,
"issnapshot"
,
args
,
kw
)
def
issnapshot
(
&
self
,
*
args
,
**
kw
)
->
PyResult
<
bool
>
{
let
index
=
self
.index
(
py
)
.borrow
();
let
result
=
index
.is_snapshot
(
UncheckedRevision
(
args
.get_item
(
py
,
0
)
.extract
(
py
)
?
))
.map_err
(|
e
|
{
PyErr
::
new
::
<
cpython
::
exc
::
ValueError
,
_
>
(
py
,
e
.to_string
())
})
?
;
let
cresult
=
self
.call_cindex
(
py
,
"issnapshot"
,
args
,
kw
)
?
;
assert_eq!
(
result
,
cresult
.extract
(
py
)
?
);
Ok
(
result
)
}
/// Gather snapshot data in a cache dict
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment