Mercurial > hg-git
annotate git_handler.py @ 215:b5d4d1552765
add some annotations for test coverage
author | Abderrahim Kitouni <a.kitouni@gmail.com> |
---|---|
date | Tue, 07 Jul 2009 17:46:14 +0100 |
parents | 61471faeb7fd |
children | 8d961ea5fc5a |
rev | line source |
---|---|
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
1 import os, sys, math, urllib, re |
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 from dulwich.repo import Repo |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
4 from dulwich.client import SimpleFetchGraphWalker |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
5 from hgext import bookmarks |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
6 from mercurial.i18n import _ |
188
5d48a2310e16
Use mercurial.node.bin instead of dulwich.objects.hex_to_sha
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
187
diff
changeset
|
7 from mercurial.node import hex, bin, nullid |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
8 from mercurial import context |
172
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
9 from dulwich.misc import make_sha |
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 Tag, |
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
14 Tree, |
129
ed4e8c2cd016
cleanup dates handling.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
118
diff
changeset
|
15 format_timezone, |
38
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
16 ) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
17 |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
18 |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
19 class GitHandler(object): |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
20 |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
21 def __init__(self, dest_repo, ui): |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
22 self.repo = dest_repo |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
23 self.ui = ui |
105
41e76444105c
make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
104
diff
changeset
|
24 self.mapfile = 'git-mapfile' |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
25 self.tagsfile = 'git-tags' |
133
f2dfb2bed724
Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
118
diff
changeset
|
26 |
f2dfb2bed724
Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
118
diff
changeset
|
27 if ui.config('git', 'intree'): |
f2dfb2bed724
Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
118
diff
changeset
|
28 self.gitdir = self.repo.wjoin('.git') |
f2dfb2bed724
Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
118
diff
changeset
|
29 else: |
f2dfb2bed724
Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
118
diff
changeset
|
30 self.gitdir = self.repo.join('git') |
f2dfb2bed724
Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
118
diff
changeset
|
31 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
32 self.paths = ui.configitems('paths') |
141
a989866eead8
Make it possible to limit what branches are imported
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
140
diff
changeset
|
33 |
16
58cd05129119
moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents:
14
diff
changeset
|
34 self.init_if_missing() |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
35 self.load_git() |
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
36 self.load_map() |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
37 self.load_tags() |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
38 |
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
39 # make the git data directory |
16
58cd05129119
moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents:
14
diff
changeset
|
40 def init_if_missing(self): |
106
3aa2f6caed16
make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
105
diff
changeset
|
41 if not os.path.exists(self.gitdir): |
3aa2f6caed16
make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
105
diff
changeset
|
42 os.mkdir(self.gitdir) |
3aa2f6caed16
make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
105
diff
changeset
|
43 Repo.init_bare(self.gitdir) |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
44 |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
45 def load_git(self): |
106
3aa2f6caed16
make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
105
diff
changeset
|
46 self.git = Repo(self.gitdir) |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
47 |
14
36e94e805fa7
added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents:
13
diff
changeset
|
48 ## FILE LOAD AND SAVE METHODS |
36e94e805fa7
added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents:
13
diff
changeset
|
49 |
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
|
50 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
|
51 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
|
52 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
|
53 |
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
|
54 def map_hg_get(self, gitsha): |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
55 return self._map_git.get(gitsha) |
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
|
56 |
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
|
57 def map_git_get(self, hgsha): |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
58 return self._map_hg.get(hgsha) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
59 |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
60 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
|
61 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
|
62 self._map_hg = {} |
105
41e76444105c
make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
104
diff
changeset
|
63 if os.path.exists(self.repo.join(self.mapfile)): |
41e76444105c
make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
104
diff
changeset
|
64 for line in self.repo.opener(self.mapfile): |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
69 def save_map(self): |
105
41e76444105c
make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
104
diff
changeset
|
70 file = self.repo.opener(self.mapfile, 'w+', atomictemp=True) |
100
e17d9eea44ab
sort the mapfile before writing
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
99
diff
changeset
|
71 for gitsha, hgsha in sorted(self._map_git.iteritems()): |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
72 file.write("%s %s\n" % (gitsha, hgsha)) |
101
7c57f15d397c
use atomictemp to prevent corruption on ctrl-c
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
100
diff
changeset
|
73 file.rename() |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
74 |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
75 |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
76 def load_tags(self): |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
77 self.tags = {} |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
78 if os.path.exists(self.repo.join(self.tagsfile)): |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
79 for line in self.repo.opener(self.tagsfile): |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
80 sha, name = line.strip().split(' ', 1) |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
81 self.tags[name] = sha |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
82 |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
83 def save_tags(self): |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
84 file = self.repo.opener(self.tagsfile, 'w+', atomictemp=True) |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
85 for name, sha in sorted(self.tags.iteritems()): |
212
174954c187e0
fix pushing tags to git (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
86 if not self.repo.tagtype(name) == 'global': |
174954c187e0
fix pushing tags to git (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
87 file.write("%s %s\n" % (sha, name)) |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
88 file.rename() |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
89 |
14
36e94e805fa7
added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents:
13
diff
changeset
|
90 ## END FILE LOAD AND SAVE METHODS |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
91 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
92 ## COMMANDS METHODS |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
93 |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
94 def import_commits(self, remote_name): |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
95 self.import_git_objects(remote_name) |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
96 self.save_map() |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
97 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
98 def fetch(self, remote): |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
99 self.ui.status(_("fetching from : %s\n") % remote) |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
100 self.export_git_objects() |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
101 refs = self.fetch_pack(remote) |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
102 remote_name = self.remote_name(remote) |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
103 |
56 | 104 if refs: |
149 | 105 self.import_git_objects(remote_name, refs) |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
106 self.import_tags(refs) |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
107 self.update_hg_bookmarks(refs) |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
108 if remote_name: |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
109 self.update_remote_branches(remote_name, refs) |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
110 elif not self.paths: |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
111 # intial cloning |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
112 self.update_remote_branches('default', refs) |
196
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
113 else: |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
114 self.ui.status(_("nothing new on the server\n")) |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
115 |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
116 self.save_map() |
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
117 |
172
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
118 def export_commits(self, export_objects=True): |
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
119 if export_objects: |
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
120 self.export_git_objects() |
147 | 121 self.export_hg_tags() |
97 | 122 self.update_references() |
123 self.save_map() | |
124 | |
196
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
125 def push(self, remote): |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
126 self.fetch(remote) # get and convert objects if they already exist |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
127 self.ui.status(_("pushing to : %s\n") % remote) |
172
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
128 self.export_commits(False) |
196
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
129 changed_refs = self.upload_pack(remote) |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
130 remote_name = self.remote_name(remote) |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
131 |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
132 if remote_name and changed_refs: |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
133 for ref, sha in changed_refs.iteritems(): |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
134 self.ui.status(" "+ remote_name + "::" + ref + " => GIT:" + sha[0:8] + "\n") |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
135 |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
136 self.update_remote_branches(remote_name, changed_refs) |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
137 |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
138 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
139 def clear(self): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
140 mapfile = self.repo.join(self.mapfile) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
141 if os.path.exists(self.gitdir): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
142 for root, dirs, files in os.walk(self.gitdir, topdown=False): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
143 for name in files: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
144 os.remove(os.path.join(root, name)) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
145 for name in dirs: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
146 os.rmdir(os.path.join(root, name)) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
147 os.rmdir(self.gitdir) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
148 if os.path.exists(mapfile): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
149 os.remove(mapfile) |
124
9dafb9ac24ff
hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents:
118
diff
changeset
|
150 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
151 ## CHANGESET CONVERSION METHODS |
125 | 152 |
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
|
153 def export_git_objects(self): |
177
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
154 self.previous_entries = {} |
172
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
155 self.written_trees = {} |
142
ed884cfe3fa3
export: be more clean in what we're doing
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
141
diff
changeset
|
156 self.ui.status(_("importing Hg objects into Git\n")) |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
157 nodes = [self.repo.lookup(n) for n in self.repo] |
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
158 export = [node for node in nodes if not hex(node) in self._map_hg] |
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
159 total = len(export) |
148
201d30003120
Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents:
147
diff
changeset
|
160 if total: |
201d30003120
Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents:
147
diff
changeset
|
161 magnitude = int(math.log(total, 10)) + 1 |
201d30003120
Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents:
147
diff
changeset
|
162 else: |
201d30003120
Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents:
147
diff
changeset
|
163 magnitude = 1 |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
164 for i, rev in enumerate(export): |
99
541571f2e429
add progress indication during export
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
97
diff
changeset
|
165 if i%100 == 0: |
541571f2e429
add progress indication during export
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
97
diff
changeset
|
166 self.ui.status(_("at: %*d/%d\n") % (magnitude, i, total)) |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
167 |
159
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
168 ctx = self.repo.changectx(rev) |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
169 state = ctx.extra().get('hg-git', None) |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
170 if state == 'octopus': |
203
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
171 self.ui.debug("revision %d is a part of octopus explosion\n" % ctx.rev()) |
159
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
172 continue |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
173 self.export_hg_commit(rev) |
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
174 self.save_map() |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
175 |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
176 # 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
|
177 # 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
|
178 # 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
|
179 def export_hg_commit(self, rev): |
159
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
180 def is_octopus_part(ctx): |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
181 return ctx.extra().get('hg-git', None) in set(['octopus', 'octopus-done']) |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
182 |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
183 self.ui.note(_("converting revision %s\n") % rev) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
184 |
203
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
185 oldenc = self.swap_out_encoding() |
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
186 |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
187 # make sure parents are converted first |
159
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
188 ctx = self.repo.changectx(rev) |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
189 extra = ctx.extra() |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
190 |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
191 parents = [] |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
192 if extra.get('hg-git', None) == 'octopus-done': |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
193 # implode octopus parents |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
194 part = ctx |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
195 while is_octopus_part(part): |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
196 (p1, p2) = part.parents() |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
197 assert not is_octopus_part(p1) |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
198 parents.append(p1) |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
199 part = p2 |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
200 parents.append(p2) |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
201 else: |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
202 parents = ctx.parents() |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
203 |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
204 for parent in parents: |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
205 p_node = parent.node() |
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
206 if p_node != nullid and not hex(p_node) in self._map_hg: |
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
207 self.export_hg_commit(p_rev) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
208 |
67
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
209 tree_sha, renames = self.write_git_tree(ctx) |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
210 |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
211 commit = {} |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
212 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
|
213 (time, timezone) = ctx.date() |
68
d28d3763eda3
Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents:
65
diff
changeset
|
214 |
203
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
215 if 'author' in extra: |
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
216 author = extra['author'] |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
217 else: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
218 # hg authors might not have emails |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
219 author = ctx.user() |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
220 |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
221 # check for git author pattern compliance |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
222 regex = re.compile('^(.*?) \<(.*?)\>(.*)$') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
223 a = regex.match(author) |
169
d67d00738298
fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents:
168
diff
changeset
|
224 |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
225 if a: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
226 name = a.group(1) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
227 email = a.group(2) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
228 if len(a.group(3)) > 0: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
229 name += ' ext:(' + urllib.quote(a.group(3)) + ')' |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
230 author = name + ' <' + email + '>' |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
231 else: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
232 author = author + ' <none@none>' |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
233 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
234 commit['author'] = author + ' ' + str(int(time)) + ' ' + format_timezone(-timezone) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
235 |
203
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
236 if 'message' in extra: |
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
237 commit['message'] = extra['message'] |
169
d67d00738298
fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents:
168
diff
changeset
|
238 else: |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
239 message = ctx.description() |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
240 commit['message'] = ctx.description() + "\n" |
65
5ed8316d3cfa
Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents:
56
diff
changeset
|
241 |
89
e35ed99fa691
committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents:
88
diff
changeset
|
242 if 'committer' in extra: |
131
dd6c77ec206c
store commitdate in mercurial's internal format.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
129
diff
changeset
|
243 # fixup timezone |
dd6c77ec206c
store commitdate in mercurial's internal format.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
129
diff
changeset
|
244 (name_timestamp, timezone) = extra['committer'].rsplit(' ', 1) |
140
6701ab807bf5
Deal with invalid timezones in extra commiter
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
138
diff
changeset
|
245 try: |
6701ab807bf5
Deal with invalid timezones in extra commiter
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
138
diff
changeset
|
246 timezone = format_timezone(-int(timezone)) |
6701ab807bf5
Deal with invalid timezones in extra commiter
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
138
diff
changeset
|
247 commit['committer'] = '%s %s' % (name_timestamp, timezone) |
215
b5d4d1552765
add some annotations for test coverage
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
213
diff
changeset
|
248 except ValueError: #pragma: no cover |
199
4a480133b29a
add test for octopus merge conversion
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
196
diff
changeset
|
249 self.ui.warn(_("Ignoring committer in extra, invalid timezone in r%d: '%s'.\n") % (ctx, timezone)) |
118
b3be536e3f50
handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents:
113
diff
changeset
|
250 if 'encoding' in extra: |
b3be536e3f50
handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents:
113
diff
changeset
|
251 commit['encoding'] = extra['encoding'] |
89
e35ed99fa691
committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents:
88
diff
changeset
|
252 |
54
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
253 # 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
|
254 add_extras = False |
67
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
255 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
|
256 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
|
257 add_extras = True |
67
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
258 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
|
259 |
67
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
260 if renames: |
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
261 add_extras = True |
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
262 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
|
263 extra_message += "rename : " + oldfile + " => " + newfile + "\n" |
164
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
264 |
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
265 for key, value in extra.iteritems(): |
203
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
266 if key in ('author', 'committer', 'encoding', 'message', 'branch', 'hg-git'): |
164
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
267 continue |
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
268 else: |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
269 add_extras = True |
164
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
270 extra_message += "extra : " + key + " : " + urllib.quote(value) + "\n" |
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
271 |
54
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
272 if add_extras: |
80
0e0a2d20deed
added a missing newline back to git conversion
Scott Chacon <schacon@gmail.com>
parents:
79
diff
changeset
|
273 commit['message'] += "\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
|
274 |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
275 commit['parents'] = [] |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
276 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
|
277 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
|
278 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
|
279 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
|
280 commit['parents'].append(git_sha) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
281 |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
282 commit_sha = self.git.write_commit_hash(commit) # writing new blobs to git |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
283 self.map_set(commit_sha, ctx.hex()) |
203
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
284 |
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
285 self.swap_out_encoding(oldenc) |
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
286 |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
287 return commit_sha |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
288 |
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
|
289 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
|
290 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
|
291 man = ctx.manifest() |
177
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
292 ctx_id = hex(ctx.node()) |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
293 |
67
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
294 renames = [] |
171
88e413d853ee
fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents:
169
diff
changeset
|
295 for filenm, nodesha in man.iteritems(): |
88e413d853ee
fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents:
169
diff
changeset
|
296 file_id = hex(nodesha) |
177
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
297 if ctx_id not in self.previous_entries: |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
298 self.previous_entries[ctx_id] = {} |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
299 self.previous_entries[ctx_id][filenm] = file_id |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
300 |
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
|
301 # write blob if not in our git database |
177
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
302 fctx = ctx.filectx(filenm) |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
303 |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
304 same_as_last = False |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
305 for par in ctx.parents(): |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
306 par_id = hex(par.node()) |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
307 if par_id in self.previous_entries: |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
308 if filenm in self.previous_entries[par_id]: |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
309 if self.previous_entries[par_id][filenm] == file_id: |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
310 same_as_last = True |
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
311 if not same_as_last: |
171
88e413d853ee
fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents:
169
diff
changeset
|
312 rename = fctx.renamed() |
88e413d853ee
fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents:
169
diff
changeset
|
313 if rename: |
88e413d853ee
fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents:
169
diff
changeset
|
314 filerename, sha = rename |
177
88fdcb23294e
only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents:
176
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 |
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
|
323 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
|
324 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
|
325 # 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
|
326 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
|
327 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
|
328 |
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
|
329 # 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
|
330 parpath = '/' |
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
331 nparpath = '/' |
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
332 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
|
333 if nparpath == '/': |
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
334 nparpath = part + '/' |
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
335 else: |
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
336 nparpath += part + '/' |
65
5ed8316d3cfa
Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents:
56
diff
changeset
|
337 |
54
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
338 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
|
339 |
54
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
340 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
|
341 trees[parpath] = [] |
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
342 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
|
343 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
|
344 |
54
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
345 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
|
346 |
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
|
347 # 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 |
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
|
353 else: |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
354 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
|
355 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
|
356 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
|
357 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
|
358 |
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
|
359 dirs = trees.keys() |
122
76a0e1ee7cf7
don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
121
diff
changeset
|
360 if dirs: |
76a0e1ee7cf7
don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
121
diff
changeset
|
361 # sort by tree depth, so we write the deepest trees first |
76a0e1ee7cf7
don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
121
diff
changeset
|
362 dirs.sort(lambda a, b: len(b.split('/'))-len(a.split('/'))) |
76a0e1ee7cf7
don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
121
diff
changeset
|
363 dirs.remove('/') |
76a0e1ee7cf7
don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
121
diff
changeset
|
364 dirs.append('/') |
76a0e1ee7cf7
don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
121
diff
changeset
|
365 else: |
76a0e1ee7cf7
don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
121
diff
changeset
|
366 # manifest is empty => make empty root tree |
76a0e1ee7cf7
don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
121
diff
changeset
|
367 trees['/'] = [] |
76a0e1ee7cf7
don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
121
diff
changeset
|
368 dirs = ['/'] |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
369 |
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
|
370 # 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
|
371 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
|
372 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
|
373 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
|
374 tree_data = [] |
172
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
375 sha_group = [] |
176
814499406d4c
fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents:
174
diff
changeset
|
376 |
814499406d4c
fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents:
174
diff
changeset
|
377 # calculating a sha for the tree, so we don't write it twice |
814499406d4c
fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents:
174
diff
changeset
|
378 listsha = make_sha() |
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
|
379 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
|
380 # 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
|
381 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
|
382 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
|
383 entry[2] = sha |
176
814499406d4c
fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents:
174
diff
changeset
|
384 listsha.update(entry[1]) |
814499406d4c
fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents:
174
diff
changeset
|
385 listsha.update(entry[2]) |
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
|
386 tree_data.append(entry) |
172
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
387 listsha = listsha.hexdigest() |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
388 |
172
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
389 if listsha in self.written_trees: |
176
814499406d4c
fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents:
174
diff
changeset
|
390 tree_sha = self.written_trees[listsha] |
814499406d4c
fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents:
174
diff
changeset
|
391 tree_shas[dirnm] = tree_sha |
172
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
392 else: |
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
393 tree_sha = self.git.write_tree_array(tree_data) # writing new trees to git |
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
394 tree_shas[dirnm] = tree_sha |
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
395 self.written_trees[listsha] = tree_sha |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
396 |
67
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
397 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
|
398 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
399 def import_git_objects(self, remote_name=None, refs=None): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
400 self.ui.status(_("importing Git objects into Hg\n")) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
401 # import heads and fetched tags as remote references |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
402 todo = [] |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
403 done = set() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
404 convert_list = {} |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
405 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
406 # get a list of all the head shas |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
407 if refs: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
408 for head, sha in refs.iteritems(): |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
409 todo.append(sha) |
195
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
410 elif remote_name: |
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
411 todo = self.git.remote_refs(remote_name).values()[:] |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
412 else: |
195
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
413 todo = self.git.heads().values()[:] |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
414 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
415 # traverse the heads getting a list of all the unique commits |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
416 while todo: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
417 sha = todo.pop() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
418 assert isinstance(sha, str) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
419 if sha in done: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
420 continue |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
421 done.add(sha) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
422 obj = self.git.get_object(sha) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
423 if isinstance (obj, Commit): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
424 convert_list[sha] = obj |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
425 todo.extend([p for p in obj.parents if p not in done]) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
426 if isinstance(obj, Tag): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
427 (obj_type, obj_sha) = obj.get_object() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
428 obj = self.git.get_object(obj_sha) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
429 if isinstance (obj, Commit): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
430 convert_list[sha] = obj |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
431 todo.extend([p for p in obj.parents if p not in done]) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
432 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
433 # sort the commits |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
434 commits = toposort.TopoSort(convert_list).items() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
435 |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
436 commits = [commit for commit in commits if not commit in self._map_git] |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
437 # import each of the commits, oldest first |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
438 total = len(commits) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
439 magnitude = int(math.log(total, 10)) + 1 if total else 1 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
440 for i, csha in enumerate(commits): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
441 if i%100 == 0: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
442 self.ui.status(_("at: %*d/%d\n") % (magnitude, i, total)) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
443 commit = convert_list[csha] |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
444 self.import_git_commit(commit) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
445 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
446 def import_git_commit(self, commit): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
447 self.ui.debug(_("importing: %s\n") % commit.id) |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
448 # TODO: Do something less coarse-grained than try/except on the |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
449 # get_file call for removed files |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
450 |
204
4734153365ac
revert the changes made in 405a915bf352 and 8bfa8aa6b68f
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
203
diff
changeset
|
451 (strip_message, hg_renames, hg_branch, extra) = self.extract_hg_metadata(commit.message) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
452 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
453 # get a list of the changed, added, removed files |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
454 files = self.git.get_files_changed(commit) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
455 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
456 date = (commit.author_time, -commit.author_timezone) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
457 text = strip_message |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
458 |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
459 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
460 text.decode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
461 except UnicodeDecodeError: |
203
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
462 extra['message'] = text |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
463 text = self.decode_guess(text, commit._encoding) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
464 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
465 author = commit.author |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
466 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
467 # convert extra data back to the end |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
468 if ' ext:' in commit.author: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
469 regex = re.compile('^(.*?)\ ext:\((.*)\) <(.*)\>$') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
470 m = regex.match(commit.author) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
471 if m: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
472 name = m.group(1) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
473 ex = urllib.unquote(m.group(2)) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
474 email = m.group(3) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
475 author = name + ' <' + email + '>' + ex |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
476 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
477 if ' <none@none>' in commit.author: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
478 author = commit.author[:-12] |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
479 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
480 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
481 author.decode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
482 except UnicodeDecodeError: |
203
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
483 extra['author'] = author |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
484 author = self.decode_guess(author, commit._encoding) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
485 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
486 oldenc = self.swap_out_encoding() |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
487 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
488 def getfilectx(repo, memctx, f): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
489 try: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
490 (mode, sha, data) = self.git.get_file(commit, f) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
491 e = self.convert_git_int_mode(mode) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
492 except TypeError: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
493 raise IOError() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
494 if f in hg_renames: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
495 copied_path = hg_renames[f] |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
496 else: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
497 copied_path = None |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
498 return context.memfilectx(f, data, 'l' in e, 'x' in e, copied_path) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
499 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
500 gparents = map(self.map_hg_get, commit.parents) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
501 p1, p2 = (nullid, nullid) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
502 octopus = False |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
503 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
504 if len(gparents) > 1: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
505 # merge, possibly octopus |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
506 def commit_octopus(p1, p2): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
507 ctx = context.memctx(self.repo, (p1, p2), text, files, getfilectx, |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
508 author, date, {'hg-git': 'octopus'}) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
509 return hex(self.repo.commitctx(ctx)) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
510 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
511 octopus = len(gparents) > 2 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
512 p2 = gparents.pop() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
513 p1 = gparents.pop() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
514 while len(gparents) > 0: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
515 p2 = commit_octopus(p1, p2) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
516 p1 = gparents.pop() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
517 else: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
518 if gparents: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
519 p1 = gparents.pop() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
520 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
521 files = list(set(files)) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
522 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
523 pa = None |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
524 if not (p2 == nullid): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
525 node1 = self.repo.changectx(p1) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
526 node2 = self.repo.changectx(p2) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
527 pa = node1.ancestor(node2) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
528 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
529 # if named branch, add to extra |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
530 if hg_branch: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
531 extra['branch'] = hg_branch |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
532 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
533 # if committer is different than author, add it to extra |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
534 if not commit._author_raw == commit._committer_raw: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
535 extra['committer'] = "%s %d %d" % (commit.committer, commit.commit_time, -commit.commit_timezone) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
536 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
537 if commit._encoding: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
538 extra['encoding'] = commit._encoding |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
539 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
540 if hg_branch: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
541 extra['branch'] = hg_branch |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
542 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
543 if octopus: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
544 extra['hg-git'] ='octopus-done' |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
545 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
546 ctx = context.memctx(self.repo, (p1, p2), text, files, getfilectx, |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
547 author, date, extra) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
548 |
204
4734153365ac
revert the changes made in 405a915bf352 and 8bfa8aa6b68f
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
203
diff
changeset
|
549 node = self.repo.commit_import_ctx(ctx, pa) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
550 |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
551 self.swap_out_encoding(oldenc) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
552 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
553 # save changeset to mapping file |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
554 cs = hex(node) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
555 self.map_set(commit.id, cs) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
556 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
557 ## PACK UPLOADING AND FETCHING |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
558 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
559 def upload_pack(self, remote): |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
560 client, path = self.get_transport_and_path(remote) |
37
7046d792dfcd
fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents:
35
diff
changeset
|
561 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
|
562 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
|
563 try: |
95
7de67fcb18b0
be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
94
diff
changeset
|
564 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
|
565 changed_refs = client.send_pack(path, changed, genpack) |
207
c06ac5b982a9
add a test for pushing to git
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
204
diff
changeset
|
566 return 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
|
567 except: |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
568 # TODO: remove try/except or do something useful here |
26
a1a5391bc3c3
edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents:
25
diff
changeset
|
569 raise |
37
7046d792dfcd
fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents:
35
diff
changeset
|
570 |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
571 # 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
|
572 # * 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
|
573 # 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
|
574 # pushed up |
7046d792dfcd
fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents:
35
diff
changeset
|
575 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
|
576 keys = refs.keys() |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
577 |
88
52b4be85151d
fixed some small compatability issues with the dulwich update
Scott Chacon <schacon@gmail.com>
parents:
80
diff
changeset
|
578 changed = {} |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
579 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
|
580 return None |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
581 |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
582 # TODO: this is a huge hack |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
583 if keys[0] == 'capabilities^{}': |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
584 # nothing on the server yet - first push |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
585 if not 'master' in self.repo.tags(): |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
586 tip = self.repo.lookup('tip') |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
587 changed['refs/heads/master'] = self.map_git_get(hex(tip)) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
588 |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
589 for tag, sha in self.tags.iteritems(): |
153
4e7c50f8b60a
dont export funky tags we import for convenience, dont push tags already on the server
Scott Chacon <schacon@gmail.com>
parents:
150
diff
changeset
|
590 tag_name = 'refs/tags/' + tag |
4e7c50f8b60a
dont export funky tags we import for convenience, dont push tags already on the server
Scott Chacon <schacon@gmail.com>
parents:
150
diff
changeset
|
591 if tag_name not in refs: |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
592 changed[tag_name] = self.map_git_get(sha) |
149 | 593 |
37
7046d792dfcd
fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents:
35
diff
changeset
|
594 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
|
595 parts = ref_name.split('/') |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
596 if parts[0] == 'refs' and parts[1] == 'heads': |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
597 # strip off 'refs/heads' |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
598 head = "/".join([v for v in parts[2:]]) |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
599 try: |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
600 local_ref = self.repo.lookup(head) |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
601 remote_ref = self.map_hg_get(refs[ref_name]) |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
602 if remote_ref: |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
603 remotectx = self.repo[remote_ref] |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
604 localctx = self.repo[local_ref] |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
605 if remotectx.ancestor(localctx) == remotectx: |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
606 # fast forward push |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
607 changed[ref_name] = self.map_git_get(hex(local_ref)) |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
608 else: |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
609 # XXX: maybe abort completely |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
610 ui.warn('not pushing branch %s, please merge'% head) |
215
b5d4d1552765
add some annotations for test coverage
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
213
diff
changeset
|
611 except RepoError: #pragma: no cover |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
612 # remote_ref is not here |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
613 pass |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
614 |
126 | 615 # Also push any local branches not on the server yet |
616 for head in self.local_heads(): | |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
617 ref = 'refs/heads/' + head |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
618 if not ref in refs: |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
619 node = self.repo.lookup(head) |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
620 changed[ref] = self.map_git_get(hex(node)) |
126 | 621 |
37
7046d792dfcd
fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents:
35
diff
changeset
|
622 return changed |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
623 |
37
7046d792dfcd
fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents:
35
diff
changeset
|
624 # 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
|
625 # 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
|
626 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
|
627 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
|
628 next = graph_walker.next() |
77
d7b8768d005a
reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents:
76
diff
changeset
|
629 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
|
630 while next: |
7046d792dfcd
fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents:
35
diff
changeset
|
631 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
|
632 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
|
633 else: |
77
d7b8768d005a
reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents:
76
diff
changeset
|
634 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
|
635 next = graph_walker.next() |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
636 |
77
d7b8768d005a
reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents:
76
diff
changeset
|
637 seen = [] |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
638 |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
639 # 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
|
640 # tuples (sha, path) for ALL the objects i'm sending |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
641 # TODO: don't send blobs or trees they already have |
38
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
642 def get_objects(tree, path): |
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
643 changes = list() |
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
644 changes.append((tree, path)) |
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
645 for (mode, name, sha) in tree.entries(): |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
646 if mode == 0160000: # TODO: properly handle submodules and document what 57344 means |
38
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
647 continue |
77
d7b8768d005a
reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents:
76
diff
changeset
|
648 if sha in seen: |
d7b8768d005a
reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents:
76
diff
changeset
|
649 continue |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
650 |
38
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
651 obj = self.git.get_object(sha) |
77
d7b8768d005a
reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents:
76
diff
changeset
|
652 seen.append(sha) |
76
aa2dadf04144
fixed the topo sorting and added a unit test
Scott Chacon <schacon@gmail.com>
parents:
75
diff
changeset
|
653 if isinstance (obj, Blob): |
38
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
654 changes.append((obj, path + name)) |
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
655 elif isinstance(obj, Tree): |
77
d7b8768d005a
reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents:
76
diff
changeset
|
656 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
|
657 return changes |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
658 |
38
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
659 objects = [] |
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
660 for commit_sha in shas: |
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
661 commit = self.git.commit(commit_sha) |
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
662 objects.append((commit, 'commit')) |
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
663 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
|
664 objects.extend( get_objects(tree, '/') ) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
665 |
38
f0daee676e10
successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents:
37
diff
changeset
|
666 return objects |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
667 |
12
227b11d75844
updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents:
11
diff
changeset
|
668 def fetch_pack(self, remote_name): |
182
9bdd8e76bbab
Remove remotes support (use the paths section in hgrc instead)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
181
diff
changeset
|
669 client, path = self.get_transport_and_path(remote_name) |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
670 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
|
671 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
|
672 try: |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
673 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
|
674 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
|
675 f.close() |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
676 commit() |
56 | 677 return refs |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
678 finally: |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
679 f.close() |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
680 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
681 ## REFERENCES HANDLING |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
682 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
683 def update_references(self): |
195
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
684 heads = self.local_heads() |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
685 |
195
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
686 # Create a local Git branch name for each |
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
687 # Mercurial bookmark. |
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
688 for key in heads: |
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
689 self.git.set_ref('refs/heads/' + key, heads[key]) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
690 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
691 def export_hg_tags(self): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
692 for tag, sha in self.repo.tags().iteritems(): |
210
9a27c618d0ed
remove broken tagging code (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
207
diff
changeset
|
693 if self.repo.tagtype(tag) in ('global', 'git'): |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
694 self.git.set_ref('refs/tags/' + tag, self.map_git_get(hex(sha))) |
212
174954c187e0
fix pushing tags to git (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
695 self.tags[tag] = hex(sha) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
696 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
697 def local_heads(self): |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
698 try: |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
699 bms = bookmarks.parse(self.repo) |
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
700 return dict([(bm, self.map_git_get(hex(bms[bm]))) for bm in bms]) |
215
b5d4d1552765
add some annotations for test coverage
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
213
diff
changeset
|
701 except AttributeError: #pragma: no cover |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
702 return {} |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
703 |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
704 def import_tags(self, refs): |
149 | 705 keys = refs.keys() |
706 if not keys: | |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
707 return |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
708 for k in keys[:]: |
149 | 709 ref_name = k |
710 parts = k.split('/') | |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
711 if parts[0] == 'refs' and parts[1] == 'tags': |
149 | 712 ref_name = "/".join([v for v in parts[2:]]) |
713 if ref_name[-3:] == '^{}': | |
714 ref_name = ref_name[:-3] | |
715 if not ref_name in self.repo.tags(): | |
716 obj = self.git.get_object(refs[k]) | |
717 sha = None | |
718 if isinstance (obj, Commit): # lightweight | |
719 sha = self.map_hg_get(refs[k]) | |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
720 self.tags[ref_name] = sha |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
721 elif isinstance (obj, Tag): # annotated |
149 | 722 (obj_type, obj_sha) = obj.get_object() |
723 obj = self.git.get_object(obj_sha) | |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
724 if isinstance (obj, Commit): |
149 | 725 sha = self.map_hg_get(obj_sha) |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
726 # TODO: better handling for annotated tags |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
727 self.tags[ref_name] = sha |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
728 self.save_tags() |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
729 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
730 def update_hg_bookmarks(self, refs): |
29
2a5c0bf0fef5
Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
731 try: |
47
3b62270c1fad
writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents:
42
diff
changeset
|
732 bms = bookmarks.parse(self.repo) |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
733 heads = dict([(ref[11:],refs[ref]) for ref in refs |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
734 if ref.startswith('refs/heads/')]) |
156
a507384308b2
Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
155
diff
changeset
|
735 |
a507384308b2
Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
155
diff
changeset
|
736 for head, sha in heads.iteritems(): |
188
5d48a2310e16
Use mercurial.node.bin instead of dulwich.objects.hex_to_sha
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
187
diff
changeset
|
737 hgsha = bin(self.map_hg_get(sha)) |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
738 if not head in bms: |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
739 # new branch |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
740 bms[head] = hgsha |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
741 else: |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
742 bm = self.repo[bms[head]] |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
743 if bm.ancestor(self.repo[hgsha]) == bm: |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
744 # fast forward |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
745 bms[head] = hgsha |
156
a507384308b2
Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
155
diff
changeset
|
746 if heads: |
a507384308b2
Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
155
diff
changeset
|
747 bookmarks.write(self.repo, bms) |
161
134915637cf7
Merge branch 'octo' with octo merge code
Scott Chacon <schacon@gmail.com>
diff
changeset
|
748 |
29
2a5c0bf0fef5
Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
749 except AttributeError: |
95
7de67fcb18b0
be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
94
diff
changeset
|
750 self.ui.warn(_('creating bookmarks failed, do you have' |
7de67fcb18b0
be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
94
diff
changeset
|
751 ' bookmarks enabled?\n')) |
65
5ed8316d3cfa
Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents:
56
diff
changeset
|
752 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
753 def update_remote_branches(self, remote_name, refs): |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
754 heads = dict([(ref[11:],refs[ref]) for ref in refs |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
755 if ref.startswith('refs/heads/')]) |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
756 |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
757 for head, sha in heads.iteritems(): |
188
5d48a2310e16
Use mercurial.node.bin instead of dulwich.objects.hex_to_sha
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
187
diff
changeset
|
758 hgsha = bin(self.map_hg_get(sha)) |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
759 tag = '%s/%s' % (remote_name, head) |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
760 self.repo.tag(tag, hgsha, '', True, None, None) |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
761 |
196
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
762 self.git.set_remote_refs(refs, remote_name) |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
763 |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
764 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
765 ## UTILITY FUNCTIONS |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
766 |
53
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
767 def convert_git_int_mode(self, mode): |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
768 # TODO: make these into constants |
53
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
769 convert = { |
121
0c94e860a0ed
use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
120
diff
changeset
|
770 0100644: '', |
0c94e860a0ed
use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
120
diff
changeset
|
771 0100755: 'x', |
0c94e860a0ed
use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
120
diff
changeset
|
772 0120000: 'l'} |
53
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
773 if mode in convert: |
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
774 return convert[mode] |
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
775 return '' |
65
5ed8316d3cfa
Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents:
56
diff
changeset
|
776 |
71
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
777 def extract_hg_metadata(self, message): |
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
778 split = message.split("\n\n--HG--\n", 1) |
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
779 renames = {} |
164
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
780 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
|
781 branch = False |
71
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
782 if len(split) == 2: |
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
783 message, meta = split |
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
784 lines = meta.split("\n") |
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
785 for line in lines: |
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
786 if line == '': |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
787 continue |
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
788 |
71
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
789 command, data = line.split(" : ", 1) |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
790 |
71
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
791 if command == 'rename': |
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
792 before, after = data.split(" => ", 1) |
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
793 renames[after] = before |
19053d11d520
explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents:
70
diff
changeset
|
794 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
|
795 branch = data |
164
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
796 if command == 'extra': |
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
797 before, after = data.split(" : ", 1) |
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
798 extra[before] = urllib.unquote(after) |
204
4734153365ac
revert the changes made in 405a915bf352 and 8bfa8aa6b68f
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
203
diff
changeset
|
799 return (message, renames, branch, extra) |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
800 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
801 def remote_name(self, remote): |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
802 names = [name for name, path in self.paths if path == remote] |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
803 if names: |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
804 return names[0] |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
805 |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
806 # Stolen from hgsubversion |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
807 def swap_out_encoding(self, new_encoding='UTF-8'): |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
808 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
809 from mercurial import encoding |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
810 old = encoding.encoding |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
811 encoding.encoding = new_encoding |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
812 except ImportError: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
813 old = hgutil._encoding |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
814 hgutil._encoding = new_encoding |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
815 return old |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
816 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
817 def decode_guess(self, string, encoding): |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
818 # text is not valid utf-8, try to make sense of it |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
819 if encoding: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
820 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
821 return string.decode(encoding).encode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
822 except UnicodeDecodeError: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
823 pass |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
824 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
825 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
826 return string.decode('latin-1').encode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
827 except UnicodeDecodeError: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
828 return string.decode('ascii', 'replace').encode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
829 |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
830 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
|
831 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
|
832 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
|
833 if uri.startswith(handler): |
215
b5d4d1552765
add some annotations for test coverage
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
213
diff
changeset
|
834 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
|
835 return transport(host), '/' + path |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
836 # 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
|
837 return SubprocessGitClient(), uri |