diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000000000000000000000000000000000000..0e55a2ecac87556ce950b6ca96206d8674190195_LmhnaWdub3Jl --- /dev/null +++ b/.hgignore @@ -0,0 +1,3 @@ +syntax: glob + +*.pyc diff --git a/__init__.py b/__init__.py index 06366111af3c6a2ffa06333ed60d3ed3b9ec0763_X19pbml0X18ucHk=..0e55a2ecac87556ce950b6ca96206d8674190195_X19pbml0X18ucHk= 100644 --- a/__init__.py +++ b/__init__.py @@ -41,6 +41,6 @@ if hg_repo_path.endswith('.git'): hg_repo_path = hg_repo_path[:-4] hg_repo_path += '-hg' - subprocess.call(['hg', 'init', hg_repo_path]) - clone_git(git_url, git_path(hg_repo_path)) + subprocess.call(['hg', 'init', hg_repo_path]) + clone_git(git_url, hg_repo_path) import_git_heads(hg_repo_path) @@ -46,4 +46,10 @@ import_git_heads(hg_repo_path) + + # check it out + oldwd = os.getcwd() + os.chdir(hg_repo_path) + subprocess.call(['hg', 'checkout']) + os.chdir(oldwd) def gpull(ui, repo, source='default', **opts): """fetch from a git repo @@ -53,7 +59,7 @@ lock = repo.lock() wlock = repo.wlock() ui.write("fetching from the remote\n") - git_fetch() + git_fetch(git_path()) import_git_heads() # do the pull finally: @@ -72,9 +78,12 @@ del lock, wlock def git_path(hg_path=None): - return os.path.join(hg_path, '.hg', 'git-remote') + if hg_path: + return os.path.join(hg_path, '.hg', 'git-remote') + else: + return os.path.join('.hg', 'git-remote') def clone_git(git_url, hg_path=None): git_initialize(git_path(hg_path), git_url) git_fetch(git_path(hg_path)) @@ -76,7 +85,7 @@ def clone_git(git_url, hg_path=None): git_initialize(git_path(hg_path), git_url) git_fetch(git_path(hg_path)) -def git_initialize(git_path, git_url): +def git_initialize(git_repo_path, git_url): # TODO: implement this in pure python - should be strait-forward @@ -82,3 +91,2 @@ # TODO: implement this in pure python - should be strait-forward - subprocess.call(['git', '--bare', 'init', git_path]) oldwd = os.getcwd() @@ -84,5 +92,7 @@ oldwd = os.getcwd() - os.chdir(git_path) + os.makedirs(git_repo_path) + os.chdir(git_repo_path) + subprocess.call(['git', '--bare', 'init']) subprocess.call(['git', 'remote', 'add', 'origin', git_url]) os.chdir(oldwd) @@ -86,7 +96,7 @@ subprocess.call(['git', 'remote', 'add', 'origin', git_url]) os.chdir(oldwd) -def git_fetch(git_path, remote='origin'): +def git_fetch(git_repo_path, remote='origin'): # TODO: implement this in pure python # - we'll have to handle ssh and git oldwd = os.getcwd() @@ -90,7 +100,7 @@ # TODO: implement this in pure python # - we'll have to handle ssh and git oldwd = os.getcwd() - os.chdir(git_path) + os.chdir(git_repo_path) subprocess.call(['git', 'fetch', remote]) os.chdir(oldwd) @@ -98,9 +108,10 @@ # find all the local changesets that aren't mapped # create git commit object shas and map them # stick those objects in a packfile and push them up (over ssh) - + return 0 + def import_git_heads(hg_path=None): # go through each branch # add all commits we don't have locally # write a SHA<->SHA mapping table # update the local branches to match @@ -102,8 +113,10 @@ def import_git_heads(hg_path=None): # go through each branch # add all commits we don't have locally # write a SHA<->SHA mapping table # update the local branches to match + if not hg_path: + hg_path = '.' return subprocess.call(['hg', 'convert', git_path(hg_path), hg_path]) diff --git a/git.py b/git.py deleted file mode 100644 index 06366111af3c6a2ffa06333ed60d3ed3b9ec0763_Z2l0LnB5..0000000000000000000000000000000000000000 --- a/git.py +++ /dev/null @@ -1,146 +0,0 @@ -# git support for the convert extension - -import os -from mercurial import util - -from common import NoRepo, commit, converter_source, checktool - -class git_tool: - # Windows does not support GIT_DIR= construct while other systems - # cannot remove environment variable. Just assume none have - # both issues. - if hasattr(os, 'unsetenv'): - def gitcmd(self, s): - prevgitdir = os.environ.get('GIT_DIR') - os.environ['GIT_DIR'] = self.path - try: - return util.popen(s, 'rb') - finally: - if prevgitdir is None: - del os.environ['GIT_DIR'] - else: - os.environ['GIT_DIR'] = prevgitdir - else: - def gitcmd(self, s): - return util.popen('GIT_DIR=%s %s' % (self.path, s), 'rb') - - def __init__(self, ui, path, rev=None): - super(convert_git, self).__init__(ui, path, rev=rev) - - if os.path.isdir(path + "/.git"): - path += "/.git" - if not os.path.exists(path + "/objects"): - raise NoRepo("%s does not look like a Git repo" % path) - - checktool('git', 'git') - - self.path = path - - def getheads(self): - if not self.rev: - return self.gitcmd('git rev-parse --branches --remotes').read().splitlines() - else: - fh = self.gitcmd("git rev-parse --verify %s" % self.rev) - return [fh.read()[:-1]] - - def catfile(self, rev, type): - if rev == "0" * 40: raise IOError() - fh = self.gitcmd("git cat-file %s %s" % (type, rev)) - return fh.read() - - def getfile(self, name, rev): - return self.catfile(rev, "blob") - - def getmode(self, name, rev): - return self.modecache[(name, rev)] - - def getchanges(self, version): - self.modecache = {} - fh = self.gitcmd("git diff-tree -z --root -m -r %s" % version) - changes = [] - seen = {} - entry = None - for l in fh.read().split('\x00'): - if not entry: - if not l.startswith(':'): - continue - entry = l - continue - f = l - if f not in seen: - seen[f] = 1 - entry = entry.split() - h = entry[3] - p = (entry[1] == "100755") - s = (entry[1] == "120000") - self.modecache[(f, h)] = (p and "x") or (s and "l") or "" - changes.append((f, h)) - entry = None - return (changes, {}) - - def getcommit(self, version): - c = self.catfile(version, "commit") # read the commit hash - end = c.find("\n\n") - message = c[end+2:] - message = self.recode(message) - l = c[:end].splitlines() - manifest = l[0].split()[1] - parents = [] - for e in l[1:]: - n, v = e.split(" ", 1) - if n == "author": - p = v.split() - tm, tz = p[-2:] - author = " ".join(p[:-2]) - if author[0] == "<": author = author[1:-1] - author = self.recode(author) - if n == "committer": - p = v.split() - tm, tz = p[-2:] - committer = " ".join(p[:-2]) - if committer[0] == "<": committer = committer[1:-1] - committer = self.recode(committer) - message += "\ncommitter: %s\n" % committer - if n == "parent": parents.append(v) - - tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:] - tz = -int(tzs) * (int(tzh) * 3600 + int(tzm)) - date = tm + " " + str(tz) - - c = commit(parents=parents, date=date, author=author, desc=message, - rev=version) - return c - - def gettags(self): - tags = {} - fh = self.gitcmd('git ls-remote --tags "%s"' % self.path) - prefix = 'refs/tags/' - for line in fh: - line = line.strip() - if not line.endswith("^{}"): - continue - node, tag = line.split(None, 1) - if not tag.startswith(prefix): - continue - tag = tag[len(prefix):-3] - tags[tag] = node - - return tags - - def getchangedfiles(self, version, i): - changes = [] - if i is None: - fh = self.gitcmd("git diff-tree --root -m -r %s" % version) - for l in fh: - if "\t" not in l: - continue - m, f = l[:-1].split("\t") - changes.append(f) - fh.close() - else: - fh = self.gitcmd('git diff-tree --name-only --root -r %s "%s^%s" --' - % (version, version, i+1)) - changes = [f.rstrip('\n') for f in fh] - fh.close() - - return changes