Kiln » largefiles » Unity
Clone URL:  

cleanup: simplify code path in revertlfiles; add dirstate wrapper that unix-ifies the pathnames; add copyfromcache

Changeset 9e5f67217e8e

Parent 53d9e75793ca

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

Changes to 2 files · Browse files at 9e5f67217e8e Showing diff from parent 53d9e75793ca Diff from another changeset...

Change 1 of 2 Show Entire File lfcommands.py Stacked
 
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
 
436
437
438
439
 
440
441
 
442
443
444
 
399
400
401
 
402
403
404
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
405
406
407
408
409
 
 
 
 
 
 
 
 
410
411
412
413
414
415
416
417
418
 
422
423
424
 
425
426
 
427
428
429
430
@@ -399,34 +399,20 @@
  continue   if os.path.exists(repo.wjoin(lfutil.standin(lfile + '.orig'))):   shutil.copyfile(repo.wjoin(lfile), repo.wjoin(lfile + '.orig')) - expectedhash = repo[None][lfutil.standin(lfile)].data().strip() + expectedhash = lfutil.readstandin(repo, lfile)   mode = os.stat(repo.wjoin(lfutil.standin(lfile))).st_mode   if not os.path.exists(repo.wjoin(lfile)) or expectedhash != \ - lfutil.hashfile(repo.wjoin(lfile)): - path = lfutil.findfile(repo, expectedhash) - 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) - if lfutil.standin(lfile) not in repo['.']: - lfdirstate.add(lfutil.unixpath(lfile)) - elif expectedhash == repo['.'][lfutil.standin(lfile)] \ - .data().strip(): - lfdirstate.normal(lfutil.unixpath(lfile)) - else: - lfutil.dirstate_normaldirty(lfdirstate, - lfutil.unixpath(lfile)) - elif os.path.exists(repo.wjoin(lfile)) and mode != \ + lfutil.hashrepofile(repo, lfile): + lfutil.copyfromcache(repo, expectedhash, lfile) + if os.path.exists(repo.wjoin(lfile)) and mode != \   os.stat(repo.wjoin(lfile)).st_mode:   os.chmod(repo.wjoin(lfile), mode) - if lfutil.standin(lfile) not in repo['.']: - lfdirstate.add(lfutil.unixpath(lfile)) - elif expectedhash == \ - repo['.'][lfutil.standin(lfile)].data().strip(): - lfdirstate.normal(lfutil.unixpath(lfile)) - else: - lfutil.dirstate_normaldirty(lfdirstate, - lfutil.unixpath(lfile)) + if lfutil.standin(lfile) not in repo['.']: + lfdirstate.add(lfile) + elif expectedhash == lfutil.readstandin(repo, lfile, '.'): + lfdirstate.normal(lfile) + else: + lfutil.dirstate_normaldirty(lfdirstate, lfile)     removed = 0   for lfile in lfdirstate: @@ -436,9 +422,9 @@
  os.unlink(repo.wjoin(lfile))   removed += 1   if lfutil.standin(lfile) in repo['.']: - lfdirstate.remove(lfutil.unixpath(lfile)) + lfdirstate.remove(lfile)   else: - lfdirstate.forget(lfutil.unixpath(lfile)) + lfdirstate.forget(lfile)   else:   state = repo.dirstate[lfutil.standin(lfile)]   if state == 'n':
Change 1 of 4 Show Entire File lfutil.py Stacked
 
97
98
99
100
 
101
102
103
 
159
160
161
 
 
 
 
 
 
 
 
 
 
162
163
164
 
172
173
174
175
 
176
177
178
 
179
180
181
 
252
253
254
 
 
 
 
 
 
 
 
 
 
 
 
255
256
257
 
97
98
99
 
100
101
102
103
 
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
 
182
183
184
 
185
186
187
 
188
189
190
191
 
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
@@ -97,7 +97,7 @@
  dirstate._map[f] = ('n', 0, -2, -1)   if f in dirstate._copymap:   del dirstate._copymap[f] - normaldirty(file) + normaldirty(unixpath(file))    def findoutgoing(repo, remote, force):   # First attempt is for Mercurial <= 1.5 second is for >= 1.6 @@ -159,6 +159,16 @@
  return systemcachepath(repo.ui, hash)   return None   +class largefiles_dirstate(dirstate.dirstate): + def normal(self, f): + return super(largefiles_dirstate, self).normal(unixpath(f)) + def remove(self, f): + return super(largefiles_dirstate, self).remove(unixpath(f)) + def add(self, f): + return super(largefiles_dirstate, self).add(unixpath(f)) + def drop(self, f): + return super(largefiles_dirstate, self).drop(unixpath(f)) +  def openlfdirstate(ui, repo):   '''   Return a dirstate object that tracks big files: i.e. its root is the @@ -172,10 +182,10 @@
  # Mercurial <= 1.8   opener = util.opener(admin)   if hasattr(repo.dirstate, '_validate'): - lfdirstate = dirstate.dirstate(opener, ui, repo.root, + lfdirstate = largefiles_dirstate(opener, ui, repo.root,   repo.dirstate._validate)   else: - lfdirstate = dirstate.dirstate(opener, ui, repo.root) + lfdirstate = largefiles_dirstate(opener, ui, repo.root)     # If the lfiles dirstate does not exist, populate and create it. This   # ensures that we create it on the first meaningful largefiles operation in @@ -252,6 +262,18 @@
 def cachepath(repo, hash):   return repo.join(os.path.join(longname, hash))   +def copyfromcache(repo, hash, filename): + '''copyfromcache copies the specified largefile from the repo or system + cache to the specified location in the repository. It will not throw an + exception on failure, as it is meant to be called only after ensuring that + the needed largefile exists in the cache.''' + path = findfile(repo, hash) + if path is None: + return False + util.makedirs(os.path.dirname(repo.wjoin(filename))) + shutil.copy(path, repo.wjoin(filename)) + return True +  def copytocache(repo, rev, file, uploaded=False):   hash = readstandin(repo, file)   if incache(repo, hash):