Skip to content

Pull request: Fix for "Cloning HG repo to Git creates "uncheck-out-able" repositories". And upgrade for filenames transcoding #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions git-remote-hg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ from mercurial import changegroup
import re
import sys
import os
import posixpath
import json
import shutil
import subprocess
Expand Down Expand Up @@ -119,6 +120,13 @@ def get_config_bool(config, default=False):
else:
return default

def get_config_str(config, default=""):
value = get_config(config).rstrip('\n')
if value != "":
return value
else:
return default

class Marks:

def __init__(self, path, repo):
Expand Down Expand Up @@ -272,10 +280,15 @@ class Parser:
return (user, int(date), hgtz(tz))

def fix_file_path(path):
path = os.path.normpath(path)
#path = os.path.normpath(path)
path = posixpath.normpath(path)
if transcode_filenames:
path = path.decode(hg_fn_enc).encode(git_fn_enc)
#new = old.decode("cp1251").encode("utf-8")
if not os.path.isabs(path):
return path
return os.path.relpath(path, '/')
#return os.path.relpath(path, '/')
return posixpath.relpath(path, '/')

def export_files(files):
final = []
Expand Down Expand Up @@ -911,6 +924,13 @@ def parse_commit(parser):
extra[ek] = urllib.unquote(ev)
data = data[:i]

if transcode_filenames:
filesr = {}
for fk in files.keys():
newfk = fk.decode(git_fn_enc).encode(hg_fn_enc)
filesr[newfk] = files[fk]
files = filesr

ctx = context.memctx(repo, (p1, p2), data,
files.keys(), getfilectx,
user, (date, tz), extra)
Expand Down Expand Up @@ -1310,6 +1330,7 @@ def main(args):
global fake_bmark, hg_version
global dry_run
global notes, alias
global transcode_filenames, hg_fn_enc, git_fn_enc

marks = None
is_tmp = False
Expand All @@ -1327,6 +1348,8 @@ def main(args):

hg_git_compat = get_config_bool('remote-hg.hg-git-compat')
track_branches = get_config_bool('remote-hg.track-branches', True)
transcode_filenames = get_config_bool('remote-hg.transcode-filenames', False)

force_push = False

if hg_git_compat:
Expand All @@ -1338,6 +1361,12 @@ def main(args):
bad_mail = 'unknown'
bad_name = 'Unknown'

if transcode_filenames:
hg_fn_enc = get_config_str('remote-hg.hg-filenames-enc','')
git_fn_enc = get_config_str('remote-hg.git-filenames-enc', 'utf-8')
if (hg_fn_enc == "") or (git_fn_enc == ""):
die('Filenames transcoding option is choosed, but hg and(or) git filenames encodings are not set!')

if alias[4:] == url:
is_tmp = True
alias = hashlib.sha1(alias).hexdigest()
Expand Down