Changeset 3c0c2d0eaa7f…
Parent b30307e35409…
by Andrew Pritchard <andrewp@fogcreek.com>
Changes to 2 files · Browse files at 3c0c2d0eaa7f Showing diff from parent b30307e35409 Diff from another changeset...
|
|
@@ -380,60 +380,6 @@ store = basestore._openstore(repo)
return store.verify(revs, contents=contents)
-def revertlfiles(ui, repo, filelist=None):
- wlock = repo.wlock()
- try:
- lfdirstate = lfutil.openlfdirstate(ui, repo)
- lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate)
- if filelist is not None:
- lfiles = [f for f in lfiles if f in filelist]
-
- if lfiles:
- cachelfiles(ui, repo, '.')
-
- map(lambda f: _revertlfile(repo, lfdirstate, f), lfiles)
- lfdirstate.write()
- finally:
- wlock.release()
-
-def _revertlfile(repo, lfdirstate, lfile):
- ret = 0
- abslfile = repo.wjoin(lfile)
- absstandin = repo.wjoin(lfutil.standin(lfile))
- if os.path.exists(absstandin):
- if os.path.exists(absstandin+'.orig'):
- shutil.copyfile(abslfile, abslfile+'.orig')
- expecthash = lfutil.readstandin(repo, lfile)
- if expecthash != '' and \
- (not os.path.exists(abslfile) or \
- expecthash != lfutil.hashfile(abslfile)):
- if not lfutil.copyfromcache(repo, expecthash, lfile):
- return False # don't try to set the mode or update the dirstate
- ret = 1
- mode = os.stat(absstandin).st_mode
- if mode != os.stat(abslfile).st_mode:
- os.chmod(abslfile, mode)
- ret = 1
- else:
- if os.path.exists(abslfile):
- os.unlink(abslfile)
- ret = -1
- state = repo.dirstate[lfutil.standin(lfile)]
- if state == 'n':
- lfdirstate.normal(lfile)
- elif state == 'r':
- lfdirstate.remove(lfile)
- elif state == 'a':
- lfdirstate.add(lfile)
- elif state == '?':
- try:
- # Mercurial >= 1.9
- lfdirstate.drop(lfile)
- except AttributeError:
- # Mercurial <= 1.8
- lfdirstate.forget(lfile)
- return ret
-
def cachelfiles(ui, repo, node):
'''cachelfiles ensures that all largefiles needed by the specified revision
are present in the repository's largefile cache.
@@ -461,33 +407,82 @@
return ([], [])
-def updatelfiles(ui, repo):
+def updatelfiles(ui, repo, filelist=None, printmessage=True):
wlock = repo.wlock()
try:
lfdirstate = lfutil.openlfdirstate(ui, repo)
lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate)
+ if filelist is not None:
+ lfiles = [f for f in lfiles if f in filelist]
+
printed = False
- if lfiles:
+ if printmessage and lfiles:
ui.status(_('getting changed largefiles\n'))
printed = True
cachelfiles(ui, repo, '.')
updated, removed = 0, 0
- for i in map(lambda f: _revertlfile(repo, lfdirstate, f), lfiles):
+ for i in map(lambda f: _updatelfile(repo, lfdirstate, f), lfiles):
+ # increment the appropriate counter according to _updatelfile's
+ # return value
updated += i > 0 and i or 0
removed -= i < 0 and i or 0
- if (removed or updated) and not printed:
+ if printmessage and (removed or updated) and not printed:
ui.status(_('getting changed largefiles\n'))
printed = True
lfdirstate.write()
- if printed:
+ if printed and printmessage:
ui.status(_('%d big files updated, %d removed\n') % (updated,
removed))
finally:
wlock.release()
+def _updatelfile(repo, lfdirstate, lfile):
+ '''updates a single largefile and copies the state of its standin from
+ the repository's dirstate to its state in the lfdirstate.
+
+ returns 1 if the file was modified, -1 if the file was removed, 0 if the
+ file was unchanged, and None if the needed largefile was missing from the
+ cache.'''
+ ret = 0
+ abslfile = repo.wjoin(lfile)
+ absstandin = repo.wjoin(lfutil.standin(lfile))
+ if os.path.exists(absstandin):
+ if os.path.exists(absstandin+'.orig'):
+ shutil.copyfile(abslfile, abslfile+'.orig')
+ expecthash = lfutil.readstandin(repo, lfile)
+ if expecthash != '' and \
+ (not os.path.exists(abslfile) or \
+ expecthash != lfutil.hashfile(abslfile)):
+ if not lfutil.copyfromcache(repo, expecthash, lfile):
+ return None # don't try to set the mode or update the dirstate
+ ret = 1
+ mode = os.stat(absstandin).st_mode
+ if mode != os.stat(abslfile).st_mode:
+ os.chmod(abslfile, mode)
+ ret = 1
+ else:
+ if os.path.exists(abslfile):
+ os.unlink(abslfile)
+ ret = -1
+ state = repo.dirstate[lfutil.standin(lfile)]
+ if state == 'n':
+ lfdirstate.normal(lfile)
+ elif state == 'r':
+ lfdirstate.remove(lfile)
+ elif state == 'a':
+ lfdirstate.add(lfile)
+ elif state == '?':
+ try:
+ # Mercurial >= 1.9
+ lfdirstate.drop(lfile)
+ except AttributeError:
+ # Mercurial <= 1.8
+ lfdirstate.forget(lfile)
+ return ret
+
# -- hg commands declarations ------------------------------------------------
|
@@ -587,7 +587,7 @@ # Mercurial <= 1.8
cmdutil.match = oldmatch
lfileslist = getattr(repo, '_lfilestoupdate', [])
- lfcommands.revertlfiles(ui, repo, lfileslist)
+ lfcommands.updatelfiles(ui, repo, filelist=lfileslist, printmessage=False)
# Empty out the lfiles list so we start fresh next time
repo._lfilestoupdate = []
for lfile in modified:
|
Loading...