comparison mercurial/streamclone.py @ 49190:4ff4e23de7df

clone: use better names for temp files Before this commit, the file names are /tmp/tmpn8smvlr8 After this commit, they are more like /tmp/hg-clone-n8smvlr8/00manifest.ndb3qj52v6, which makes it much clearer what these files correspond to. Differential Revision: https://phab.mercurial-scm.org/D12623
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Tue, 10 May 2022 20:30:26 +0100
parents 642e31cb55f0
children d44e3c45f0e4
comparison
equal deleted inserted replaced
49189:237855525f64 49190:4ff4e23de7df
556 556
557 557
558 @contextlib.contextmanager 558 @contextlib.contextmanager
559 def maketempcopies(): 559 def maketempcopies():
560 """return a function to temporary copy file""" 560 """return a function to temporary copy file"""
561
561 files = [] 562 files = []
563 dst_dir = pycompat.mkdtemp(prefix=b'hg-clone-')
562 try: 564 try:
563 565
564 def copy(src): 566 def copy(src):
565 fd, dst = pycompat.mkstemp() 567 fd, dst = pycompat.mkstemp(
568 prefix=os.path.basename(src), dir=dst_dir
569 )
566 os.close(fd) 570 os.close(fd)
567 files.append(dst) 571 files.append(dst)
568 util.copyfiles(src, dst, hardlink=True) 572 util.copyfiles(src, dst, hardlink=True)
569 return dst 573 return dst
570 574
571 yield copy 575 yield copy
572 finally: 576 finally:
573 for tmp in files: 577 for tmp in files:
574 util.tryunlink(tmp) 578 util.tryunlink(tmp)
579 util.tryrmdir(dst_dir)
575 580
576 581
577 def _makemap(repo): 582 def _makemap(repo):
578 """make a (src -> vfs) map for the repo""" 583 """make a (src -> vfs) map for the repo"""
579 vfsmap = { 584 vfsmap = {