remote-bzr: add support for fecthing special modes

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Nov 11, 2012 at 15:19 UTC bdeeb809d75b71bc9bdc3ed1b4ebc64e3d965840
2 files changed +59 -11
contrib/remote-helpers/git-remote-bzr
+27 -11
@@ -198,23 +198,39 @@ def export_files(tree, files):
198
199 final = []
200 for path, fid in files.iteritems():
201 + kind = tree.kind(fid)
202 +
203 h = tree.get_file_sha1(fid)
204
203 - mode = '100644'
205 + if kind == 'symlink':
206 + d = tree.get_symlink_target(fid)
207 + mode = '120000'
208 + elif kind == 'file':
209 +
210 + if tree.is_executable(fid):
211 + mode = '100755'
212 + else:
213 + mode = '100644'
214 +
215 + # is the blog already exported?
216 + if h in filenodes:
217 + mark = filenodes[h]
218 + final.append((mode, mark, path))
219 + continue
220
205 - # is the blob already exported?
206 - if h in filenodes:
207 - mark = filenodes[h]
208 - else:
221 d = tree.get_file_text(fid)
222 + elif kind == 'directory':
223 + continue
224 + else:
225 + die("Unhandled kind '%s' for path '%s'" % (kind, path))
226
211 - mark = marks.next_mark()
212 - filenodes[h] = mark
227 + mark = marks.next_mark()
228 + filenodes[h] = mark
229
214 - print "blob"
215 - print "mark :%u" % mark
216 - print "data %d" % len(d)
217 - print d
230 + print "blob"
231 + print "mark :%u" % mark
232 + print "data %d" % len(d)
233 + print d
234
235 final.append((mode, mark, path))
236
contrib/remote-helpers/test-bzr.sh
+32
@@ -108,4 +108,36 @@ test_expect_success 'roundtrip' '
108 test_cmp expected actual
109 '
110
111 +cat > expected <<EOF
112 +100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content
113 +100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable
114 +120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link
115 +EOF
116 +
117 +test_expect_success 'special modes' '
118 + (cd bzrrepo &&
119 + echo exec > executable
120 + chmod +x executable &&
121 + bzr add executable
122 + bzr commit -m exec &&
123 + ln -s content link
124 + bzr add link
125 + bzr commit -m link &&
126 + mkdir dir &&
127 + bzr add dir &&
128 + bzr commit -m dir) &&
129 +
130 + (cd gitrepo &&
131 + git pull
132 + git ls-tree HEAD > ../actual) &&
133 +
134 + test_cmp expected actual &&
135 +
136 + (cd gitrepo &&
137 + git cat-file -p HEAD:link > ../actual) &&
138 +
139 + echo -n content > expected &&
140 + test_cmp expected actual
141 +'
142 +
143 test_done