##// END OF EJS Templates
shelve: move patch extension to a string constant...
Kostia Balytskyi -
r30554:1775975d default
parent child Browse files
Show More
@@ -63,6 +63,8 testedwith = 'ships-with-hg-core'
63 backupdir = 'shelve-backup'
63 backupdir = 'shelve-backup'
64 shelvedir = 'shelved'
64 shelvedir = 'shelved'
65 shelvefileextensions = ['hg', 'patch']
65 shelvefileextensions = ['hg', 'patch']
66 # universal extension is present in all types of shelves
67 patchextension = 'patch'
66
68
67 # we never need the user, so we use a
69 # we never need the user, so we use a
68 # generic user for all shelve operations
70 # generic user for all shelve operations
@@ -220,7 +222,8 class shelvedstate(object):
220 def cleanupoldbackups(repo):
222 def cleanupoldbackups(repo):
221 vfs = scmutil.vfs(repo.join(backupdir))
223 vfs = scmutil.vfs(repo.join(backupdir))
222 maxbackups = repo.ui.configint('shelve', 'maxbackups', 10)
224 maxbackups = repo.ui.configint('shelve', 'maxbackups', 10)
223 hgfiles = [f for f in vfs.listdir() if f.endswith('.hg')]
225 hgfiles = [f for f in vfs.listdir()
226 if f.endswith('.' + patchextension)]
224 hgfiles = sorted([(vfs.stat(f).st_mtime, f) for f in hgfiles])
227 hgfiles = sorted([(vfs.stat(f).st_mtime, f) for f in hgfiles])
225 if 0 < maxbackups and maxbackups < len(hgfiles):
228 if 0 < maxbackups and maxbackups < len(hgfiles):
226 bordermtime = hgfiles[-maxbackups][0]
229 bordermtime = hgfiles[-maxbackups][0]
@@ -230,7 +233,7 def cleanupoldbackups(repo):
230 if mtime == bordermtime:
233 if mtime == bordermtime:
231 # keep it, because timestamp can't decide exact order of backups
234 # keep it, because timestamp can't decide exact order of backups
232 continue
235 continue
233 base = f[:-3]
236 base = f[:-(1 + len(patchextension))]
234 for ext in shelvefileextensions:
237 for ext in shelvefileextensions:
235 try:
238 try:
236 vfs.unlink(base + '.' + ext)
239 vfs.unlink(base + '.' + ext)
@@ -264,12 +267,12 def getshelvename(repo, parent, opts):
264 label = label.replace('/', '_')
267 label = label.replace('/', '_')
265
268
266 if name:
269 if name:
267 if shelvedfile(repo, name, 'hg').exists():
270 if shelvedfile(repo, name, patchextension).exists():
268 e = _("a shelved change named '%s' already exists") % name
271 e = _("a shelved change named '%s' already exists") % name
269 raise error.Abort(e)
272 raise error.Abort(e)
270 else:
273 else:
271 for n in gennames():
274 for n in gennames():
272 if not shelvedfile(repo, n, 'hg').exists():
275 if not shelvedfile(repo, n, patchextension).exists():
273 name = n
276 name = n
274 break
277 break
275 else:
278 else:
@@ -337,7 +340,7 def _shelvecreatedcommit(repo, node, nam
337 bases = list(mutableancestors(repo[node]))
340 bases = list(mutableancestors(repo[node]))
338 shelvedfile(repo, name, 'hg').writebundle(bases, node)
341 shelvedfile(repo, name, 'hg').writebundle(bases, node)
339 cmdutil.export(repo, [node],
342 cmdutil.export(repo, [node],
340 fp=shelvedfile(repo, name, 'patch').opener('wb'),
343 fp=shelvedfile(repo, name, patchextension).opener('wb'),
341 opts=mdiff.diffopts(git=True))
344 opts=mdiff.diffopts(git=True))
342
345
343 def _includeunknownfiles(repo, pats, opts, extra):
346 def _includeunknownfiles(repo, pats, opts, extra):
@@ -444,7 +447,7 def deletecmd(ui, repo, pats):
444 # but the .hg file is optional as in future we
447 # but the .hg file is optional as in future we
445 # will add obsolete shelve with does not create a
448 # will add obsolete shelve with does not create a
446 # bundle
449 # bundle
447 if shfile.exists() or suffix == 'patch':
450 if shfile.exists() or suffix == patchextension:
448 shfile.movetobackup()
451 shfile.movetobackup()
449 cleanupoldbackups(repo)
452 cleanupoldbackups(repo)
450 except OSError as err:
453 except OSError as err:
@@ -463,7 +466,7 def listshelves(repo):
463 info = []
466 info = []
464 for (name, _type) in names:
467 for (name, _type) in names:
465 pfx, sfx = name.rsplit('.', 1)
468 pfx, sfx = name.rsplit('.', 1)
466 if not pfx or sfx != 'patch':
469 if not pfx or sfx != patchextension:
467 continue
470 continue
468 st = shelvedfile(repo, name).stat()
471 st = shelvedfile(repo, name).stat()
469 info.append((st.st_mtime, shelvedfile(repo, pfx).filename()))
472 info.append((st.st_mtime, shelvedfile(repo, pfx).filename()))
@@ -491,7 +494,7 def listcmd(ui, repo, pats, opts):
491 ui.write(age, label='shelve.age')
494 ui.write(age, label='shelve.age')
492 ui.write(' ' * (12 - len(age)))
495 ui.write(' ' * (12 - len(age)))
493 used += 12
496 used += 12
494 with open(name + '.patch', 'rb') as fp:
497 with open(name + '.' + patchextension, 'rb') as fp:
495 while True:
498 while True:
496 line = fp.readline()
499 line = fp.readline()
497 if not line:
500 if not line:
@@ -519,7 +522,7 def singlepatchcmds(ui, repo, pats, opts
519 raise error.Abort(_("--%s expects a single shelf") % subcommand)
522 raise error.Abort(_("--%s expects a single shelf") % subcommand)
520 shelfname = pats[0]
523 shelfname = pats[0]
521
524
522 if not shelvedfile(repo, shelfname, 'patch').exists():
525 if not shelvedfile(repo, shelfname, patchextension).exists():
523 raise error.Abort(_("cannot find shelf %s") % shelfname)
526 raise error.Abort(_("cannot find shelf %s") % shelfname)
524
527
525 listcmd(ui, repo, pats, opts)
528 listcmd(ui, repo, pats, opts)
@@ -823,7 +826,7 def _dounshelve(ui, repo, *shelved, **op
823 else:
826 else:
824 basename = shelved[0]
827 basename = shelved[0]
825
828
826 if not shelvedfile(repo, basename, 'patch').exists():
829 if not shelvedfile(repo, basename, patchextension).exists():
827 raise error.Abort(_("shelved change '%s' not found") % basename)
830 raise error.Abort(_("shelved change '%s' not found") % basename)
828
831
829 oldquiet = ui.quiet
832 oldquiet = ui.quiet
@@ -195,12 +195,12 apply it and make sure our state is as e
195 (this also tests that same timestamp prevents backups from being
195 (this also tests that same timestamp prevents backups from being
196 removed, even though there are more than 'maxbackups' backups)
196 removed, even though there are more than 'maxbackups' backups)
197
197
198 $ f -t .hg/shelve-backup/default.hg
198 $ f -t .hg/shelve-backup/default.patch
199 .hg/shelve-backup/default.hg: file
199 .hg/shelve-backup/default.patch: file
200 $ touch -t 200001010000 .hg/shelve-backup/default.hg
200 $ touch -t 200001010000 .hg/shelve-backup/default.patch
201 $ f -t .hg/shelve-backup/default-1.hg
201 $ f -t .hg/shelve-backup/default-1.patch
202 .hg/shelve-backup/default-1.hg: file
202 .hg/shelve-backup/default-1.patch: file
203 $ touch -t 200001010000 .hg/shelve-backup/default-1.hg
203 $ touch -t 200001010000 .hg/shelve-backup/default-1.patch
204
204
205 $ hg unshelve
205 $ hg unshelve
206 unshelving change 'default-01'
206 unshelving change 'default-01'
General Comments 0
You need to be logged in to leave comments. Login now