Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
mercurial
hg-git
Commits
44b9bfdcfe8f
Commit
44b9bfdc
authored
Oct 28, 2022
by
Dan Villiom Podlaski Christiansen
Browse files
incoming: use a memory-based pack
parent
a27c495c6dd0
Pipeline
#57751
passed with stages
in 23 minutes and 3 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
hggit/git_handler.py
View file @
44b9bfdc
...
...
@@ -8,4 +8,5 @@
import
tempfile
from
dulwich.errors
import
HangupException
,
GitProtocolError
,
ApplyDeltaError
from
dulwich.object_store
import
MemoryObjectStore
,
OverlayObjectStore
from
dulwich.objects
import
Blob
,
Commit
,
Tag
,
Tree
,
parse_timezone
...
...
@@ -11,5 +12,5 @@
from
dulwich.objects
import
Blob
,
Commit
,
Tag
,
Tree
,
parse_timezone
from
dulwich.pack
import
create_delta
,
apply_delta
from
dulwich.pack
import
PackData
,
PackInflater
,
create_delta
,
apply_delta
from
dulwich.refs
import
(
ANNOTATED_TAG_SUFFIX
,
LOCAL_BRANCH_PREFIX
,
...
...
@@ -608,7 +609,12 @@
# incoming support
def
getremotechanges
(
self
,
remote
,
revs
):
result
=
self
.
fetch_pack
(
remote
.
path
,
revs
)
memory_store
=
MemoryObjectStore
()
overlay_store
=
OverlayObjectStore
(
[
self
.
git
.
object_store
,
memory_store
],
memory_store
,
)
result
=
self
.
fetch_pack
(
remote
.
path
,
revs
,
overlay_store
)
# refs contains all remote refs. Prune to only those requested.
if
revs
:
...
...
@@ -623,7 +629,9 @@
commits
=
[
c
.
node
for
c
in
self
.
get_git_incoming
(
reqrefs
,
self
.
remote_names
(
remote
.
path
,
push
=
False
)
reqrefs
,
self
.
remote_names
(
remote
.
path
,
push
=
False
),
store
=
overlay_store
,
)
]
...
...
@@ -627,7 +635,7 @@
)
]
b
=
overlayrepo
(
self
,
commits
,
result
.
refs
)
b
=
overlayrepo
(
self
,
overlay_store
,
commits
,
result
.
refs
)
return
(
b
,
commits
,
lambda
:
None
)
...
...
@@ -1003,6 +1011,6 @@
return
message
,
git_extra
def
get_git_incoming
(
self
,
refs
,
remote_names
):
def
get_git_incoming
(
self
,
refs
,
remote_names
,
store
=
None
):
return
git2hg
.
find_incoming
(
self
.
ui
,
...
...
@@ -1007,6 +1015,6 @@
return
git2hg
.
find_incoming
(
self
.
ui
,
self
.
git
.
object_store
,
store
or
self
.
git
.
object_store
,
self
.
_map_git
,
refs
,
remote_names
,
...
...
@@ -1559,7 +1567,7 @@
return
new_refs
def
fetch_pack
(
self
,
remote
,
heads
=
None
):
def
fetch_pack
(
self
,
remote
,
heads
=
None
,
object_store
=
None
):
# The dulwich default walk only checks refs/heads/. We also want to
# consider remotes when doing discovery, so we build our own list. We
# can't just do 'refs/' here because the tag class doesn't have a
...
...
@@ -1583,7 +1591,11 @@
dir
=
self
.
gitdir
,
)
if
self
.
is_clone
and
self
.
gitdir
.
startswith
(
self
.
repo
.
root
):
if
(
object_store
is
None
and
self
.
is_clone
and
self
.
gitdir
.
startswith
(
self
.
repo
.
root
)
):
# if we're in a clone, and the git directory is within the
# repository just created, so we can use a named temporary
# file, suitable for moving into the git repository
...
...
@@ -1605,7 +1617,15 @@
)
if
f
.
tell
()
!=
0
:
if
move
:
if
object_store
is
not
None
:
# copied from Dulwich, as memory stores can't load packs :/
f
.
seek
(
0
)
p
=
PackData
.
from_file
(
f
,
f
.
tell
())
for
obj
in
PackInflater
.
for_pack_data
(
p
,
object_store
.
get_raw
):
object_store
.
add_object
(
obj
)
elif
move
:
self
.
ui
.
debug
(
b
'moving git pack into %s
\n
'
%
self
.
gitdir
)
# windows might have issues moving an open file?
f
.
close
()
...
...
hggit/overlay.py
View file @
44b9bfdc
...
...
@@ -39,7 +39,7 @@
class
overlaymanifest
(
object
):
def
__init__
(
self
,
repo
,
sha
):
self
.
repo
=
repo
self
.
tree
=
repo
.
handler
.
git
.
get_object
(
sha
)
self
.
tree
=
repo
.
object_store
[
sha
]
self
.
_map
=
None
self
.
_flags
=
None
...
...
@@ -76,7 +76,7 @@
for
entry
in
tree
.
items
():
if
entry
.
mode
&
0o40000
:
# expand directory
subtree
=
self
.
repo
.
handler
.
git
.
get_object
(
entry
.
sha
)
subtree
=
self
.
repo
.
object_store
[
entry
.
sha
]
addtree
(
subtree
,
dirname
+
entry
.
path
+
b
'/'
)
else
:
path
=
dirname
+
entry
.
path
...
...
@@ -206,7 +206,7 @@
return
self
.
fileid
def
data
(
self
):
blob
=
self
.
_repo
.
handler
.
git
.
get_object
(
_maybehex
(
self
.
fileid
)
)
blob
=
self
.
_repo
.
object_store
[
_maybehex
(
self
.
fileid
)
]
return
blob
.
data
def
isbinary
(
self
):
...
...
@@ -223,7 +223,7 @@
sha
=
sha
.
encode
(
'ascii'
)
else
:
sha
=
sha
.
hex
()
self
.
commit
=
repo
.
handler
.
git
.
get_object
(
_maybehex
(
sha
)
)
self
.
commit
=
repo
.
object_store
[
_maybehex
(
sha
)
]
self
.
_overlay
=
getattr
(
repo
,
'gitoverlay'
,
repo
)
self
.
_rev
=
self
.
_overlay
.
rev
(
bin
(
self
.
commit
.
id
))
self
.
_maybe_filtered
=
maybe_filtered
...
...
@@ -328,7 +328,7 @@
if
gitrev
is
None
:
# we've reached a revision we have
return
self
.
base
.
parents
(
n
)
commit
=
self
.
repo
.
handler
.
git
.
get_object
(
_maybehex
(
n
)
)
commit
=
self
.
repo
.
object_store
[
_maybehex
(
n
)
]
if
not
commit
.
parents
:
return
[
nullid
,
nullid
]
...
...
@@ -441,5 +441,5 @@
class
overlayrepo
(
object
):
def
__init__
(
self
,
handler
,
commits
,
refs
):
def
__init__
(
self
,
handler
,
object_store
,
commits
,
refs
):
self
.
handler
=
handler
...
...
@@ -445,4 +445,5 @@
self
.
handler
=
handler
self
.
object_store
=
object_store
self
.
_activebookmark
=
None
self
.
changelog
=
overlaychangelog
(
self
,
handler
.
repo
.
changelog
)
...
...
tests/test-incoming.t
View file @
44b9bfdc
...
...
@@ -137,6 +137,11 @@
summary:
add
d
/
gamma
and
that
shouldn
'
t cause anything to persist in the git repository
$ hg gimport
no changes found
nothing incoming after pull
$ hg pull
...
...
tests/test-push.t
View file @
44b9bfdc
...
...
@@ -216,5 +216,5 @@
Push
empty
Hg
repo
to
empty
Git
repo
(
issue
#58)
$
hg
init
hgrepo2
$
git
init
-
q --bare
repo
.
git
$
hg
-
R
hgrepo2
push
repo
.
git
$
hg
-
R
hgrepo2
push
-
v
repo
.
git
pushing
to
repo
.
git
...
...
@@ -220,4 +220,6 @@
pushing
to
repo
.
git
finding
unexported
changesets
exporting
0
changesets
searching
for
changes
abort:
no
bookmarks
or
tags
to
push
to
git
(
see
"
hg help bookmarks
"
for
details
on
creating
them
)
...
...
Write
Preview
Supports
Markdown
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