Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/hg.py (15 lines) | |||
| M | mercurial/util.py (19 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| Martin von Zweigbergk | Jun 18 2018, 1:57 AM |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz |
| def copystore(ui, srcrepo, destpath): | def copystore(ui, srcrepo, destpath): | ||||
| '''copy files from store of srcrepo in destpath | '''copy files from store of srcrepo in destpath | ||||
| returns destlock | returns destlock | ||||
| ''' | ''' | ||||
| destlock = None | destlock = None | ||||
| try: | try: | ||||
| hardlink = None | hardlink = None | ||||
| topic = _('linking') if hardlink else _('copying') | |||||
| progress = ui.makeprogress(topic) | |||||
| num = 0 | num = 0 | ||||
| closetopic = [None] | |||||
| def prog(topic, pos): | |||||
| if pos is None: | |||||
| closetopic[0] = topic | |||||
| else: | |||||
| ui.progress(topic, pos + num) | |||||
| srcpublishing = srcrepo.publishing() | srcpublishing = srcrepo.publishing() | ||||
| srcvfs = vfsmod.vfs(srcrepo.sharedpath) | srcvfs = vfsmod.vfs(srcrepo.sharedpath) | ||||
| dstvfs = vfsmod.vfs(destpath) | dstvfs = vfsmod.vfs(destpath) | ||||
| for f in srcrepo.store.copylist(): | for f in srcrepo.store.copylist(): | ||||
| if srcpublishing and f.endswith('phaseroots'): | if srcpublishing and f.endswith('phaseroots'): | ||||
| continue | continue | ||||
| dstbase = os.path.dirname(f) | dstbase = os.path.dirname(f) | ||||
| if dstbase and not dstvfs.exists(dstbase): | if dstbase and not dstvfs.exists(dstbase): | ||||
| dstvfs.mkdir(dstbase) | dstvfs.mkdir(dstbase) | ||||
| if srcvfs.exists(f): | if srcvfs.exists(f): | ||||
| if f.endswith('data'): | if f.endswith('data'): | ||||
| # 'dstbase' may be empty (e.g. revlog format 0) | # 'dstbase' may be empty (e.g. revlog format 0) | ||||
| lockfile = os.path.join(dstbase, "lock") | lockfile = os.path.join(dstbase, "lock") | ||||
| # lock to avoid premature writing to the target | # lock to avoid premature writing to the target | ||||
| destlock = lock.lock(dstvfs, lockfile) | destlock = lock.lock(dstvfs, lockfile) | ||||
| hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f), | hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f), | ||||
| hardlink, progress=prog) | hardlink, progress) | ||||
| num += n | num += n | ||||
| if hardlink: | if hardlink: | ||||
| ui.debug("linked %d files\n" % num) | ui.debug("linked %d files\n" % num) | ||||
| if closetopic[0]: | |||||
| ui.progress(closetopic[0], None) | |||||
| else: | else: | ||||
| ui.debug("copied %d files\n" % num) | ui.debug("copied %d files\n" % num) | ||||
| if closetopic[0]: | progress.complete() | ||||
| ui.progress(closetopic[0], None) | |||||
| return destlock | return destlock | ||||
| except: # re-raises | except: # re-raises | ||||
| release(destlock) | release(destlock) | ||||
| raise | raise | ||||
| def clonewithshare(ui, peeropts, sharepath, source, srcpeer, dest, pull=False, | def clonewithshare(ui, peeropts, sharepath, source, srcpeer, dest, pull=False, | ||||
| rev=None, update=True, stream=False): | rev=None, update=True, stream=False): | ||||
| """Perform a clone using a shared repo. | """Perform a clone using a shared repo. | ||||
| if newstat.isambig(oldstat): | if newstat.isambig(oldstat): | ||||
| # stat of copied file is ambiguous to original one | # stat of copied file is ambiguous to original one | ||||
| advanced = ( | advanced = ( | ||||
| oldstat.stat[stat.ST_MTIME] + 1) & 0x7fffffff | oldstat.stat[stat.ST_MTIME] + 1) & 0x7fffffff | ||||
| os.utime(dest, (advanced, advanced)) | os.utime(dest, (advanced, advanced)) | ||||
| except shutil.Error as inst: | except shutil.Error as inst: | ||||
| raise error.Abort(str(inst)) | raise error.Abort(str(inst)) | ||||
| def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): | def copyfiles(src, dst, hardlink=None, progress=None): | ||||
| """Copy a directory tree using hardlinks if possible.""" | """Copy a directory tree using hardlinks if possible.""" | ||||
| num = 0 | num = 0 | ||||
| gettopic = lambda: hardlink and _('linking') or _('copying') | def settopic(): | ||||
| if progress: | |||||
| progress.topic = _('linking') if hardlink else _('copying') | |||||
| if os.path.isdir(src): | if os.path.isdir(src): | ||||
| if hardlink is None: | if hardlink is None: | ||||
| hardlink = (os.stat(src).st_dev == | hardlink = (os.stat(src).st_dev == | ||||
| os.stat(os.path.dirname(dst)).st_dev) | os.stat(os.path.dirname(dst)).st_dev) | ||||
| topic = gettopic() | settopic() | ||||
| os.mkdir(dst) | os.mkdir(dst) | ||||
| for name, kind in listdir(src): | for name, kind in listdir(src): | ||||
| srcname = os.path.join(src, name) | srcname = os.path.join(src, name) | ||||
| dstname = os.path.join(dst, name) | dstname = os.path.join(dst, name) | ||||
| def nprog(t, pos): | hardlink, n = copyfiles(srcname, dstname, hardlink, progress) | ||||
| if pos is not None: | |||||
| return progress(t, pos + num) | |||||
| hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog) | |||||
| num += n | num += n | ||||
| else: | else: | ||||
| if hardlink is None: | if hardlink is None: | ||||
| hardlink = (os.stat(os.path.dirname(src)).st_dev == | hardlink = (os.stat(os.path.dirname(src)).st_dev == | ||||
| os.stat(os.path.dirname(dst)).st_dev) | os.stat(os.path.dirname(dst)).st_dev) | ||||
| topic = gettopic() | settopic() | ||||
| if hardlink: | if hardlink: | ||||
| try: | try: | ||||
| oslink(src, dst) | oslink(src, dst) | ||||
| except (IOError, OSError): | except (IOError, OSError): | ||||
| hardlink = False | hardlink = False | ||||
| shutil.copy(src, dst) | shutil.copy(src, dst) | ||||
| else: | else: | ||||
| shutil.copy(src, dst) | shutil.copy(src, dst) | ||||
| num += 1 | num += 1 | ||||
| progress(topic, num) | if progress: | ||||
| progress(topic, None) | progress.increment() | ||||
| return hardlink, num | return hardlink, num | ||||
| _winreservednames = { | _winreservednames = { | ||||
| 'con', 'prn', 'aux', 'nul', | 'con', 'prn', 'aux', 'nul', | ||||
| 'com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9', | 'com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9', | ||||
| 'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9', | 'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9', | ||||
| } | } | ||||