annotate git_handler.py @ 79:7b4cf18c896b

readded yet another piece of code that disappeared at some point, recovering branches properly
author Scott Chacon <schacon@gmail.com>
date Thu, 07 May 2009 15:07:18 -0700
parents 71b07e16004f
children 0e0a2d20deed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
1 import os, errno, sys, time, datetime, pickle, copy
76
aa2dadf04144 fixed the topo sorting and added a unit test
Scott Chacon <schacon@gmail.com>
parents: 75
diff changeset
2 import toposort
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
3 import dulwich
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
4 from dulwich.repo import Repo
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
5 from dulwich.client import SimpleFetchGraphWalker
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
6 from hgext import bookmarks
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
7 from mercurial.i18n import _
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
8 from mercurial.node import bin, hex, nullid
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
9 from mercurial import hg, util, context, error
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
10 from dulwich.objects import (
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
11 Blob,
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
12 Commit,
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
13 ShaFile,
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
14 Tag,
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
15 Tree,
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
16 hex_to_sha
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
17 )
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
18
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
19 import math
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
20
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
21 def seconds_to_offset(time):
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
22 hours = (float(time) / 60 / 60)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
23 hour_diff = math.fmod(time, 60)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
24 minutes = int(hour_diff)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
25 hours = int(math.floor(hours))
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
26 if hours > 12:
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
27 sign = '+'
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
28 hours = 12 - (hours - 12)
69
983c2792f8d8 Better deal with negative timezone offsets
Chris Wanstrath <chris@ozmm.org>
parents: 68
diff changeset
29 elif hours > 0:
983c2792f8d8 Better deal with negative timezone offsets
Chris Wanstrath <chris@ozmm.org>
parents: 68
diff changeset
30 sign = '-'
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
31 else:
69
983c2792f8d8 Better deal with negative timezone offsets
Chris Wanstrath <chris@ozmm.org>
parents: 68
diff changeset
32 sign = ''
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
33 return sign + str(hours).rjust(2, '0') + str(minutes).rjust(2, '0')
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
34
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
35 def offset_to_seconds(offset):
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
36 if len(offset) == 5:
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
37 sign = offset[0:1]
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
38 hours = int(offset[1:3])
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
39 minutes = int(offset[3:5])
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
40 if sign == '+':
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
41 hours = 12 + (12 - hours)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
42 return (hours * 60 * 60) + (minutes) * 60
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
43 else:
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
44 return 0
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
45
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
46 class GitHandler(object):
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
47
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
48 def __init__(self, dest_repo, ui):
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
49 self.repo = dest_repo
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
50 self.ui = ui
16
58cd05129119 moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents: 14
diff changeset
51 self.init_if_missing()
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
52 self.load_git()
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
53 self.load_map()
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
54 self.load_config()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
55
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
56 # make the git data directory
16
58cd05129119 moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents: 14
diff changeset
57 def init_if_missing(self):
58cd05129119 moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents: 14
diff changeset
58 git_hg_path = os.path.join(self.repo.path, 'git')
17
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
59 if not os.path.exists(git_hg_path):
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
60 os.mkdir(git_hg_path)
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
61 dulwich.repo.Repo.init_bare(git_hg_path)
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
62
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
63 def load_git(self):
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
64 git_dir = os.path.join(self.repo.path, 'git')
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
65 self.git = Repo(git_dir)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
66
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
67 ## FILE LOAD AND SAVE METHODS
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
68
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
69 def map_set(self, gitsha, hgsha):
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
70 self._map_git[gitsha] = hgsha
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
71 self._map_hg[hgsha] = gitsha
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
72
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
73 def map_hg_get(self, gitsha):
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
74 if gitsha in self._map_git:
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
75 return self._map_git[gitsha]
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
76 else:
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
77 return None
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
78
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
79 def map_git_get(self, hgsha):
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
80 if hgsha in self._map_hg:
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
81 return self._map_hg[hgsha]
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
82 else:
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
83 return None
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
84
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
85 def load_map(self):
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
86 self._map_git = {}
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
87 self._map_hg = {}
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
88 if os.path.exists(self.repo.join('git-mapfile')):
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
89 for line in self.repo.opener('git-mapfile'):
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
90 gitsha, hgsha = line.strip().split(' ', 1)
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
91 self._map_git[gitsha] = hgsha
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
92 self._map_hg[hgsha] = gitsha
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
93
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
94 def save_map(self):
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
95 file = self.repo.opener('git-mapfile', 'w+')
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
96 for gitsha, hgsha in self._map_git.iteritems():
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
97 file.write("%s %s\n" % (gitsha, hgsha))
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
98 file.close()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
99
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
100 def load_config(self):
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
101 self._config = {}
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
102 if os.path.exists(self.repo.join('git-config')):
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
103 for line in self.repo.opener('git-config'):
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
104 key, value = line.strip().split(' ', 1)
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
105 self._config[key] = value
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
106
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
107 def save_config(self):
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
108 file = self.repo.opener('git-config', 'w+')
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
109 for key, value in self._config.iteritems():
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
110 file.write("%s %s\n" % (key, value))
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
111 file.close()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
112
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
113
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
114 ## END FILE LOAD AND SAVE METHODS
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
115
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
116 def fetch(self, remote_name):
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
117 self.ui.status(_("fetching from : " + remote_name + "\n"))
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
118 self.export_git_objects()
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
119 refs = self.fetch_pack(remote_name)
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
120 if refs:
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
121 self.import_git_objects(remote_name)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
122 self.save_map()
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
123
17
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
124 def push(self, remote_name):
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
125 self.ui.status(_("pushing to : " + remote_name + "\n"))
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
126 self.export_git_objects()
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
127 self.update_references()
17
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
128 self.upload_pack(remote_name)
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
129 self.save_map()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
130
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
131 def remote_add(self, remote_name, git_url):
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
132 self._config['remote.' + remote_name + '.url'] = git_url
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
133 self.save_config()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
134
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
135 def remote_remove(self, remote_name):
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
136 key = 'remote.' + remote_name + '.url'
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
137 if key in self._config:
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
138 del self._config[key]
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
139 self.save_config()
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
140
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
141 def remote_show(self, remote_name):
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
142 key = 'remote.' + remote_name + '.url'
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
143 if key in self._config:
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
144 name = self._config[key]
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
145 self.ui.status("URL for %s : %s\n" % (remote_name, name, ))
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
146 else:
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
147 self.ui.status("No remote named : %s\n" % remote_name)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
148 return
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
149
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
150 def remote_list(self):
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
151 for key, value in self._config.iteritems():
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
152 if key[0:6] == 'remote':
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
153 self.ui.status('%s\t%s\n' % (key, value, ))
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
154
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
155 def remote_name_to_url(self, remote_name):
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
156 return self._config['remote.' + remote_name + '.url']
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
157
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
158 def update_references(self):
25
88e9e9e1caf1 will now set the current tip() as your git 'master' branch for packfile upload
Scott Chacon <schacon@gmail.com>
parents: 24
diff changeset
159 # TODO : if bookmarks exist, add them as git branches
88e9e9e1caf1 will now set the current tip() as your git 'master' branch for packfile upload
Scott Chacon <schacon@gmail.com>
parents: 24
diff changeset
160 c = self.map_git_get(hex(self.repo.changelog.tip()))
88e9e9e1caf1 will now set the current tip() as your git 'master' branch for packfile upload
Scott Chacon <schacon@gmail.com>
parents: 24
diff changeset
161 self.git.set_ref('refs/heads/master', c)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
162
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
163 def export_git_objects(self):
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
164 self.ui.status("exporting git objects\n")
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
165 for rev in self.repo.changelog:
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
166 self.export_hg_commit(rev)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
167
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
168 # convert this commit into git objects
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
169 # go through the manifest, convert all blobs/trees we don't have
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
170 # write the commit object (with metadata info)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
171 def export_hg_commit(self, rev):
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
172 # return if we've already processed this
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
173 node = self.repo.changelog.lookup(rev)
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
174 phgsha = hex(node)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
175 pgit_sha = self.map_git_get(phgsha)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
176 if pgit_sha:
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
177 return pgit_sha
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
178
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
179 self.ui.status("converting revision " + str(rev) + "\n")
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
180
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
181 # make sure parents are converted first
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
182 parents = self.repo.parents(rev)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
183 for parent in parents:
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
184 p_rev = parent.rev()
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
185 hgsha = hex(parent.node())
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
186 git_sha = self.map_git_get(hgsha)
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
187 if not p_rev == -1:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
188 if not git_sha:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
189 self.export_hg_commit(p_rev)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
190
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
191 ctx = self.repo.changectx(rev)
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
192 tree_sha, renames = self.write_git_tree(ctx)
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
193
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
194 commit = {}
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
195 commit['tree'] = tree_sha
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
196 (time, timezone) = ctx.date()
68
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
197
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
198 # hg authors might not have emails
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
199 author = ctx.user()
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
200 if not '>' in author:
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
201 author = author + ' <none@none>'
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
202 commit['author'] = author + ' ' + str(int(time)) + ' ' + seconds_to_offset(timezone)
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
203 message = ctx.description()
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
204 commit['message'] = ctx.description()
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
205
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
206 # HG EXTRA INFORMATION
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
207 add_extras = False
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
208 extra_message = ''
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
209 if not ctx.branch() == 'default':
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
210 add_extras = True
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
211 extra_message += "branch : " + ctx.branch() + "\n"
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
212
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
213 if renames:
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
214 add_extras = True
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
215 for oldfile, newfile in renames:
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
216 extra_message += "rename : " + oldfile + " => " + newfile + "\n"
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
217
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
218 if add_extras:
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
219 commit['message'] += "\n\n--HG--\n" + extra_message
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
220
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
221 commit['parents'] = []
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
222 for parent in parents:
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
223 hgsha = hex(parent.node())
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
224 git_sha = self.map_git_get(hgsha)
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
225 if git_sha:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
226 commit['parents'].append(git_sha)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
227
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
228 commit_sha = self.git.write_commit_hash(commit) # writing new blobs to git
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
229 self.map_set(commit_sha, phgsha)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
230 return commit_sha
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
231
23
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
232 def write_git_tree(self, ctx):
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
233 trees = {}
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
234 man = ctx.manifest()
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
235 renames = []
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
236 for filenm in man.keys():
23
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
237 # write blob if not in our git database
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
238 fctx = ctx.filectx(filenm)
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
239 rename = fctx.renamed()
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
240 if rename:
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
241 filerename, sha = rename
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
242 renames.append((filerename, filenm))
23
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
243 is_exec = 'x' in fctx.flags()
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
244 is_link = 'l' in fctx.flags()
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
245 file_id = hex(fctx.filenode())
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
246 blob_sha = self.map_git_get(file_id)
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
247 if not blob_sha:
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
248 blob_sha = self.git.write_blob(fctx.data()) # writing new blobs to git
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
249 self.map_set(blob_sha, file_id)
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
250
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
251 parts = filenm.split('/')
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
252 if len(parts) > 1:
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
253 # get filename and path for leading subdir
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
254 filepath = parts[-1:][0]
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
255 dirpath = "/".join([v for v in parts[0:-1]]) + '/'
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
256
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
257 # get subdir name and path for parent dir
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
258 parpath = '/'
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
259 nparpath = '/'
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
260 for part in parts[0:-1]:
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
261 if nparpath == '/':
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
262 nparpath = part + '/'
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
263 else:
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
264 nparpath += part + '/'
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
265
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
266 treeentry = ['tree', part + '/', nparpath]
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
267
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
268 if parpath not in trees:
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
269 trees[parpath] = []
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
270 if treeentry not in trees[parpath]:
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
271 trees[parpath].append( treeentry )
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
272
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
273 parpath = nparpath
23
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
274
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
275 # set file entry
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
276 fileentry = ['blob', filepath, blob_sha, is_exec, is_link]
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
277 if dirpath not in trees:
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
278 trees[dirpath] = []
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
279 trees[dirpath].append(fileentry)
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
280
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
281 else:
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
282 fileentry = ['blob', parts[0], blob_sha, is_exec, is_link]
23
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
283 if '/' not in trees:
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
284 trees['/'] = []
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
285 trees['/'].append(fileentry)
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
286
23
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
287 # sort by tree depth, so we write the deepest trees first
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
288 dirs = trees.keys()
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
289 dirs.sort(lambda a, b: len(b.split('/'))-len(a.split('/')))
42
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
290 dirs.remove('/')
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
291 dirs.append('/')
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
292
23
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
293 # write all the trees
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
294 tree_sha = None
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
295 tree_shas = {}
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
296 for dirnm in dirs:
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
297 tree_data = []
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
298 for entry in trees[dirnm]:
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
299 # replace tree path with tree SHA
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
300 if entry[0] == 'tree':
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
301 sha = tree_shas[entry[2]]
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
302 entry[2] = sha
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
303 tree_data.append(entry)
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
304 tree_sha = self.git.write_tree_array(tree_data) # writing new trees to git
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
305 tree_shas[dirnm] = tree_sha
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
306 return (tree_sha, renames) # should be the last root tree sha
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
307
13
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
308 def remote_head(self, remote_name):
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
309 for head, sha in self.git.remote_refs(remote_name).iteritems():
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
310 if head == 'HEAD':
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
311 return self.map_hg_get(sha)
13
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
312 return None
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
313
17
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
314 def upload_pack(self, remote_name):
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
315 git_url = self.remote_name_to_url(remote_name)
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
316 client, path = self.get_transport_and_path(git_url)
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
317 changed = self.get_changed_refs
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
318 genpack = self.generate_pack_contents
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
319 try:
52
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
320 self.ui.status("creating and sending data\n")
47
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
321 changed_refs = client.send_pack(path, changed, genpack)
52
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
322 if changed_refs:
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
323 new_refs = {}
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
324 for old, new, ref in changed_refs:
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
325 self.ui.status(" "+ remote_name + "::" + ref + " : GIT:" + old[0:8] + " => GIT:" + new[0:8] + "\n")
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
326 new_refs[ref] = new
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
327 self.git.set_remote_refs(new_refs, remote_name)
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
328 self.update_hg_bookmarks(remote_name)
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
329 except:
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
330 raise
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
331
42
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
332 # TODO : for now, we'll just push all heads that match remote heads
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
333 # * we should have specified push, tracking branches and --all
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
334 # takes a dict of refs:shas from the server and returns what should be
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
335 # pushed up
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
336 def get_changed_refs(self, refs):
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
337 keys = refs.keys()
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
338
42
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
339 changed = []
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
340 if not keys:
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
341 return None
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
342
42
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
343 # TODO : this is a huge hack
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
344 if keys[0] == 'capabilities^{}': # nothing on the server yet - first push
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
345 changed.append(("0"*40, self.git.ref('master'), 'refs/heads/master'))
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
346
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
347 for ref_name in keys:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
348 parts = ref_name.split('/')
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
349 if parts[0] == 'refs': # strip off 'refs/heads'
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
350 if parts[1] == 'heads':
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
351 head = "/".join([v for v in parts[2:]])
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
352 local_ref = self.git.ref(ref_name)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
353 if local_ref:
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
354 if not local_ref == refs[ref_name]:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
355 changed.append((refs[ref_name], local_ref, ref_name))
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
356 return changed
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
357
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
358 # takes a list of shas the server wants and shas the server has
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
359 # and generates a list of commit shas we need to push up
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
360 def generate_pack_contents(self, want, have):
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
361 graph_walker = SimpleFetchGraphWalker(want, self.git.get_parents)
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
362 next = graph_walker.next()
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
363 shas = set()
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
364 while next:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
365 if next in have:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
366 graph_walker.ack(next)
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
367 else:
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
368 shas.add(next)
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
369 next = graph_walker.next()
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
370
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
371 seen = []
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
372
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
373 # so now i have the shas, need to turn them into a list of
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
374 # tuples (sha, path) for ALL the objects i'm sending
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
375 # TODO : don't send blobs or trees they already have
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
376 def get_objects(tree, path):
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
377 changes = list()
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
378 changes.append((tree, path))
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
379 for (mode, name, sha) in tree.entries():
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
380 if mode == 57344: # TODO : properly handle submodules
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
381 continue
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
382 if sha in seen:
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
383 continue
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
384
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
385 obj = self.git.get_object(sha)
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
386 seen.append(sha)
76
aa2dadf04144 fixed the topo sorting and added a unit test
Scott Chacon <schacon@gmail.com>
parents: 75
diff changeset
387 if isinstance (obj, Blob):
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
388 changes.append((obj, path + name))
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
389 elif isinstance(obj, Tree):
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
390 changes.extend(get_objects(obj, path + name + '/'))
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
391 return changes
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
392
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
393 objects = []
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
394 for commit_sha in shas:
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
395 commit = self.git.commit(commit_sha)
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
396 objects.append((commit, 'commit'))
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
397 tree = self.git.get_object(commit.tree)
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
398 objects.extend( get_objects(tree, '/') )
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
399
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
400 return objects
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
401
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
402 def fetch_pack(self, remote_name):
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
403 git_url = self.remote_name_to_url(remote_name)
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
404 client, path = self.get_transport_and_path(git_url)
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
405 graphwalker = SimpleFetchGraphWalker(self.git.heads().values(), self.git.get_parents)
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
406 f, commit = self.git.object_store.add_pack()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
407 try:
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
408 determine_wants = self.git.object_store.determine_wants_all
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
409 refs = client.fetch_pack(path, determine_wants, graphwalker, f.write, sys.stdout.write)
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
410 f.close()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
411 commit()
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
412 if refs:
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
413 self.git.set_remote_refs(refs, remote_name)
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
414 else:
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
415 self.ui.status(_("nothing new on the server\n"))
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
416 return refs
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
417 except:
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
418 f.close()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
419 raise
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
420
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
421 def import_git_objects(self, remote_name):
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
422 self.ui.status(_("importing Git objects into Hg\n"))
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
423 # import heads as remote references
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
424 todo = []
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
425 done = set()
9
7e776864b301 sorts the commits topologically before converting
Scott Chacon <schacon@gmail.com>
parents: 8
diff changeset
426 convert_list = {}
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
427
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
428 # get a list of all the head shas
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
429 for head, sha in self.git.remote_refs(remote_name).iteritems():
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
430 todo.append(sha)
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
431
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
432 # traverse the heads getting a list of all the unique commits
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
433 while todo:
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
434 sha = todo.pop()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
435 assert isinstance(sha, str)
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
436 if sha in done:
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
437 continue
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
438 done.add(sha)
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
439 try:
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
440 commit = self.git.commit(sha)
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
441 convert_list[sha] = commit
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
442 todo.extend([p for p in commit.parents if p not in done])
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
443 except:
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
444 self.ui.warn("Cannot import tags yet\n") # TODO
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
445
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
446 # sort the commits
78
71b07e16004f fix, but im not sure its fixed yet
Scott Chacon <schacon@gmail.com>
parents: 77
diff changeset
447 commits = toposort.TopoSort(convert_list).items()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
448
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
449 # import each of the commits, oldest first
9
7e776864b301 sorts the commits topologically before converting
Scott Chacon <schacon@gmail.com>
parents: 8
diff changeset
450 for csha in commits:
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
451 if not self.map_hg_get(csha): # it's already here
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
452 commit = convert_list[csha]
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
453 self.import_git_commit(commit)
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
454
47
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
455 self.update_hg_bookmarks(remote_name)
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
456
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
457 def update_hg_bookmarks(self, remote_name):
29
2a5c0bf0fef5 Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
458 try:
47
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
459 bms = bookmarks.parse(self.repo)
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
460 for head, sha in self.git.remote_refs(remote_name).iteritems():
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
461 hgsha = hex_to_sha(self.map_hg_get(sha))
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
462 if not head == 'HEAD':
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
463 bms[remote_name + '/' + head] = hgsha
29
2a5c0bf0fef5 Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
464 bookmarks.write(self.repo, bms)
2a5c0bf0fef5 Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
465 except AttributeError:
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
466 self.ui.warn('creating bookmarks failed, do you have'
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
467 ' bookmarks enabled?\n')
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
468
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
469 def convert_git_int_mode(self, mode):
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
470 convert = {
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
471 33188: '',
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
472 40960: 'l',
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
473 33261: 'e'}
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
474 if mode in convert:
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
475 return convert[mode]
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
476 return ''
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
477
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
478 def extract_hg_metadata(self, message):
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
479 split = message.split("\n\n--HG--\n", 1)
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
480 renames = {}
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
481 branch = False
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
482 if len(split) == 2:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
483 message, meta = split
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
484 lines = meta.split("\n")
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
485 for line in lines:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
486 if line == '':
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
487 continue
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
488
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
489 command, data = line.split(" : ", 1)
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
490 if command == 'rename':
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
491 before, after = data.split(" => ", 1)
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
492 renames[after] = before
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
493 if command == 'branch':
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
494 branch = data
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
495 return (message, renames, branch)
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
496
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
497 def import_git_commit(self, commit):
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
498 self.ui.debug("importing: %s\n" % commit.id)
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
499 # TODO : find and use hg named branches
35
562fc51b991e we did the same thing, not sure why it conflicted
Scott Chacon <schacon@gmail.com>
parents: 29
diff changeset
500 # TODO : add extra Git data (committer info) as extras to changeset
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
501
10
66860f141788 update todo file and removed outdated TODO comments
Scott Chacon <schacon@gmail.com>
parents: 9
diff changeset
502 # TODO : (?) have to handle merge contexts at some point (two parent files, etc)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
503 # TODO : Do something less coarse-grained than try/except on the
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
504 # get_file call for removed files
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
505
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
506 (strip_message, hg_renames, hg_branch) = self.extract_hg_metadata(commit.message)
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
507
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
508 def getfilectx(repo, memctx, f):
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
509 try:
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
510 (mode, sha, data) = self.git.get_file(commit, f)
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
511 e = self.convert_git_int_mode(mode)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
512 except TypeError:
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
513 raise IOError()
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
514 if f in hg_renames:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
515 copied_path = hg_renames[f]
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
516 else:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
517 copied_path = None
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
518 return context.memfilectx(f, data, 'l' in e, 'x' in e, copied_path)
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
519
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
520 p1 = "0" * 40
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
521 p2 = "0" * 40
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
522 if len(commit.parents) > 0:
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
523 sha = commit.parents[0]
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
524 p1 = self.map_hg_get(sha)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
525 if len(commit.parents) > 1:
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
526 sha = commit.parents[1]
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
527 p2 = self.map_hg_get(sha)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
528 if len(commit.parents) > 2:
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
529 # TODO : map extra parents to the extras file
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
530 pass
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
531
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
532 # get a list of the changed, added, removed files
76
aa2dadf04144 fixed the topo sorting and added a unit test
Scott Chacon <schacon@gmail.com>
parents: 75
diff changeset
533 files = self.git.get_files_changed(commit)
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
534
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
535 # if this is a merge commit, don't list renamed files
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
536 # i'm really confused here - this is the only way my use case will
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
537 # work, but it seems really hacky - do I need to just remove renames
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
538 # from one of the parents? AARRGH!
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
539 if not (p2 == "0"*40):
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
540 for removefile in hg_renames.values():
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
541 files.remove(removefile)
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
542
76
aa2dadf04144 fixed the topo sorting and added a unit test
Scott Chacon <schacon@gmail.com>
parents: 75
diff changeset
543 extra = {}
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
544
76
aa2dadf04144 fixed the topo sorting and added a unit test
Scott Chacon <schacon@gmail.com>
parents: 75
diff changeset
545 # *TODO : if committer is different than author, add it to extra
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
546
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
547 # if named branch, add to extra
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
548 if hg_branch:
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
549 extra['branch'] = hg_branch
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
550
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
551 text = strip_message
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
552 date = datetime.datetime.fromtimestamp(commit.author_time).strftime("%Y-%m-%d %H:%M:%S")
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
553 ctx = context.memctx(self.repo, (p1, p2), text, files, getfilectx,
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
554 commit.author, date, extra)
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
555 a = self.repo.commitctx(ctx)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
556
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
557 # get changeset id
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
558 p2 = hex(self.repo.changelog.tip())
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
559 # save changeset to mapping file
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
560 gitsha = commit.id
21
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
561 self.map_set(gitsha, p2)
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
562
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
563 def check_bookmarks(self):
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
564 if self.ui.config('extensions', 'hgext.bookmarks') is not None:
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
565 self.ui.warn("YOU NEED TO SETUP BOOKMARKS\n")
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
566
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
567 def get_transport_and_path(self, uri):
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
568 from dulwich.client import TCPGitClient, SSHGitClient, SubprocessGitClient
35
562fc51b991e we did the same thing, not sure why it conflicted
Scott Chacon <schacon@gmail.com>
parents: 29
diff changeset
569 for handler, transport in (("git://", TCPGitClient), ("git@", SSHGitClient), ("git+ssh://", SSHGitClient)):
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
570 if uri.startswith(handler):
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
571 if handler == 'git@':
28
b258ef16ae37 Fix non-ssh URI parsing.
Augie Fackler <durin42@gmail.com>
parents: 26
diff changeset
572 host, path = uri[len(handler):].split(":", 1)
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
573 host = 'git@' + host
28
b258ef16ae37 Fix non-ssh URI parsing.
Augie Fackler <durin42@gmail.com>
parents: 26
diff changeset
574 else:
35
562fc51b991e we did the same thing, not sure why it conflicted
Scott Chacon <schacon@gmail.com>
parents: 29
diff changeset
575 host, path = uri[len(handler):].split("/", 1)
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
576 return transport(host), '/' + path
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
577 # if its not git or git+ssh, try a local url..
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
578 return SubprocessGitClient(), uri
9
7e776864b301 sorts the commits topologically before converting
Scott Chacon <schacon@gmail.com>
parents: 8
diff changeset
579
40
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
580 def clear(self):
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
581 git_dir = self.repo.join('git')
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
582 mapfile = self.repo.join('git-mapfile')
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
583 if os.path.exists(git_dir):
40
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
584 for root, dirs, files in os.walk(git_dir, topdown=False):
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
585 for name in files:
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
586 os.remove(os.path.join(root, name))
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
587 for name in dirs:
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
588 os.rmdir(os.path.join(root, name))
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
589 os.rmdir(git_dir)
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
590 if os.path.exists(mapfile):
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
591 os.remove(mapfile)