Kiln » largefiles » Unity
Clone URL:  

largefiles: download largefiles to the repository cache rather than directly to the working copy

Changeset 3d9fcccc0ee8

Parent f5d8843a249a

by Profile picture of User 521Andrew Pritchard <andrewp@fogcreek.com>

Changes to 4 files · Browse files at 3d9fcccc0ee8 Showing diff from parent f5d8843a249a Diff from another changeset...

Change 1 of 3 Show Entire File basestore.py Stacked
 
11
12
13
 
14
15
16
 
71
72
73
74
75
76
77
78
79
80
 
 
 
 
81
82
83
84
85
 
86
87
88
 
100
101
102
103
104
105
106
107
108
109
 
 
 
 
 
 
 
110
111
112
 
11
12
13
14
15
16
17
 
72
73
74
 
 
 
 
 
 
 
75
76
77
78
79
80
81
82
 
83
84
85
86
 
98
99
100
 
 
 
 
 
 
 
101
102
103
104
105
106
107
108
109
110
@@ -11,6 +11,7 @@
 import tempfile  import binascii  import re +import shutil    from mercurial import util, node, error, url as url_, hg  from mercurial.i18n import _ @@ -71,18 +72,15 @@
  ui.progress(_('getting largefiles'), at, unit='lfile',   total=len(files))   at += 1 - ui.note(_('getting %s\n') % filename) - outfilename = self.repo.wjoin(filename) - destdir = os.path.dirname(outfilename) - util.makedirs(destdir) - if not os.path.isdir(destdir): - self.abort(error.RepoError(_('cannot create dest directory %s') - % destdir)) + ui.note(_('getting %s:%s\n') % (filename, hash)) + + cachefilename = lfutil.cachepath(self.repo, hash) + cachedir = os.path.dirname(cachefilename)     # No need to pass mode='wb' to fdopen(), since mkstemp() already   # opened the file in binary mode.   (tmpfd, tmpfilename) = tempfile.mkstemp( - dir=destdir, prefix=os.path.basename(filename)) + dir=cachedir, prefix=os.path.basename(filename))   tmpfile = os.fdopen(tmpfd, 'w')     try: @@ -100,13 +98,13 @@
  % (filename, hash, hhash))   os.remove(tmpfilename)   missing.append(filename) - else: - if os.path.exists(outfilename): # for windows - os.remove(outfilename) - os.rename(tmpfilename, outfilename) - lfutil.copytocache(self.repo, self.repo['.'].node(), filename, - True) - success.append((filename, hhash)) + continue + + if os.path.exists(cachefilename): # Windows + os.remove(cachefilename) + os.rename(tmpfilename, cachefilename) + lfutil.linktosystemcache(self.repo, hash) + success.append((filename, hhash))     ui.progress(_('getting largefiles'), None)   return (success, missing)
Change 1 of 9 Show Entire File lfcommands.py Stacked
 
389
390
391
392
 
 
 
 
393
394
395
 
398
399
400
401
 
402
403
404
 
407
408
409
410
411
412
 
413
414
415
 
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
 
483
484
485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
487
488
 
492
493
494
495
496
497
498
 
501
502
503
 
 
504
505
506
 
514
515
516
517
518
519
 
520
521
522
 
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
 
389
390
391
 
392
393
394
395
396
397
398
 
401
402
403
 
404
405
406
407
 
410
411
412
 
 
 
413
414
415
416
 
436
437
438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
440
441
 
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
 
502
503
504
 
505
506
507
 
510
511
512
513
514
515
516
517
 
525
526
527
 
 
 
528
529
530
531
 
537
538
539
 
 
 
 
 
 
 
 
 
 
 
 
540
541
542
@@ -389,7 +389,10 @@
  unsure, modified, added, removed, missing, unknown, ignored, clean = s     lfiles = lfutil.listlfiles(repo) - toget = [] + + if lfiles: + cachelfiles(ui, repo, '.') +   at = 0   updated = 0   for lfile in lfiles: @@ -398,7 +401,7 @@
  lfdirstate.remove(lfile)   continue   if os.path.exists(repo.wjoin(lfutil.standin(os.path.join(lfile\ - + '.orig')))): + + '.orig')))):   shutil.copyfile(repo.wjoin(lfile), repo.wjoin(lfile + \   '.orig'))   at += 1 @@ -407,9 +410,7 @@
  if not os.path.exists(repo.wjoin(lfile)) or expectedhash != \   lfutil.hashfile(repo.wjoin(lfile)):   path = lfutil.findfile(repo, expectedhash) - if path is None: - toget.append((lfile, expectedhash)) - else: + if path is not None:   util.makedirs(os.path.dirname(repo.wjoin(lfile)))   shutil.copy(path, repo.wjoin(lfile))   os.chmod(repo.wjoin(lfile), mode) @@ -435,24 +436,6 @@
  lfutil.dirstate_normaldirty(lfdirstate,   lfutil.unixpath(lfile))   - if toget: - store = basestore._openstore(repo) - success, missing = store.get(toget) - else: - success, missing = [], [] - - for (filename, hash) in success: - mode = os.stat(repo.wjoin(lfutil.standin(filename))).st_mode - os.chmod(repo.wjoin(filename), mode) - updated += 1 - if lfutil.standin(filename) not in repo['.']: - lfdirstate.add(lfutil.unixpath(filename)) - elif hash == repo['.'][lfutil.standin(filename)].data().strip(): - lfdirstate.normal(lfutil.unixpath(filename)) - else: - lfutil.dirstate_normaldirty(lfdirstate, - lfutil.unixpath(filename)) -   removed = 0   for lfile in lfdirstate:   if filelist is None or lfile in filelist: @@ -483,6 +466,33 @@
  finally:   wlock.release()   +def cachelfiles(ui, repo, node): + '''cachelfiles ensures that all largefiles needed by the specified revision + are present in the repository's largefile cache. + + returns a tuple (cached, missing). cached is the list of files downloaded + by this operation; missing is the list of files that were needed but could + not be found.''' + lfiles = lfutil.listlfiles(repo, node) + toget = [] + + for lfile in lfiles: + expectedhash = repo[node][lfutil.standin(lfile)].data().strip() + # if it exists and its hash matches, it might have been locally + # modified before updating and the user chose 'local'. in this case, + # it will not be in any store, so don't look for it. + if (not os.path.exists(repo.wjoin(lfile)) \ + or expectedhash != lfutil.hashfile(repo.wjoin(lfile))) and \ + not lfutil.findfile(repo, expectedhash): + toget.append((lfile, expectedhash)) + + if toget: + store = basestore._openstore(repo) + ret = store.get(toget) + return ret + + return ([], []) +  def updatelfiles(ui, repo):   wlock = repo.wlock()   try: @@ -492,7 +502,6 @@
  unsure, modified, added, removed, missing, unknown, ignored, clean = s     lfiles = lfutil.listlfiles(repo) - toget = []   at = 0   updated = 0   removed = 0 @@ -501,6 +510,8 @@
  ui.status(_('getting changed largefiles\n'))   printed = True   + success, missing = cachelfiles(ui, repo, None) +   for lfile in lfiles:   at += 1   if os.path.exists(repo.wjoin(lfile)) and not \ @@ -514,9 +525,7 @@
  if not os.path.exists(repo.wjoin(lfile)) or expectedhash != \   lfutil.hashfile(repo.wjoin(lfile)):   path = lfutil.findfile(repo, expectedhash) - if not path: - toget.append((lfile, expectedhash)) - else: + if path:   util.makedirs(os.path.dirname(repo.wjoin(lfile)))   shutil.copy(path, repo.wjoin(lfile))   os.chmod(repo.wjoin(lfile), mode) @@ -528,18 +537,6 @@
  updated += 1   lfdirstate.normal(lfutil.unixpath(lfile))   - if toget: - store = basestore._openstore(repo) - (success, missing) = store.get(toget) - else: - success, missing = [],[] - - for (filename, hash) in success: - mode = os.stat(repo.wjoin(lfutil.standin(filename))).st_mode - os.chmod(repo.wjoin(filename), mode) - updated += 1 - lfdirstate.normal(lfutil.unixpath(filename)) -   for lfile in lfdirstate:   if lfile not in lfiles:   if os.path.exists(repo.wjoin(lfile)):
Change 1 of 1 Show Entire File lfutil.py Stacked
 
265
266
267
268
269
 
 
 
 
 
270
271
272
 
265
266
267
 
 
268
269
270
271
272
273
274
275
@@ -265,8 +265,11 @@
  else:   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)) + linktosystemcache(repo, hash) + +def linktosystemcache(repo, hash): + createdir(os.path.dirname(systemcachepath(repo.ui, hash))) + link(cachepath(repo, hash), systemcachepath(repo.ui, hash))    def getstandinmatcher(repo, pats=[], opts={}):   '''Return a match object that applies pats to the standin directory'''
Change 1 of 1 Show Entire File overrides.py Stacked
 
685
686
687
 
 
688
689
690
 
685
686
687
688
689
690
691
692
@@ -685,6 +685,8 @@
  # No need to lock because we are only reading history and lfile caches   # neither of which are modified   + lfcommands.cachelfiles(repo.ui, repo, node) +   if kind not in archival.archivers:   raise util.Abort(_("unknown archive type '%s'") % kind)