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
08174d741106
Commit
08174d74
authored
Jan 27, 2022
by
Dan Villiom Podlaski Christiansen
Browse files
exchange: use proper path object, when available
parent
6ede57cad9e3
Pipeline
#34324
failed with stages
in 75 minutes and 47 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
hggit/commands.py
View file @
08174d74
...
...
@@ -30,7 +30,7 @@
@
eh
.
command
(
b
'gimport'
)
def
gimport
(
ui
,
repo
,
remote_name
=
None
):
def
gimport
(
ui
,
repo
):
'''import commits from Git to Mercurial (ADVANCED)
This command is equivalent to pulling from a Git source, but
...
...
@@ -41,7 +41,7 @@
'''
with
repo
.
wlock
():
repo
.
githandler
.
import_commits
(
remote_name
)
repo
.
githandler
.
import_commits
()
@
eh
.
command
(
b
'gexport'
)
...
...
hggit/git_handler.py
View file @
08174d74
...
...
@@ -22,7 +22,10 @@
from
mercurial.i18n
import
_
from
mercurial.node
import
hex
,
bin
,
nullid
,
short
from
mercurial.utils
import
dateutil
from
mercurial.utils
import
(
dateutil
,
urlutil
,
)
from
mercurial
import
(
bookmarks
,
context
,
...
...
@@ -346,5 +349,5 @@
# COMMANDS METHODS
def
import_commits
(
self
,
remote_name
):
def
import_commits
(
self
):
refs
=
self
.
git
.
refs
.
as_dict
()
...
...
@@ -350,4 +353,3 @@
refs
=
self
.
git
.
refs
.
as_dict
()
remote_names
=
[
remote_name
]
if
remote_name
else
[]
self
.
import_git_objects
(
remote_names
,
refs
)
self
.
import_git_objects
(
None
,
refs
)
...
...
@@ -353,9 +355,8 @@
def
fetch
(
self
,
remote
,
heads
):
result
=
self
.
fetch_pack
(
remote
.
path
,
heads
)
remote_names
=
self
.
remote_names
(
remote
.
path
,
False
)
def
fetch
(
self
,
path
,
heads
):
result
=
self
.
fetch_pack
(
path
,
heads
)
oldheads
=
self
.
repo
.
changelog
.
heads
()
if
result
.
refs
:
imported
=
self
.
import_git_objects
(
...
...
@@ -357,7 +358,7 @@
oldheads
=
self
.
repo
.
changelog
.
heads
()
if
result
.
refs
:
imported
=
self
.
import_git_objects
(
remote_names
,
path
,
result
.
refs
,
...
...
@@ -363,5 +364,5 @@
result
.
refs
,
heads
=
heads
,
heads
,
)
else
:
imported
=
0
...
...
@@ -472,10 +473,10 @@
_
(
b
"git remote error: "
)
+
pycompat
.
sysbytes
(
str
(
e
))
)
def
push
(
self
,
remote
,
revs
,
force
):
old_refs
,
new_refs
=
self
.
upload_pack
(
remote
,
revs
,
force
)
remote_names
=
self
.
remote_names
(
remote
,
True
)
remote_desc
=
remote_names
[
0
]
if
remote_names
else
remote
def
push
(
self
,
path
,
revs
,
force
):
old_refs
,
new_refs
=
self
.
upload_pack
(
path
,
revs
,
force
)
remote_names
=
self
.
remote_names
(
path
,
True
)
remote_desc
=
remote_names
[
0
]
if
remote_names
else
path
if
not
isinstance
(
new_refs
,
dict
):
# dulwich 0.20.6 changed the API and deprectated treating
...
...
@@ -521,7 +522,7 @@
try
:
new_refs_with_head
.
update
(
self
.
fetch_pack
(
remote
,
[
b
'HEAD'
]).
refs
,
self
.
fetch_pack
(
path
,
[
b
'HEAD'
]).
refs
,
)
except
(
error
.
RepoLookupError
):
self
.
ui
.
debug
(
b
'remote repository has no HEAD
\n
'
)
...
...
@@ -988,7 +989,7 @@
else
:
return
None
,
None
def
import_git_objects
(
self
,
remote_names
,
refs
,
heads
=
None
):
def
import_git_objects
(
self
,
path
,
refs
,
heads
=
None
):
filteredrefs
=
self
.
filter_min_date
(
refs
)
if
heads
is
not
None
:
filteredrefs
=
git2hg
.
filter_refs
(
filteredrefs
,
heads
)
...
...
@@ -1028,6 +1029,9 @@
)
self
.
import_tags
(
refs
)
remote_names
=
self
.
remote_names
(
path
,
False
)
self
.
update_hg_bookmarks
(
remote_names
,
refs
)
for
remote_name
in
remote_names
:
...
...
@@ -1315,7 +1319,7 @@
# PACK UPLOADING AND FETCHING
def
upload_pack
(
self
,
remote
,
revs
,
force
):
def
upload_pack
(
self
,
path
,
revs
,
force
):
all_exportable
=
self
.
export_commits
()
old_refs
=
{}
change_totals
=
{}
...
...
@@ -1368,6 +1372,10 @@
progress
=
GitProgress
(
self
.
ui
)
progressfunc
=
progress
.
progress
remote
=
(
path
.
pushloc
or
path
.
loc
if
isinstance
(
path
,
urlutil
.
path
)
else
path
)
try
:
new_refs
=
self
.
_call_client
(
remote
,
'send_pack'
,
changed
,
genpack
,
progress
=
progressfunc
...
...
@@ -1458,7 +1466,7 @@
return
new_refs
def
fetch_pack
(
self
,
remote
,
heads
=
None
):
def
fetch_pack
(
self
,
path
,
heads
=
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
...
...
@@ -1495,7 +1503,7 @@
try
:
ret
=
self
.
_call_client
(
remote
,
path
.
loc
if
isinstance
(
path
,
urlutil
.
path
)
else
path
,
'fetch_pack'
,
determine_wants
,
graphwalker
,
...
...
@@ -2055,6 +2063,12 @@
)
def
remote_names
(
self
,
remote
,
push
):
if
not
isinstance
(
remote
,
bytes
):
if
remote
is
None
or
remote
.
name
is
None
:
return
[]
else
:
return
[
remote
.
name
]
names
=
set
()
url
=
compat
.
url
(
remote
)
...
...
hggit/gitrepo.py
View file @
08174d74
...
...
@@ -188,7 +188,10 @@
)
with
repo
.
wlock
(),
repo
.
lock
(),
pullop
.
trmanager
:
pullop
.
cgresult
=
repo
.
githandler
.
fetch
(
remote
,
heads
)
pullop
.
cgresult
=
repo
.
githandler
.
fetch
(
kwargs
.
get
(
"path"
)
or
remote
.
path
,
heads
,
)
return
pullop
else
:
return
orig
(
...
...
@@ -225,7 +228,11 @@
bookmarks
,
**
pycompat
.
strkwargs
(
opargs
or
{}),
)
pushop
.
cgresult
=
repo
.
githandler
.
push
(
remote
.
path
,
revs
,
force
)
pushop
.
cgresult
=
repo
.
githandler
.
push
(
kwargs
.
get
(
"path"
)
or
remote
.
path
,
revs
,
force
,
)
return
pushop
else
:
return
orig
(
...
...
tests/test-multiple-remotes.t
View file @
08174d74
...
...
@@ -36,6 +36,10 @@
(
run
'
hg update
'
to
get
a
working
copy
)
pulling
from
$TESTTMP
/
repo
.
git
no
changes
found
5.9
cannot
distinguish
remotes
by
name:
#if no-hg60
$
hg
tags
tip
0
:
ff7a2f2d8d70
git
/
not
-
master
0
:
ff7a2f2d8d70
...
...
@@ -46,6 +50,29 @@
also
-
git
/
master
0
:
ff7a2f2d8d70
also
-
bare
/
not
-
master
0
:
ff7a2f2d8d70
also
-
bare
/
master
0
:
ff7a2f2d8d70
#endif
6.0
can
,
but
picks
the
wrong
one:
#if hg60 no-hg61
$
hg
tags
tip
0
:
ff7a2f2d8d70
default
/
not
-
master
0
:
ff7a2f2d8d70
default
/
master
0
:
ff7a2f2d8d70
#endif
6.1
gets
it
right:
#if hg61
$
hg
tags
tip
0
:
ff7a2f2d8d70
git
/
not
-
master
0
:
ff7a2f2d8d70
git
/
master
0
:
ff7a2f2d8d70
bare
/
not
-
master
0
:
ff7a2f2d8d70
bare
/
master
0
:
ff7a2f2d8d70
#endif
And
now
,
try
a
push
:
$
hg
up
master
1
files
updated
,
0
files
merged
,
0
files
removed
,
0
files
unresolved
...
...
@@ -64,6 +91,10 @@
added
1
commits
with
1
trees
and
1
blobs
updating
reference
refs
/heads/mas
ter
Prior
to
6.0
cannot
distinguish
remotes
by
name
for
push
:
#if no-hg61
$
hg
tags
tip
1
:
47580592
d3d6
git
/
master
1
:
47580592
d3d6
...
...
@@ -71,6 +102,8 @@
also
-
git
/
master
1
:
47580592
d3d6
also
-
bare
/
master
1
:
47580592
d3d6
git
/
not
-
master
0
:
ff7a2f2d8d70
default
/
not
-
master
0
:
ff7a2f2d8d70
(
hg60
!
)
default
/
master
0
:
ff7a2f2d8d70
(
hg60
!
)
bare
/
not
-
master
0
:
ff7a2f2d8d70
also
-
git
/
not
-
master
0
:
ff7a2f2d8d70
also
-
bare
/
not
-
master
0
:
ff7a2f2d8d70
...
...
@@ -74,4 +107,5 @@
bare
/
not
-
master
0
:
ff7a2f2d8d70
also
-
git
/
not
-
master
0
:
ff7a2f2d8d70
also
-
bare
/
not
-
master
0
:
ff7a2f2d8d70
#endif
...
...
@@ -77,1 +111,22 @@
6.1
gets
it
right:
#if hg61
$
hg
tags
tip
1
:
47580592
d3d6
git
/
master
1
:
47580592
d3d6
bare
/
master
1
:
47580592
d3d6
git
/
not
-
master
0
:
ff7a2f2d8d70
bare
/
not
-
master
0
:
ff7a2f2d8d70
$
hg
pull
also
-
git
pulling
from
$TESTTMP
/
gitrepo
no
changes
found
$
hg
tags
tip
1
:
47580592
d3d6
git
/
master
1
:
47580592
d3d6
bare
/
master
1
:
47580592
d3d6
also
-
git
/
master
1
:
47580592
d3d6
git
/
not
-
master
0
:
ff7a2f2d8d70
bare
/
not
-
master
0
:
ff7a2f2d8d70
also
-
git
/
not
-
master
0
:
ff7a2f2d8d70
#endif
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