本文整理汇总了Python中mercurial.util.copyfile函数的典型用法代码示例。如果您正苦于以下问题:Python copyfile函数的具体用法?Python copyfile怎么用?Python copyfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了copyfile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: write
def write(repo):
'''Write bookmarks
Write the given bookmark => hash dictionary to the .hg/bookmarks file
in a format equal to those of localtags.
We also store a backup of the previous state in undo.bookmarks that
can be copied back on rollback.
'''
refs = repo._bookmarks
if os.path.exists(repo.join('bookmarks')):
util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks'))
if repo._bookmarkcurrent not in refs:
setcurrent(repo, None)
wlock = repo.wlock()
try:
file = repo.opener('bookmarks', 'w', atomictemp=True)
for refspec, node in refs.iteritems():
file.write("%s %s\n" % (hex(node), refspec))
file.rename()
# touch 00changelog.i so hgweb reloads bookmarks (no lock needed)
try:
os.utime(repo.sjoin('00changelog.i'), None)
except OSError:
pass
finally:
wlock.release()
开发者ID:ThissDJ,项目名称:designhub,代码行数:29,代码来源:bookmarks.py
示例2: orderFiles
def orderFiles(sourcePath, file):
srcPath = sourcePath + "/" + file
d = get_date(srcPath)
destPath = dest + d[0] + "/" + d[1] + "_" + d[0] + "/" + file
make_sure_path_exists(dest + d[0] + "/" + d[1] + "_" + d[0])
if not (os.path.exists(destPath)):
copyfile(srcPath, destPath)
开发者ID:alfcrisci,项目名称:magic,代码行数:7,代码来源:order_by_date.py
示例3: _updatebigrepo
def _updatebigrepo(ui, repo, files, brepo, bigfiles, ds):
for file in files:
f = repo.wjoin(file)
hash = accelerated_hash(repo, file, os.lstat(f), ds)
bigfiles[file] = hash
rf = "%s/%s.%s" % (brepo, file, hash)
util.makedirs(os.path.dirname(rf))
try:
ext = f.split('.')[-1]
dont_pack=['gz', 'zip', 'tgz', '7z', 'jpg', 'jpeg', 'gif',
'mpg', 'mpeg', 'avi', 'rar', 'cab']
if ext in dont_pack:
util.copyfile(f, rf)
else:
fo = open(f, 'rb')
rfo_fileobj = open(rf+'.gz', 'wb')
rfo = gzip.GzipFile(file+'.'+hash, 'wb', 9, rfo_fileobj)
def read10Mb():
return fo.read(1024*1024*10)
for chunk in iter(read10Mb, ''):
rfo.write(chunk)
fo.close()
rfo.close()
rfo_fileobj.close()
except:
ui.write(_('failed to store %s\n') % f)
开发者ID:vorou,项目名称:config,代码行数:26,代码来源:bigfiles.py
示例4: remember_path
def remember_path(ui, repo, path, value):
'''appends the path to the working copy's hgrc and backs up the original'''
paths = dict(ui.configitems('paths'))
# This should never happen.
if path in paths:
return
# ConfigParser only cares about these three characters.
if re.search(r'[:=\s]', path):
return
try:
audit_path = scmutil.pathauditor(repo.root)
except ImportError:
audit_path = getattr(repo.opener, 'audit_path', util.path_auditor(repo.root))
audit_path('hgrc')
audit_path('hgrc.backup')
base = repo.opener.base
hgrc, backup = [os.path.join(base, x) for x in 'hgrc', 'hgrc.backup']
if os.path.exists(hgrc):
util.copyfile(hgrc, backup)
ui.setconfig('paths', path, value)
try:
fp = repo.opener('hgrc', 'a', text=True)
# Mercurial assumes Unix newlines by default and so do we.
fp.write('\n[paths]\n%s = %s\n' % (path, value))
fp.close()
except IOError:
return
开发者ID:szechyjs,项目名称:dotfiles,代码行数:33,代码来源:kiln.py
示例5: storeuntracked
def storeuntracked(repo, untracked):
if not untracked:
return
os.mkdir(repo.join('tasks/untrackedbackup'))
for f in untracked:
shaname = util.sha1(f).hexdigest()
util.copyfile(util.pathto(repo.root, None, f),
repo.join('tasks/untrackedbackup/%s' % shaname))
util.unlink(util.pathto(repo.root, None, f))
开发者ID:Evanlec,项目名称:config,代码行数:9,代码来源:tasks.py
示例6: unshelve
def unshelve(ui, repo, **opts):
'''restore shelved changes'''
# Shelf name and path
shelfname = opts.get('name')
shelfpath = getshelfpath(repo, shelfname)
# List all the active shelves by name and return '
if opts['list']:
listshelves(ui,repo)
return
try:
patch_diff = repo.opener(shelfpath).read()
fp = cStringIO.StringIO(patch_diff)
if opts['inspect']:
ui.status(fp.getvalue())
else:
files = []
ac = parsepatch(fp)
for chunk in ac:
if isinstance(chunk, header):
files += chunk.files()
backupdir = repo.join('shelve-backups')
backups = makebackup(ui, repo, backupdir, set(files))
ui.debug('applying shelved patch\n')
patchdone = 0
try:
try:
fp.seek(0)
internalpatch(fp, ui, 1, repo.root)
patchdone = 1
except:
if opts['force']:
patchdone = 1
else:
ui.status('restoring backup files\n')
for realname, tmpname in backups.iteritems():
ui.debug('restoring %r to %r\n' %
(tmpname, realname))
util.copyfile(tmpname, repo.wjoin(realname))
finally:
try:
ui.debug('removing backup files\n')
shutil.rmtree(backupdir, True)
except OSError:
pass
if patchdone:
ui.debug("removing shelved patches\n")
os.unlink(repo.join(shelfpath))
ui.status("unshelve completed\n")
except IOError:
ui.warn('nothing to unshelve\n')
开发者ID:lugecy,项目名称:dot-rc,代码行数:55,代码来源:hgshelve.py
示例7: backup
def backup(self, repo, files, copy=False):
# backup local changes in --force case
for f in sorted(files):
absf = repo.wjoin(f)
if os.path.lexists(absf):
self.ui.note(_('saving current version of %s as %s\n') %
(f, f + '.orig'))
if copy:
util.copyfile(absf, absf + '.orig')
else:
util.rename(absf, absf + '.orig')
开发者ID:peiyaoyao,项目名称:intellij-community,代码行数:11,代码来源:mq.py
示例8: unremember_path
def unremember_path(ui, repo):
'''restores the working copy's hgrc'''
audit_path = getattr(repo.opener, 'audit_path',
util.path_auditor(repo.root))
audit_path('hgrc')
audit_path('hgrc.backup')
base = repo.opener.base
if os.path.exists(os.path.join(base, 'hgrc')):
util.copyfile(os.path.join(base, 'hgrc.backup'),
os.path.join(base, 'hgrc'))
开发者ID:sergio,项目名称:dotfiles,代码行数:12,代码来源:kiln.py
示例9: copyfile
def copyfile(abssrc, relsrc, otarget, exact):
abstarget = scmutil.canonpath(repo.root, cwd, otarget)
reltarget = repo.pathto(abstarget, cwd)
target = repo.wjoin(abstarget)
src = repo.wjoin(abssrc)
state = repo.dirstate[abstarget]
scmutil.checkportable(ui, abstarget)
# check for collisions
prevsrc = targets.get(abstarget)
if prevsrc is not None:
ui.warn(_('%s: not overwriting - %s collides with %s\n') %
(reltarget, repo.pathto(abssrc, cwd),
repo.pathto(prevsrc, cwd)))
return
# check for overwrites
exists = os.path.lexists(target)
if not after and exists or after and state in 'mn':
if not opts['force']:
ui.warn(_('%s: not overwriting - file exists\n') %
reltarget)
return
if after:
if not exists:
if rename:
ui.warn(_('%s: not recording move - %s does not exist\n') %
(relsrc, reltarget))
else:
ui.warn(_('%s: not recording copy - %s does not exist\n') %
(relsrc, reltarget))
return
elif not dryrun:
try:
if exists:
os.unlink(target)
targetdir = os.path.dirname(target) or '.'
if not os.path.isdir(targetdir):
os.makedirs(targetdir)
util.copyfile(src, target)
srcexists = True
except IOError, inst:
if inst.errno == errno.ENOENT:
ui.warn(_('%s: deleted in working copy\n') % relsrc)
srcexists = False
else:
ui.warn(_('%s: cannot copy - %s\n') %
(relsrc, inst.strerror))
return True # report a failure
开发者ID:PMR2,项目名称:pmr2.mercurial,代码行数:51,代码来源:ext.py
示例10: unremember_path
def unremember_path(ui, repo):
'''restores the working copy's hgrc'''
try:
audit_path = scmutil.pathauditor(repo.root)
except ImportError:
audit_path = getattr(repo.opener, 'audit_path', util.path_auditor(repo.root))
audit_path('hgrc')
audit_path('hgrc.backup')
base = repo.opener.base
hgrc, backup = [os.path.join(base, x) for x in 'hgrc', 'hgrc.backup']
if os.path.exists(backup):
util.copyfile(backup, hgrc)
else:
os.remove(hgrc)
开发者ID:szechyjs,项目名称:dotfiles,代码行数:17,代码来源:kiln.py
示例11: unshelve
def unshelve(ui, repo, *pats, **opts):
'''restore shelved changes'''
try:
fp = cStringIO.StringIO()
fp.write(repo.opener('shelve').read())
if opts['inspect']:
ui.status(fp.getvalue())
else:
files = []
for chunk in parsepatch(fp):
if isinstance(chunk, header):
files += chunk.files()
backupdir = repo.join('shelve-backups')
backups = makebackup(ui, repo, backupdir, set(files))
ui.debug('applying shelved patch\n')
patchdone = 0
try:
try:
fp.seek(0)
internalpatch(fp, ui, 1, repo.root)
patchdone = 1
except:
if opts['force']:
patchdone = 1
else:
ui.status('restoring backup files\n')
for realname, tmpname in backups.iteritems():
ui.debug('restoring %r to %r\n' %
(tmpname, realname))
util.copyfile(tmpname, repo.wjoin(realname))
finally:
try:
ui.debug('removing backup files\n')
shutil.rmtree(backupdir, True)
except OSError:
pass
if patchdone:
ui.debug("removing shelved patches\n")
os.unlink(repo.join('shelve'))
ui.status("unshelve completed\n")
except IOError:
ui.warn('nothing to unshelve\n')
开发者ID:wamcvey,项目名称:wam-homedir,代码行数:45,代码来源:hgshelve.py
示例12: write
def write(ui, repo, tasks):
'''Write tasks
Write the given task dictionary to the .hg/tasks/tasks file.
We also store a backup of the previous state in .hg/tasks/undo.tasks that
can be copied back on rollback.
'''
if os.path.exists(repo.join('tasks/tasks')):
util.copyfile(repo.join('tasks/tasks'), repo.join('tasks/undo.tasks'))
# is this needed here?
if current(repo) not in tasks:
setcurrent(ui, repo, None)
if not os.path.isdir(repo.join('tasks')):
try:
os.mkdir(repo.join('tasks'))
except OSError, inst:
if inst.errno != errno.EEXIST:
raise
开发者ID:Evanlec,项目名称:config,代码行数:21,代码来源:tasks.py
示例13: write
def write(repo, refs):
"""Write bookmarks
Write the given bookmark => hash dictionary to the .hg/bookmarks file
in a format equal to those of localtags.
We also store a backup of the previous state in undo.bookmarks that
can be copied back on rollback.
"""
if os.path.exists(repo.join("bookmarks")):
util.copyfile(repo.join("bookmarks"), repo.join("undo.bookmarks"))
if current(repo) not in refs:
setcurrent(repo, None)
wlock = repo.wlock()
try:
file = repo.opener("bookmarks", "w", atomictemp=True)
for refspec, node in refs.iteritems():
file.write("%s %s\n" % (hex(node), refspec))
file.rename()
finally:
wlock.release()
开发者ID:fuzxxl,项目名称:plan9front,代码行数:21,代码来源:bookmarks.py
示例14: bigupdate
def bigupdate(ui, repo, *pats, **opts):
'''fetch files from versions directory as recorded in '.bigfiles'.
Also complain about necessary files missing in the version directory'''
ds = read_bigfiledirstate(ui, repo)
bigfiles = parse_bigfiles(repo)
tracked_gotbig, added_big, modified, removed, gotsmall, \
missinginrepo = _bigstatus(ui, repo, pats, opts, ds, bigfiles)
brepo = bigfiles_repo(ui)
tocopy = removed
if opts['clean']:
tocopy = tocopy+modified
for file in tocopy:
f = repo.wjoin(file)
hash= bigfiles[file]
rf = "%s/%s.%s" % (brepo, file, hash)
ui.write(_("fetching %s\n") % rf)
if not opts['dry_run']:
util.makedirs(os.path.dirname(f))
if os.path.exists(f):
util.unlink(f)
if os.path.exists(rf):
util.copyfile(rf, f)
else:
fo = open(f, 'wb')
rfo = gzip.open(rf + '.gz', 'rb')
def read10Mb():
return rfo.read(1024*1024*10)
for chunk in iter(read10Mb, ''):
fo.write(chunk)
fo.close()
rfo.close()
if missinginrepo:
ui.write(_("\nNeeded files missing in bigrepo %s:\n") % brepo)
for file in missinginrepo:
hash = bigfiles[file]
ui.write("%s.%s\n" % (file, hash))
write_bigfiledirstate(ui, repo, ds)
开发者ID:vorou,项目名称:config,代码行数:39,代码来源:bigfiles.py
示例15: dodiff
#.........这里部分代码省略.........
if revs and change:
msg = _('cannot specify --rev and --change at the same time')
raise util.Abort(msg)
elif change:
node2 = repo.lookup(change)
node1a, node1b = repo.changelog.parents(node2)
else:
node1a, node2 = cmdutil.revpair(repo, revs)
if not revs:
node1b = repo.dirstate.parents()[1]
else:
node1b = nullid
# Disable 3-way merge if there is only one parent
if do3way:
if node1b == nullid:
do3way = False
matcher = cmdutil.match(repo, pats, opts)
mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher)[:3])
if do3way:
mod_b, add_b, rem_b = map(set, repo.status(node1b, node2, matcher)[:3])
else:
mod_b, add_b, rem_b = set(), set(), set()
modadd = mod_a | add_a | mod_b | add_b
common = modadd | rem_a | rem_b
if not common:
return 0
tmproot = tempfile.mkdtemp(prefix='extdiff.')
try:
# Always make a copy of node1a (and node1b, if applicable)
dir1a_files = mod_a | rem_a | ((mod_b | add_b) - add_a)
dir1a = snapshot(ui, repo, dir1a_files, node1a, tmproot)[0]
if do3way:
dir1b_files = mod_b | rem_b | ((mod_a | add_a) - add_b)
dir1b = snapshot(ui, repo, dir1b_files, node1b, tmproot)[0]
else:
dir1b = None
fns_and_mtime = []
# If node2 in not the wc or there is >1 change, copy it
dir2root = ''
if node2:
dir2 = snapshot(ui, repo, modadd, node2, tmproot)[0]
elif len(common) > 1:
#we only actually need to get the files to copy back to
#the working dir in this case (because the other cases
#are: diffing 2 revisions or single file -- in which case
#the file is already directly passed to the diff tool).
dir2, fns_and_mtime = snapshot(ui, repo, modadd, None, tmproot)
else:
# This lets the diff tool open the changed file directly
dir2 = ''
dir2root = repo.root
# If only one change, diff the files instead of the directories
# Handle bogus modifies correctly by checking if the files exist
if len(common) == 1:
common_file = util.localpath(common.pop())
dir1a = os.path.join(dir1a, common_file)
if not os.path.isfile(os.path.join(tmproot, dir1a)):
dir1a = os.devnull
if do3way:
dir1b = os.path.join(dir1b, common_file)
if not os.path.isfile(os.path.join(tmproot, dir1b)):
dir1b = os.devnull
dir2 = os.path.join(dir2root, dir2, common_file)
# Function to quote file/dir names in the argument string.
# When not operating in 3-way mode, an empty string is
# returned for parent2
replace = dict(parent=dir1a, parent1=dir1a, parent2=dir1b, child=dir2)
def quote(match):
key = match.group()[1:]
if not do3way and key == 'parent2':
return ''
return util.shellquote(replace[key])
# Match parent2 first, so 'parent1?' will match both parent1 and parent
regex = '\$(parent2|parent1?|child)'
if not do3way and not re.search(regex, args):
args += ' $parent1 $child'
args = re.sub(regex, quote, args)
cmdline = util.shellquote(diffcmd) + ' ' + args
ui.debug('running %r in %s\n' % (cmdline, tmproot))
util.system(cmdline, cwd=tmproot)
for copy_fn, working_fn, mtime in fns_and_mtime:
if os.path.getmtime(copy_fn) != mtime:
ui.debug('file changed while diffing. '
'Overwriting: %s (src: %s)\n' % (working_fn, copy_fn))
util.copyfile(copy_fn, working_fn)
return 1
finally:
ui.note(_('cleaning up temp directory\n'))
shutil.rmtree(tmproot)
开发者ID:Frostman,项目名称:intellij-community,代码行数:101,代码来源:extdiff.py
示例16: overridecopy
def overridecopy(orig, ui, repo, pats, opts, rename=False):
# doesn't remove largefile on rename
if len(pats) < 2:
# this isn't legal, let the original function deal with it
return orig(ui, repo, pats, opts, rename)
def makestandin(relpath):
path = scmutil.canonpath(repo.root, repo.getcwd(), relpath)
return os.path.join(repo.wjoin(lfutil.standin(path)))
fullpats = scmutil.expandpats(pats)
dest = fullpats[-1]
if os.path.isdir(dest):
if not os.path.isdir(makestandin(dest)):
os.makedirs(makestandin(dest))
# This could copy both lfiles and normal files in one command,
# but we don't want to do that. First replace their matcher to
# only match normal files and run it, then replace it to just
# match largefiles and run it again.
nonormalfiles = False
nolfiles = False
try:
try:
installnormalfilesmatchfn(repo[None].manifest())
result = orig(ui, repo, pats, opts, rename)
except util.Abort, e:
if str(e) != _('no files to copy'):
raise e
else:
nonormalfiles = True
result = 0
finally:
restorematchfn()
# The first rename can cause our current working directory to be removed.
# In that case there is nothing left to copy/rename so just quit.
try:
repo.getcwd()
except OSError:
return result
try:
try:
# When we call orig below it creates the standins but we don't add
# them to the dir state until later so lock during that time.
wlock = repo.wlock()
manifest = repo[None].manifest()
oldmatch = None # for the closure
def overridematch(ctx, pats=[], opts={}, globbed=False,
default='relpath'):
newpats = []
# The patterns were previously mangled to add the standin
# directory; we need to remove that now
for pat in pats:
if match_.patkind(pat) is None and lfutil.shortname in pat:
newpats.append(pat.replace(lfutil.shortname, ''))
else:
newpats.append(pat)
match = oldmatch(ctx, newpats, opts, globbed, default)
m = copy.copy(match)
lfile = lambda f: lfutil.standin(f) in manifest
m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
m._fmap = set(m._files)
m._always = False
origmatchfn = m.matchfn
m.matchfn = lambda f: (lfutil.isstandin(f) and
(f in manifest) and
origmatchfn(lfutil.splitstandin(f)) or
None)
return m
oldmatch = installmatchfn(overridematch)
listpats = []
for pat in pats:
if match_.patkind(pat) is not None:
listpats.append(pat)
else:
listpats.append(makestandin(pat))
try:
origcopyfile = util.copyfile
copiedfiles = []
def overridecopyfile(src, dest):
if (lfutil.shortname in src and
dest.startswith(repo.wjoin(lfutil.shortname))):
destlfile = dest.replace(lfutil.shortname, '')
if not opts['force'] and os.path.exists(destlfile):
raise IOError('',
_('destination largefile already exists'))
copiedfiles.append((src, dest))
origcopyfile(src, dest)
util.copyfile = overridecopyfile
result += orig(ui, repo, listpats, opts, rename)
finally:
util.copyfile = origcopyfile
lfdirstate = lfutil.openlfdirstate(ui, repo)
for (src, dest) in copiedfiles:
#.........这里部分代码省略.........
开发者ID:jordigh,项目名称:mercurial-crew,代码行数:101,代码来源:overrides.py
示例17: unshelve
def unshelve(ui, repo, **opts):
"""restore shelved changes"""
# Shelf name and path
shelfname = opts.get("name")
shelfpath = getshelfpath(repo, shelfname)
# List all the active shelves by name and return '
if opts["list"]:
listshelves(ui, repo)
return
try:
patch_diff = repo.opener(shelfpath).read()
fp = cStringIO.StringIO(patch_diff)
if opts["inspect"]:
# wrap ui.write so diff output can be labeled/colorized
def wrapwrite(orig, *args, **kw):
label = kw.pop("label", "")
if label:
label += " "
for chunk, l in patch.difflabel(lambda: args):
orig(chunk, label=label + l)
oldwrite = ui.write
extensions.wrapfunction(ui, "write", wrapwrite)
try:
ui.status(fp.getvalue())
finally:
ui.write = oldwrite
else:
files = []
ac = parsepatch(fp)
for chunk in ac:
if isinstance(chunk, header):
files += chunk.files()
backupdir = repo.join("shelve-backups")
backups = makebackup(ui, repo, backupdir, set(files))
ui.debug("applying shelved patch\n")
patchdone = 0
try:
try:
fp.seek(0)
patch.internalpatch(ui, repo, fp, 1)
patchdone = 1
except:
if opts["force"]:
patchdone = 1
else:
ui.status("restoring backup files\n")
for realname, tmpname in backups.iteritems():
ui.debug("restoring %r to %r\n" % (tmpname, realname))
util.copyfile(tmpname, repo.wjoin(realname))
finally:
try:
ui.debug("removing backup files\n")
shutil.rmtree(backupdir, True)
except OSError:
pass
if patchdone:
ui.debug("removing shelved patches\n")
os.unlink(repo.join(shelfpath))
ui.status("unshelve completed\n")
except IOError:
ui.warn("nothing to unshelve\n")
开发者ID:cflynn07,项目名称:dotfiles-1,代码行数:67,代码来源:hgshelve.py
示例18: shelvefunc
def shelvefunc(ui, repo, message, match, opts):
parents = repo.dirstate.parents()
changes = repo.status(match=match)[:5]
modified, added, removed = changes[:3]
files = modified + added + removed
diffopts = mdiff.diffopts(git=True, nodates=True)
patch_diff = "".join(patch.diff(repo, parents[0], match=match, changes=changes, opts=diffopts))
fp = cStringIO.StringIO(patch_diff)
ac = parsepatch(fp)
fp.close()
chunks = filterpatch(ui, ac, not opts["all"])
rc = refilterpatch(ac, chunks)
# set of files to be processed
contenders = {}
for h in chunks:
try:
contenders.update(dict.fromkeys(h.files()))
except AttributeError:
pass
# exclude sources of copies that are otherwise untouched
newfiles = set(f for f in files if f in contenders)
if not newfiles:
ui.status(_("no changes to shelve\n"))
return 0
backupdir = repo.join("shelve-backups")
try:
backups = makebackup(ui, repo, backupdir, newfiles)
# patch to shelve
sp = cStringIO.StringIO()
for c in chunks:
c.write(sp)
# patch to apply to shelved files
fp = cStringIO.StringIO()
for c in rc:
# skip files not selected for shelving
if c.filename() in newfiles:
c.write(fp)
dopatch = fp.tell()
fp.seek(0)
try:
# 3a. apply filtered patch to clean repo (clean)
opts["no_backup"] = True
cmdutil.revert(ui, repo, repo["."], parents, *[os.path.join(repo.root, f) for f in newfiles], **opts)
for f in added:
if f in newfiles:
util.unlinkpath(repo.wjoin(f))
# 3b. apply filtered patch to clean repo (apply)
if dopatch:
ui.debug("applying patch\n")
ui.debug(fp.getvalue())
patch.internalpatch(ui, repo, fp, 1)
del fp
# 3c. apply filtered patch to clean repo (shelve)
ui.debug("saving patch to shelve\n")
if opts["append"]:
sp.write(repo.opener(shelfpath).read())
sp.seek(0)
f = repo.opener(shelfpath, "w")
f.write(sp.getvalue())
del f, sp
except:
ui.warn("shelving failed: %s\n" % sys.exc_info()[1])
try:
# re-schedule remove
matchremoved = scmutil.matchfiles(repo, removed)
cmdutil.forget(ui, repo, matchremoved, "", True)
for f in removed:
if f in newfiles and os.path.isfile(f):
os.unlink(f)
# copy back backups
for realname, tmpname in backups.iteritems():
ui.debug("restoring %r to %r\n" % (tmpname, realname))
util.copyfile(tmpname, repo.wjoin(realname))
# re-schedule add
matchadded = scmutil.matchfiles(repo, added)
cmdutil.add(ui, repo, matchadded, False, False, "", True)
ui.debug("removing shelve file\n")
if os.path.isfile(repo.wjoin(shelfpath)):
os.unlink(repo.join(shelfpath))
except OSError, err:
ui.warn("restoring backup failed: %s\n" % err)
return 0
开发者ID:cflynn07,项目名称:dotfiles-1,代码行数:96,代码来源:hgshelve.py
示例19: makebackup
def makebackup(ui, repo, dir, files):
try:
os.mkdir(dir)
except OSError, err:
if err.errno != errno.EEXIST:
raise
backups = {}
for f in files:
if os.path.isfile(repo.wjoin(f)):
fd, tmpname = tempfile.mkstemp(prefix=f.replace("/", "_") + ".", dir=dir)
os.close(fd)
ui.debug("backup %r as %r\n" % (f, tmpname))
util.copyfile(repo.wjoin(f), tmpname)
backups[f] = tmpname
return backups
def getshelfpath(repo, name):
if name:
shelfpath = "shelves/" + name
else:
# Check if a shelf from an older version exists
if os.path.isfile(repo.join("shelve")):
shelfpath = "shelve"
else:
shelfpath = "shelves/default"
开发者ID:cflynn07,项目名称:dotfiles-1,代码行数:28,代码来源:hgshelve.py
示例20: shelvefunc
def shelvefunc(ui, repo, message, match, opts):
changes = repo.status(match=match)[:5]
modified, added, removed = changes[:3]
files = modified + added + removed
diffopts = mdiff.diffopts(git=True, nodates=True)
patch_diff = ''.join(patch.diff(repo, repo.dirstate.parents()[0],
match=match, changes=changes, opts=diffopts))
fp = cStringIO.StringIO(patch_diff)
ac = parsepatch(fp)
fp.close()
chunks = filterpatch(ui, ac, not opts['all'])
rc = refilterpatch(ac, chunks)
contenders = {}
for h in chunks:
try: contenders.update(dict.fromkeys(h.files()))
except AttributeError: pass
newfiles = [f for f in files if f in contenders]
if not newfiles:
ui.status(_('no changes to shelve\n'))
return 0
modified = dict.fromkeys(changes[0])
backupdir = repo.join('shelve-backups')
try:
bkfiles = [f for f in newfiles if f in modified]
backups = makebackup(ui, repo, backupdir, bkfiles)
# patch to shelve
sp = cStringIO.StringIO()
for c in chunks:
if c.filename() in backups:
c.write(sp)
doshelve = sp.tell()
sp.seek(0)
# patch to apply to shelved files
fp = cStringIO.StringIO()
for c in rc:
if c.filename() in backups:
c.write(fp)
dopatch = fp.tell()
fp.seek(0)
try:
# 3a. apply filtered patch to clean repo (clean)
if backups:
hg.revert(repo, repo.dirstate.parents()[0], backups.has_key)
# 3b. apply filtered patch to clean repo (apply)
if dopatch:
ui.debug('applying patch\n')
ui.debug(fp.getvalue())
patch.internalpatch(fp, ui, 1, repo.root)
del fp
# 3c. apply filtered patch to clean repo (shelve)
if doshelve:
ui.debug("saving patch to shelve\n")
if opts['append']:
f = repo.opener(shelfpath, "a")
else:
f = repo.opener(shelfpath, "w")
f.write(sp.getvalue())
del f
del sp
except:
try:
for realname, tmpname in backups.iteritems():
ui.debug('restoring %r to %r\n' % (tmpname, realname))
util.copyfile(tmpname, repo.wjoin(realname))
ui.debug('removing shelve file\n')
os.unlink(repo.join(shelfpath))
except OSError:
pass
return 0
finally:
try:
for realname, tmpname in backups.iteritems():
ui.debug('removing backup for %r : %r\n' % (realname, tmpname))
os.unlink(tmpname)
os.rmdir(backupdir)
except OSError:
pass
开发者ID:lugecy,项目名称:dot-rc,代码行数:91,代码来源:hgshelve.py
注:本文中的mercurial.util.copyfile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论