Kiln » Kiln Extensions
Clone URL:  
Pushed to 2 repositories · View In Graph Contained in tip

upgrade extensions to Kiln 2.5.163

Changeset 35d64ba16cb6

Parent bf74641d43fb

by Profile picture of User 12Benjamin Pollack <benjamin@fogcreek.com>

Changes to 12 files · Browse files at 35d64ba16cb6 Showing diff from parent bf74641d43fb Diff from another changeset...

 
21
22
23
 
 
24
25
 
26
27
28
 
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
24
25
26
27
28
29
30
31
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@@ -21,8 +21,11 @@
 '''    from mercurial import commands +from mercurial import wireproto +  import bfsetup  import bfcommands +import bfproto    reposetup = bfsetup.reposetup  uisetup = bfsetup.uisetup @@ -30,3 +33,14 @@
 commands.norepo += " kbfconvert"    cmdtable = bfcommands.cmdtable + +def extsetup(ui): + wireproto.commands['putbfile'] = (bfproto.putbfile, 'sha') + wireproto.commands['getbfile'] = (bfproto.getbfile, 'sha') + wireproto.commands['statbfile'] = (bfproto.statbfile, 'sha') + wireproto.commands['capabilities'] = (bfproto.capabilities, '') + wireproto.dispatch = bfproto.dispatch + + wireproto.wirerepository.putbfile = bfproto.wirerepo_putbfile + wireproto.wirerepository.getbfile = bfproto.wirerepo_getbfile + wireproto.wirerepository.statbfile = bfproto.wirerepo_statbfile
 
20
21
22
23
24
25
 
 
 
 
 
 
 
 
26
27
28
 
74
75
76
 
77
78
79
 
157
158
159
160
161
162
163
164
165
 
 
 
 
 
 
 
 
166
167
168
 
176
177
178
179
 
180
181
182
 
20
21
22
 
 
 
23
24
25
26
27
28
29
30
31
32
33
 
79
80
81
82
83
84
85
 
163
164
165
 
 
 
 
 
 
166
167
168
169
170
171
172
173
174
175
176
 
184
185
186
 
187
188
189
190
@@ -20,9 +20,14 @@
  self.detail = detail     def longmessage(self): - return ("%s: %s\n" - "(failed URL: %s)\n" - % (self.filename, self.detail, self.url)) + if self.url: + return ('%s: %s\n' + '(failed URL: %s)\n' + % (self.filename, self.detail, self.url)) + else: + return ('%s: %s\n' + '(no default or default-push path set in hgrc)\n' + % (self.filename, self.detail))     def __str__(self):   return "%s: %s" % (self.url, self.detail) @@ -74,6 +79,7 @@
  try:   bhash = self._getfile(tmpfile, filename, hash)   except StoreError, err: + tmpfile.close()   ui.warn(err.longmessage())   os.remove(tmpfilename)   missing.append(filename) @@ -157,12 +163,14 @@
 def _openstore(repo, path=None, put=False):   ui = repo.ui   if not path: - path = ui.expandpath('default-push', 'default') - # If 'default-push' and 'default' can't be expanded - # they are just returned. In that case use the empty string which - # use the filescheme. - if path is 'default-push' or path is 'default': - path = '' + path = getattr(repo, 'bfpullsource', None) + if not path: + path = ui.expandpath('default-push', 'default') + # If 'default-push' and 'default' can't be expanded + # they are just returned. In that case fail with an informative + # error message + if path in ('default-push', 'default'): + path = ''     # The path could be a scheme so use Mercurial's normal functionality   # to resolve the scheme to a repository and use its path @@ -176,7 +184,7 @@
  scheme = match.group(1)     try: - (mod, klass) = _storeprovider[scheme] + mod, klass = _storeprovider[scheme]   except KeyError:   raise util.Abort(_('unsupported URL scheme %r') % scheme)  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
 
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
 
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
 '''High-level command functions: bfadd() et. al, plus the cmdtable.'''    import os  import shutil    from mercurial import util, match as match_, hg, node, context, error  from mercurial.i18n import _    import bfutil, basestore    # -- Commands ----------------------------------------------------------    def bfconvert(ui, src, dest, *pats, **opts):   '''Convert a repository to a repository using bfiles     Convert source repository creating an identical   repository, except that all files that match the   patterns given, or are over a given size will   be added as bfiles. The size of a file is the size of the   first version of the file. After running this command you   will need to set the store then run bfput on the new   repository to upload the bfiles to the central store.   '''     if opts['tonormal']:   tobfile = False   else:   tobfile = True   size = opts['size']   if not size:   size = ui.config(bfutil.longname, 'size', default=None)   try:   size = int(size)   except ValueError:   raise util.Abort(_('bfiles.size must be integer, was %s\n') % size)   except TypeError:   raise util.Abort(_('size must be specified'))     try:   rsrc = hg.repository(ui, src)   if not rsrc.local():   raise util.Abort(_('%s is not a local Mercurial repo') % src)   except error.RepoError, err:   ui.traceback()   raise util.Abort(err.args[0])   if os.path.exists(dest):   if not os.path.isdir(dest):   raise util.Abort(_('destination %s already exists') % dest)   elif os.listdir(dest):   raise util.Abort(_('destination %s is not empty') % dest)   try:   ui.status(_('initializing destination %s\n') % dest)   rdst = hg.repository(ui, dest, create=True)   if not rdst.local():   raise util.Abort(_('%s is not a local Mercurial repo') % dest)   except error.RepoError:   ui.traceback()   raise util.Abort(_('%s is not a repo') % dest)     try:   # Lock destination to prevent modification while it is converted to.   # Don't need to lock src because we are just reading from its history   # which can't change.   dst_lock = rdst.lock()     # Get a list of all changesets in the source. The easy way to do this   # is to simply walk the changelog, using changelog.nodesbewteen().   # Take a look at mercurial/revlog.py:639 for more details.   # Use a generator instead of a list to decrease memory usage   ctxs = (rsrc[ctx] for ctx in rsrc.changelog.nodesbetween(None, rsrc.heads())[0])   revmap = {node.nullid: node.nullid}   if tobfile:   bfiles = set()   normalfiles = set()   if not pats:   pats = ui.config(bfutil.longname, 'patterns', default=())   if pats:   pats = pats.split(' ')   if pats:   matcher = match_.match(rsrc.root, '', list(pats))   else:   matcher = None     bfiletohash = {}   for ctx in ctxs:   ui.progress(_('converting revisions'), ctx.rev(), unit=_('revision'), total=rsrc['tip'].rev())   _bfconvert_addchangeset(rsrc, rdst, ctx, revmap,   bfiles, normalfiles, matcher, size, bfiletohash)   ui.progress(_('converting revisions'), None)     if os.path.exists(rdst.wjoin(bfutil.shortname)):   shutil.rmtree(rdst.wjoin(bfutil.shortname))     for f in bfiletohash.keys():   if os.path.isfile(rdst.wjoin(f)):   os.unlink(rdst.wjoin(f))   try:   os.removedirs(os.path.dirname(rdst.wjoin(f)))   except:   pass     else:   for ctx in ctxs:   ui.progress(_('converting revisions'), ctx.rev(), unit=_('revision'), total=rsrc['tip'].rev())   _addchangeset(ui, rsrc, rdst, ctx, revmap)     ui.progress(_('converting revisions'), None)   except:   # we failed, remove the new directory   shutil.rmtree(rdst.root)   raise   finally:   dst_lock.release()    def _addchangeset(ui, rsrc, rdst, ctx, revmap):   # Convert src parents to dst parents   parents = []   for p in ctx.parents():   parents.append(revmap[p.node()])   while len(parents) < 2:   parents.append(node.nullid)     # Generate list of changed files   files = set(ctx.files())   if node.nullid not in parents:   mc = ctx.manifest()   mp1 = ctx.parents()[0].manifest()   mp2 = ctx.parents()[1].manifest()   for f in mp1:   if f not in mc:   files.add(f)   for f in mp2:   if f not in mc:   files.add(f)   for f in mc:   if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):   files.add(f)     def getfilectx(repo, memctx, f):   if bfutil.standin(f) in files:   # if the file isn't in the manifest then it was removed   # or renamed, raise IOError to indicate this   try:   fctx = ctx.filectx(bfutil.standin(f))   except error.LookupError:   raise IOError()   renamed = fctx.renamed()   if renamed:   renamed = bfutil.splitstandin(renamed[0])     hash = fctx.data().strip()   path = bfutil.findfile(rsrc, hash)   ### TODO: What if the file is not cached?   data = ''   with open(path, 'rb') as fd:   data = fd.read()   return context.memfilectx(f, data, 'l' in fctx.flags(),   'x' in fctx.flags(), renamed)   else:   try:   fctx = ctx.filectx(f)   except error.LookupError:   raise IOError()   renamed = fctx.renamed()   if renamed:   renamed = renamed[0]   data = fctx.data()   if f == '.hgtags':   newdata = []   for line in data.splitlines():   id, name = line.split(' ', 1)   newdata.append('%s %s\n' % (node.hex(revmap[node.bin(id)]), name))   data = ''.join(newdata)   return context.memfilectx(f, data, 'l' in fctx.flags(),   'x' in fctx.flags(), renamed)     dstfiles = []   for file in files:   if bfutil.isstandin(file):   dstfiles.append(bfutil.splitstandin(file))   else:   dstfiles.append(file)   # Commit   mctx = context.memctx(rdst, parents, ctx.description(), dstfiles,   getfilectx, ctx.user(), ctx.date(), ctx.extra())   ret = rdst.commitctx(mctx)   rdst.dirstate.setparents(ret)   revmap[ctx.node()] = rdst.changelog.tip()    def _bfconvert_addchangeset(rsrc, rdst, ctx, revmap, bfiles, normalfiles, matcher, size, bfiletohash):   # Convert src parents to dst parents   parents = []   for p in ctx.parents():   parents.append(revmap[p.node()])   while len(parents) < 2:   parents.append(node.nullid)     # Generate list of changed files   files = set(ctx.files())   if node.nullid not in parents:   mc = ctx.manifest()   mp1 = ctx.parents()[0].manifest()   mp2 = ctx.parents()[1].manifest()   for f in mp1:   if f not in mc:   files.add(f)   for f in mp2:   if f not in mc:   files.add(f)   for f in mc:   if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):   files.add(f)     dstfiles = []   for f in files:   if f not in bfiles and f not in normalfiles:   isbfile = _isbfile(f, ctx, matcher, size)   # If this file was renamed or copied then copy   # the bfileness of its predecessor   if f in ctx.manifest():   fctx = ctx.filectx(f)   renamed = fctx.renamed()   renamedbfile = renamed and renamed[0] in bfiles   isbfile |= renamedbfile   if 'l' in fctx.flags():   if renamedbfile:   raise util.Abort(_('Renamed/copied bfile %s becomes symlink') % f)   isbfile = False   if isbfile:   bfiles.add(f)   else:   normalfiles.add(f)     if f in bfiles:   dstfiles.append(bfutil.standin(f))   # bfile in manifest if it has not been removed/renamed   if f in ctx.manifest():   if 'l' in ctx.filectx(f).flags():   if renamed and renamed[0] in bfiles:   raise util.Abort(_('bfile %s becomes symlink') % f)     # bfile was modified, update standins   fullpath = rdst.wjoin(f)   bfutil.createdir(os.path.dirname(fullpath))   m = util.sha1('')   m.update(ctx[f].data())   hash = m.hexdigest()   if f not in bfiletohash or bfiletohash[f] != hash:   with open(fullpath, 'wb') as fd:   fd.write(ctx[f].data())   executable = 'x' in ctx[f].flags()   os.chmod(fullpath, bfutil.getmode(executable))   bfutil.writestandin(rdst, bfutil.standin(f), hash, executable)   bfiletohash[f] = hash   else:   # normal file   dstfiles.append(f)     def getfilectx(repo, memctx, f):   if bfutil.isstandin(f):   # if the file isn't in the manifest then it was removed   # or renamed, raise IOError to indicate this   srcfname = bfutil.splitstandin(f)   try:   fctx = ctx.filectx(srcfname)   except error.LookupError:   raise IOError()   renamed = fctx.renamed()   if renamed:   # standin is always a bfile because bfileness   # doesn't change after rename or copy   renamed = bfutil.standin(renamed[0])     return context.memfilectx(f, bfiletohash[srcfname], 'l' in fctx.flags(),   'x' in fctx.flags(), renamed)   else:   try:   fctx = ctx.filectx(f)   except error.LookupError:   raise IOError()   renamed = fctx.renamed()   if renamed:   renamed = renamed[0]     data = fctx.data()   if f == '.hgtags':   newdata = []   for line in data.splitlines():   id, name = line.split(' ', 1)   newdata.append('%s %s\n' % (node.hex(revmap[node.bin(id)]), name))   data = ''.join(newdata)   return context.memfilectx(f, data, 'l' in fctx.flags(),   'x' in fctx.flags(), renamed)     # Commit   mctx = context.memctx(rdst, parents, ctx.description(), dstfiles,   getfilectx, ctx.user(), ctx.date(), ctx.extra())   ret = rdst.commitctx(mctx)   rdst.dirstate.setparents(ret)   revmap[ctx.node()] = rdst.changelog.tip()    def _isbfile(file, ctx, matcher, size):   '''   A file is a bfile if it matches a pattern or is over   the given size.   '''   # Never store hgtags or hgignore as bfiles   if file == '.hgtags' or file == '.hgignore' or file == '.hgsigs':   return False   if matcher and matcher(file):   return True   try:   return ctx.filectx(file).size() >= size * 1024 * 1024   except error.LookupError:   return False    def uploadbfiles(ui, rsrc, rdst, files):   '''upload big files to the central store'''     if not files:   return     # Don't upload locally. All bfiles are in the system wide cache   # so the other repo can just get them from there.   if not rdst.path.startswith('http'):   return     store = basestore._openstore(rsrc, rdst.path, put=True)     at = 0   for hash in files:   ui.progress(_('uploading bfiles'), at, unit='bfile', total=len(files))   if store.exists(hash):   at += 1   continue   source = bfutil.findfile(rsrc, hash)   if not source:   raise util.Abort(_('Missing bfile %s needs to be uploaded') % hash)   # XXX check for errors here   store.put(source, hash)   at += 1   ui.progress('uploading bfiles', None)    def verifybfiles(ui, repo, all=False, contents=False):   '''Verify that every big file revision in the current changeset   exists in the central store. With --contents, also verify that   the contents of each big file revision are correct (SHA-1 hash   matches the revision ID). With --all, check every changeset in   this repository.'''   if all:   # Pass a list to the function rather than an iterator because we know a list will work.   revs = range(len(repo))   else:   revs = ['.']     store = basestore._openstore(repo)   return store.verify(revs, contents=contents)    def revertbfiles(ui, repo, filelist=None):   wlock = repo.wlock()   try:   bfdirstate = bfutil.openbfdirstate(ui, repo)   s = bfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False, False, False)   (unsure, modified, added, removed, missing, unknown, ignored, clean) = s     bfiles = bfutil.listbfiles(repo)   toget = []   at = 0   updated = 0   for bfile in bfiles:   if filelist == None or bfile in filelist:   if not os.path.exists(repo.wjoin(bfutil.standin(bfile))):   bfdirstate.remove(bfile)   continue   if os.path.exists(repo.wjoin(bfutil.standin(os.path.join(bfile + '.orig')))):   shutil.copyfile(repo.wjoin(bfile), repo.wjoin(bfile + '.orig'))   at += 1   expectedhash = repo[None][bfutil.standin(bfile)].data().strip()   mode = os.stat(repo.wjoin(bfutil.standin(bfile))).st_mode   if not os.path.exists(repo.wjoin(bfile)) or expectedhash != bfutil.hashfile(repo.wjoin(bfile)):   path = bfutil.findfile(repo, expectedhash)   if path is None:   toget.append((bfile, expectedhash))   else:   util.makedirs(os.path.dirname(repo.wjoin(bfile)))   shutil.copy(path, repo.wjoin(bfile))   os.chmod(repo.wjoin(bfile), mode)   updated += 1   if bfutil.standin(bfile) not in repo['.']:   bfdirstate.add(bfutil.unixpath(bfile))   elif expectedhash == repo['.'][bfutil.standin(bfile)].data().strip():   bfdirstate.normal(bfutil.unixpath(bfile))   else:   bfutil.dirstate_normaldirty(bfdirstate, bfutil.unixpath(bfile))   elif os.path.exists(repo.wjoin(bfile)) and mode != os.stat(repo.wjoin(bfile)).st_mode:   os.chmod(repo.wjoin(bfile), mode)   updated += 1   if bfutil.standin(bfile) not in repo['.']:   bfdirstate.add(bfutil.unixpath(bfile))   elif expectedhash == repo['.'][bfutil.standin(bfile)].data().strip():   bfdirstate.normal(bfutil.unixpath(bfile))   else:   bfutil.dirstate_normaldirty(bfdirstate, bfutil.unixpath(bfile))     if toget:   store = basestore._openstore(repo)   success, missing = store.get(toget)   else:   success, missing = [], []     for (filename, hash) in success:   mode = os.stat(repo.wjoin(bfutil.standin(filename))).st_mode   os.chmod(repo.wjoin(filename), mode)   updated += 1   if bfutil.standin(filename) not in repo['.']:   bfdirstate.add(bfutil.unixpath(filename))   elif hash == repo['.'][bfutil.standin(filename)].data().strip():   bfdirstate.normal(bfutil.unixpath(filename))   else:   bfutil.dirstate_normaldirty(bfdirstate, bfutil.unixpath(filename))     removed = 0   for bfile in bfdirstate: - if filelist == None or bfile in filelist: + if filelist is None or bfile in filelist:   if not os.path.exists(repo.wjoin(bfutil.standin(bfile))):   if os.path.exists(repo.wjoin(bfile)):   os.unlink(repo.wjoin(bfile))   removed += 1   if bfutil.standin(bfile) in repo['.']:   bfdirstate.remove(bfutil.unixpath(bfile))   else:   bfdirstate.forget(bfutil.unixpath(bfile))   else:   state = repo.dirstate[bfutil.standin(bfile)]   if state == 'n':   bfdirstate.normal(bfile)   elif state == 'r':   bfdirstate.remove(bfile)   elif state == 'a':   bfdirstate.add(bfile)   elif state == '?':   try:   # Mercurial >= 1.9   bfdirstate.drop(bfile)   except AttributeError:   # Mercurial <= 1.8   bfdirstate.forget(bfile)   bfdirstate.write()   finally:   wlock.release()    def updatebfiles(ui, repo):   wlock = repo.wlock()   try:   bfdirstate = bfutil.openbfdirstate(ui, repo)   s = bfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False, False, False)   (unsure, modified, added, removed, missing, unknown, ignored, clean) = s     bfiles = bfutil.listbfiles(repo)   toget = []   at = 0   updated = 0   removed = 0   printed = False   if bfiles:   ui.status(_('getting changed bfiles\n'))   printed = True     for bfile in bfiles:   at += 1   if os.path.exists(repo.wjoin(bfile)) and not os.path.exists(repo.wjoin(bfutil.standin(bfile))):   os.unlink(repo.wjoin(bfile))   removed += 1   bfdirstate.forget(bfutil.unixpath(bfile))   continue   expectedhash = repo[None][bfutil.standin(bfile)].data().strip()   mode = os.stat(repo.wjoin(bfutil.standin(bfile))).st_mode   if not os.path.exists(repo.wjoin(bfile)) or expectedhash != bfutil.hashfile(repo.wjoin(bfile)):   path = bfutil.findfile(repo, expectedhash)   if not path:   toget.append((bfile, expectedhash))   else:   util.makedirs(os.path.dirname(repo.wjoin(bfile)))   shutil.copy(path, repo.wjoin(bfile))   os.chmod(repo.wjoin(bfile), mode)   updated += 1   bfdirstate.normal(bfutil.unixpath(bfile))   elif os.path.exists(repo.wjoin(bfile)) and mode != os.stat(repo.wjoin(bfile)).st_mode:   os.chmod(repo.wjoin(bfile), mode)   updated += 1   bfdirstate.normal(bfutil.unixpath(bfile))     if toget:   store = basestore._openstore(repo)   (success, missing) = store.get(toget)   else:   success, missing = [],[]     for (filename, hash) in success:   mode = os.stat(repo.wjoin(bfutil.standin(filename))).st_mode   os.chmod(repo.wjoin(filename), mode)   updated += 1   bfdirstate.normal(bfutil.unixpath(filename))     for bfile in bfdirstate:   if bfile not in bfiles:   if os.path.exists(repo.wjoin(bfile)):   if not printed:   ui.status(_('getting changed bfiles\n'))   printed = True   os.unlink(repo.wjoin(bfile))   removed += 1   path = bfutil.unixpath(bfile)   try:   # Mercurial >= 1.9   bfdirstate.drop(path)   except AttributeError:   # Mercurial <= 1.8   bfdirstate.forget(path)     bfdirstate.write()   if printed:   ui.status(_('%d big files updated, %d removed\n') % (updated, removed))   finally:   wlock.release()    # -- hg commands declarations ------------------------------------------------      cmdtable = {   'kbfconvert': (bfconvert,   [('s', 'size', 0, 'All files over this size '   '(in megabytes) will be considered bfiles. This can also be specified in your hgrc as [bfiles].size.'),   ('','tonormal',False, 'Convert from a bfiles repo to a normal repo')],   _('hg kbfconvert SOURCE DEST [FILE ...]')),   }
Change 1 of 1 Show Entire File bfiles/​kbfiles/​bfproto.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@@ -0,0 +1,57 @@
+import tempfile, shutil, os + +from mercurial.i18n import _ +from mercurial import wireproto, error, util + +import bfutil, bfsetup + +def putbfile(repo, proto, sha): + fd, tempname = tempfile.mkstemp(prefix='hg-putbfile-') + with os.fdopen(fd, 'wb+') as fp: + proto.getfile(fp) + bfutil.copytocacheabsolute(repo, tempname, sha) + return '' + +def getbfile(repo, proto, sha): + filename = bfutil.findfile(repo, sha) + if not filename: + raise util.Abort(_('requested bfile %s not present in cache') % sha) + f = open(filename, 'rb') + return wireproto.streamres(f) + +# '0' for OK, '1' for invalid checksum, '2' for missing +def statbfile(repo, proto, sha): + filename = bfutil.findfile(repo, sha) + if not filename: + return '2\n' + with open(filename, 'rb') as f: + return '0\n' if bfutil.hexsha1(f) == sha else '1\n' + +def wirerepo_putbfile(self, sha, fd): + return self._callstream("putbfile", data=fd, sha=sha, headers={'content-type':'application/mercurial-0.1'}) + +def wirerepo_getbfile(self, sha): + return self._callstream("getbfile", sha=sha) + +def wirerepo_statbfile(self, sha): + try: + return int(self._call("statbfile", sha=sha)) + except: + return 2 + # if the server returns something that's not an integer followed by a + # newline, it's not kbfiles-capable, so obviously it doesn't have the + # bfile; any other exception means _something_ went wrong, so tell the + # caller the bfile is missing + +def dispatch(repo, proto, command): + func, spec = wireproto.commands[command] + args = proto.getargs(spec) + if len(args) > 0 and isinstance(args[-1], dict): + if bfutil.listbfiles(repo) and command in affectedcommands and not args[-1].pop('kbfiles'): + return '0\n' + return func(repo, proto, *args) + +def capabilities(repo, proto): + return wireproto.capabilities(repo, proto) + ' bfilestore=serve' + +affectedcommands = [ 'changegroup', 'changegroupsubset', 'getbundle', 'unbundle', 'stream_out', 'pushkey' ]
 
88
89
90
91
 
92
93
94
 
233
234
235
236
 
237
238
239
 
942
943
944
945
 
946
947
948
 
962
963
964
 
 
 
965
966
967
 
974
975
976
 
 
 
977
978
979
 
1267
1268
1269
1270
 
1271
1272
1273
 
88
89
90
 
91
92
93
94
 
233
234
235
 
236
237
238
239
 
942
943
944
 
945
946
947
948
 
962
963
964
965
966
967
968
969
970
 
977
978
979
980
981
982
983
984
985
 
1273
1274
1275
 
1276
1277
1278
1279
@@ -88,7 +88,7 @@
  return result   ctx.__class__ = bfiles_ctx   return ctx - +   # Figure out the status of big files and insert them into the   # appropriate list in the result. Also removes standin files from   # the listing. This function reverts to the original status if @@ -233,7 +233,7 @@
  try:   if getattr(repo, "_isrebasing", False):   # We have to take the time to pull down the new bfiles now. Otherwise - # if we are rebasing, any bfiles that were modified in the changesets we + # if we are rebasing, any bfiles that were modified in the changesets we   # are rebasing on top of get overwritten either by the rebase or in the   # first commit after the rebase.   bfcommands.updatebfiles(repo.ui, repo) @@ -942,7 +942,7 @@
 # When we rebase a repository with remotely changed bfiles, we need  # to take some extra care so that the bfiles are correctly updated  # in the working copy -def override_pull(orig, ui, repo, source="default", **opts): +def override_pull(orig, ui, repo, source=None, **opts):   if opts.get('rebase', False):   repo._isrebasing = True   try: @@ -962,6 +962,9 @@
  def _dummy(*args, **kwargs):   pass   commands.postincoming = _dummy + repo.bfpullsource = source + if not source: + source = 'default'   try:   result = commands.pull(ui, repo, source, **opts)   finally: @@ -974,6 +977,9 @@
  finally:   repo._isrebasing = False   else: + repo.bfpullsource = source + if not source: + source = 'default'   result = orig(ui, repo, source, **opts)   return result   @@ -1267,7 +1273,7 @@
  bfdirstate.add(file)   bfdirstate.write()   return result - +  def uisetup(ui):   # Disable auto-status for some commands which assume that all   # files in the result are under Mercurial's control
 
1
2
3
4
5
6
7
 
8
9
10
 
63
64
65
66
 
67
68
69
 
247
248
249
 
 
 
250
251
252
253
254
255
 
 
256
257
258
 
287
288
289
290
 
291
292
293
 
435
436
437
 
 
 
 
 
 
438
439
440
 
1
2
 
 
 
 
 
3
4
5
6
 
59
60
61
 
62
63
64
65
 
243
244
245
246
247
248
249
250
251
252
 
 
253
254
255
256
257
 
286
287
288
 
289
290
291
292
 
434
435
436
437
438
439
440
441
442
443
444
445
@@ -1,10 +1,6 @@
 '''bfiles utility code: must not import other modules in this package.'''   -import os -import errno -import inspect -import shutil -import stat +import os, errno, inspect, shutil, stat, hashlib    from mercurial import \   util, dirstate, cmdutil, match as match_ @@ -63,7 +59,7 @@
  repo[None].forget(list)   finally:   wlock.release() - +   return remove(list, unlink=unlink)    def repo_forget(repo, list): @@ -247,12 +243,15 @@
  hash = readstandin(repo, standin(file))   if incache(repo, hash):   return + copytocacheabsolute(repo, repo.wjoin(file), hash) + +def copytocacheabsolute(repo, file, hash):   createdir(os.path.dirname(cachepath(repo, hash)))   if insystemcache(repo.ui, hash):   link(systemcachepath(repo.ui, hash), cachepath(repo, hash))   else: - shutil.copyfile(repo.wjoin(file), cachepath(repo, hash)) - os.chmod(cachepath(repo, hash), os.stat(repo.wjoin(file)).st_mode) + shutil.copyfile(file, cachepath(repo, hash)) + os.chmod(cachepath(repo, hash), os.stat(file).st_mode)   createdir(os.path.dirname(systemcachepath(repo.ui, hash)))   link(cachepath(repo, hash), systemcachepath(repo.ui, hash))   @@ -287,7 +286,7 @@
  except ImportError:   # Mercurial <= 1.8   match = cmdutil.match(repo, pats, opts) - +   if not showbad:   match.bad = lambda f, msg: None   return match @@ -435,6 +434,12 @@
  url = join(url, a)   return url   +def hexsha1(data): + h = hashlib.sha1() + for chunk in util.filechunkiter(data): + h.update(chunk) + return h.hexdigest() +  # Convert a path to a unix style path. This is used to give a  # canonical path to the bfdirstate.  def unixpath(path):
 
1
2
3
4
5
 
6
7
 
8
9
10
 
17
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
24
25
26
27
28
29
30
31
32
 
 
33
34
35
 
40
41
42
43
44
45
46
47
48
49
 
50
51
52
 
58
59
60
61
62
63
64
 
65
66
67
 
70
71
72
 
 
 
 
73
74
75
76
77
78
79
80
81
82
 
83
84
85
 
86
87
88
89
90
91
 
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 
112
113
114
115
116
117
118
119
120
121
122
 
126
127
128
129
130
131
132
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
150
151
152
153
154
 
155
156
157
 
158
 
 
 
 
 
 
 
 
 
 
 
1
2
 
 
 
3
4
 
5
6
7
8
 
15
16
17
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
 
 
 
 
 
 
 
34
35
36
37
38
39
40
41
 
46
47
48
 
 
 
 
 
 
 
49
50
51
52
 
58
59
60
 
61
 
 
62
63
64
65
 
68
69
70
71
72
73
74
75
 
 
 
 
 
 
 
 
 
76
77
78
 
79
80
81
82
83
84
 
85
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
 
 
 
 
 
 
92
93
94
 
98
99
100
 
101
102
 
 
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
 
 
 
 
143
144
 
 
145
146
147
148
149
150
151
152
153
154
155
156
@@ -1,10 +1,8 @@
 '''HTTP-based store.'''   -import inspect -import urlparse -import urllib2 +import inspect, urlparse, urllib2   -from mercurial import util, url as url_ +from mercurial import util, hg, url as url_  from mercurial.i18n import _    try: @@ -17,19 +15,27 @@
 class httpstore(basestore.basestore):   """A store accessed via HTTP"""   def __init__(self, ui, repo, url): - url = bfutil.urljoin(url, 'bfile') + store_type = None + try: + remoterepo = hg.peer(repo, dict([]), url) + store_type = remoterepo.capable('bfilestore') + except: + pass + if store_type == 'serve': + self.proto = hgservestoreproto(remoterepo, url) + elif store_type == 'kiln': + self.proto = kilnstoreproto(ui, url) + else: + ui.note(_('bfilestore capability not found; assuming %s is a Kiln repo') % url) + self.proto = kilnstoreproto(ui, url) + self.url = self.proto.url + self.rawurl, authinfo = urlparse.urlsplit(self.url)[1:3]   super(httpstore, self).__init__(ui, repo, url) - self.rawurl, self.path = urlparse.urlsplit(self.url)[1:3] - try: - # Mercurial >= 1.9 - baseurl, authinfo = util.url(self.url).authinfo() - except AttributeError: - # Mercurial <= 1.8 - baseurl, authinfo = url_.getauthinfo(self.url) - self.opener = url_.opener(self.ui, authinfo)     def put(self, source, hash):   self.sendfile(source, hash) + if not self._verify(hash): + raise util.Abort(_('could not put %s to remote store') % source)   self.ui.debug('put %s to remote store\n' % source)     def exists(self, hash): @@ -40,13 +46,7 @@
  return     self.ui.debug('httpstore.sendfile(%s, %s)\n' % (filename, hash)) - try: - # Mercurial >= 1.9 - baseurl, authinfo = util.url(self.url).authinfo() - except AttributeError: - # Mercurial <= 1.8 - baseurl, authinfo = url_.getauthinfo(self.url) - fd = None + Ffd = None   try:   try:   # Mercurial >= 1.9 @@ -58,10 +58,8 @@
  else:   # Mercurial <= 1.7   fd = url_.httpsendfile(filename, 'rb') - request = urllib2.Request(bfutil.urljoin(baseurl, hash), fd)   try: - url = self.opener.open(request) - self.ui.note(_('[OK] %s/%s\n') % (self.rawurl, url.geturl())) + url = self.proto.put(hash, fd)   except urllib2.HTTPError, e:   raise util.Abort(_('unable to POST: %s\n') % e.msg)   except Exception, e: @@ -70,53 +68,27 @@
  if fd: fd.close()     def _getfile(self, tmpfile, filename, hash): + stat = self.proto.stat(hash) + if stat: + raise util.Abort(_('bfile %s is %s') % + (hash, 'invalid' if stat == 1 else 'missing'))   try: - # Mercurial >= 1.9 - baseurl, authinfo = util.url(self.url).authinfo() - except AttributeError: - # Mercurial <= 1.8 - baseurl, authinfo = url_.getauthinfo(self.url) - url = bfutil.urljoin(baseurl, hash) - try: - request = urllib2.Request(url) - infile = self.opener.open(request) + infile = self.proto.get(hash)   except urllib2.HTTPError, err:   detail = _("HTTP error: %s %s") % (err.code, err.msg) - raise basestore.StoreError(filename, hash, url, detail) + raise basestore.StoreError(filename, hash, self.url, detail)   except urllib2.URLError, err:   # This usually indicates a connection problem, so don't   # keep trying with the other files... they will probably   # all fail too.   reason = err[0][1] # assumes err[0] is a socket.error - raise util.Abort('%s: %s' % (baseurl, reason)) + raise util.Abort('%s: %s' % (self.url, reason))   return bfutil.copyandhash(bfutil.blockstream(infile), tmpfile)     def _verify(self, hash): - try: - # Mercurial >= 1.9 - baseurl, authinfo = util.url(self.url).authinfo() - except AttributeError: - # Mercurial <= 1.8 - baseurl, authinfo = url_.getauthinfo(self.url) - store_path = bfutil.urljoin(baseurl, hash) - request = urllib2.Request(store_path) - request.add_header('SHA1-Request', hash) - try: - url = self.opener.open(request) - if 'Content-SHA1' in url.info() and hash == url.info()['Content-SHA1']: - return True - else: - return False - except: - return False + return not self.proto.stat(hash)     def _verifyfile(self, cctx, cset, contents, standin, verified): - try: - # Mercurial >= 1.9 - baseurl, authinfo = util.url(self.url).authinfo() - except AttributeError: - # Mercurial <= 1.8 - baseurl, authinfo = url_.getauthinfo(self.url)   filename = bfutil.splitstandin(standin)   if not filename:   return False @@ -126,33 +98,59 @@
  return False     expect_hash = fctx.data()[0:40] - store_path = bfutil.urljoin(baseurl, expect_hash)   verified.add(key)   - request = urllib2.Request(store_path) - request.add_header('SHA1-Request',expect_hash) + stat = self.proto.stat(hash) + if not stat: + return False + elif stat == 1: + self.ui.warn( + _('changeset %s: %s: contents differ\n (%s)\n') + % (cset, filename, store_path)) + return True # failed + elif stat == 2: + self.ui.warn( + _('changeset %s: %s missing\n (%s)\n') + % (cset, filename, store_path)) + return True # failed + else: + raise util.Abort(_('check failed, unexpected response' + 'statbfile: %d') % stat) + +class kilnstoreproto(object): + def __init__(self, ui, url): + self.url = bfutil.urljoin(url, "bfile")   try: - url = self.opener.open(request) - if 'Content-SHA1' in url.info(): - rhash = url.info()['Content-SHA1'] - if rhash == expect_hash: - return False - else: - self.ui.warn( - _('changeset %s: %s: contents differ\n (%s)\n') - % (cset, filename, store_path)) - return True # failed - else: - self.ui.warn(_('remote did not send a hash, ' - 'it probably does not understand this protocol\n')) - return False + # Mercurial >= 1.9 + baseurl, authinfo = util.url(self.url).authinfo() + except AttributeError: + # Mercurial <= 1.8 + baseurl, authinfo = url_.getauthinfo(self.url) + self.opener = url_.opener(ui, authinfo) + def put(self, hash, fd): + req = urllib2.Request(bfutil.urljoin(self.url, hash), fd) + return self.opener.open(req) + def get(self, hash): + req = urllib2.Request(bfutil.urljoin(self.url, hash)) + req.add_header('SHA1-Request', hash) + return self.opener.open(req) + # '0' for OK, '1' for invalid checksum, '2' for missing + def stat(self, hash): + try: + return 0 if hash == bfutil.hexsha1(self.get(hash)) else 1   except urllib2.HTTPError, e:   if e.code == 404: - self.ui.warn( - _('changeset %s: %s missing\n (%s)\n') - % (cset, filename, store_path)) - return True # failed + return 2   else: - raise util.Abort(_('check failed, unexpected response' - 'status: %d: %s') % (e.code, e.msg)) + raise   +class hgservestoreproto(object): + def __init__(self, repo, url): + self.repo = repo + self.url = url + def put(self, hash, fd): + return self.repo.putbfile(hash, fd) + def get(self, hash): + return self.repo.getbfile(hash) + def stat(self, hash): + return self.repo.statbfile(hash)
 
32
33
34
35
 
36
37
38
 
32
33
34
 
35
36
37
38
@@ -32,7 +32,7 @@
  stdout, stderr = child.communicate()   versions = re.findall(r'\d+\.\d+(?:\.\d+)?', stdout)   parts = [re.match(r'\d+', v).group(0) for v in versions[0].split('.')] - +   version = [0, 0, 0]   for i, part in enumerate(map(int, parts)):   version[i] = part
 
5
6
7
8
 
9
10
 
5
6
7
 
8
9
10
@@ -5,6 +5,6 @@
 # write access to that repo group.    KILNEXTPATH = '~/kiln/extensions' -KILNURL = 'http://localhost/FogBugz/kiln' +KILNURL = 'http://localhost/kiln'  USER = 'test'  PASSWORD = 'tester'
 
350
351
352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
@@ -350,3 +350,41 @@
 ''')  os.chdir('..')  common.checkrepos(hgt, 'repo1', 'repo2', [0, 3, 4, 5, 8, 11, 14, 17]) + +hgt.announce('no default path error') +os.mkdir('repo3') +os.chdir('repo3') +hgt.hg(['init']) +hgt.hg(['pull', '../repo1'], + stdout='''pulling from ../repo1 +requesting all changes +adding changesets +adding manifests +adding file changes +added 18 changesets with 33 changes to 16 files +(run 'hg update' to get a working copy) +''') +hgt.writefile('.hg/hgrc', '''[kilnbfiles] +systemcache = . +''') +hgt.hg(['up'], + stdout='''13 files updated, 0 files merged, 0 files removed, 0 files unresolved +getting changed bfiles +0 big files updated, 0 removed +''', stderr='''b1: Can't get file locally +(no default or default-push path set in hgrc) +dir/b1.foo: Can't get file locally +(no default or default-push path set in hgrc) +dir/b2: Can't get file locally +(no default or default-push path set in hgrc) +dir/b2222.foo: Can't get file locally +(no default or default-push path set in hgrc) +dir/b3.foo: Can't get file locally +(no default or default-push path set in hgrc) +dir/b3333.foo: Can't get file locally +(no default or default-push path set in hgrc) +dir/b4: Can't get file locally +(no default or default-push path set in hgrc) +dir/b4.foo: Can't get file locally +(no default or default-push path set in hgrc) +''')
 
68
69
70
 
 
 
 
 
 
68
69
70
71
72
73
74
75
@@ -68,3 +68,8 @@
 hg commit -m merge  hg push ../repo1  hg up + +% no default path error +hg init +hg pull ../repo1 +hg up
Change 1 of 1 Show Entire File kilnauth.py Stacked
 
84
85
86
87
 
 
 
88
89
90
 
84
85
86
 
87
88
89
90
91
92
@@ -84,7 +84,9 @@
  if before != after:   try:   os.rename(self.__temporary_path, self.__original_path) - except (IOError, WindowsError, OSError): + except WindowsError: + shutil.copyfile(self.__temporary_path, self.__original_path) + except (IOError, OSError):   pass    def get_cookiejar(ui):