Mozilla: hg as a collaboration tool
Andrei Vermel
avermel at mail.ru
Thu Feb 7 02:50:39 CST 2008
-----Original Message-----
From: Bryan O'Sullivan [mailto:bos at serpentine.com]
Sent: Thursday, February 07, 2008 10:22 AM
To: Andrei Vermel
Subject: Re: Mozilla: hg as a collaboration tool
>
> That's a cute idea. Why don't you clean it up a little and resubmit it,
> and I'll apply it.
Here goes.
Andrei
# HG changeset patch
# User Andrei Vermel <avermel at mail.ru>
# Date 1202373978 -10800
# Node ID 687062ed07d05a5d9b068ffceef9f80b0bfb82be
# Parent e8cf04d8e81907533b322acd20854decf03b79dd
mq: add qtimes command to save and restore modification times
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -2219,6 +2219,45 @@
repo.__class__ = mqrepo
repo.mq = queue(ui, repo.join(""))
+import md5
+def times(ui, repo, *pats, **opts):
+ """save or restore modification times of patched files"""
+ q = repo.mq
+ node1, node2 = cmdutil.revpair(repo, ['qparent', 'tip'])
+ if node1 == node2:
+ ui.warn(_('no patches applied - nothing to do'))
+ return True
+ files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
+ cwd = (pats and repo.getcwd()) or ''
+ modified, added, removed, deleted, unknown, ignored, clean = [
+ n for n in repo.status(node1=node1, node2=node2, files=files,
+ match=matchfn)]
+ if opts['save']:
+ pm = file(repo.path+'/patched_mtimes', 'w')
+ patched = modified + added
+ for f in patched:
+ fname = repo.wjoin(f)
+ mtime = os.stat(fname).st_mtime
+ checksum = md5.new()
+ checksum.update(file(fname, 'r').read())
+ pm.write("%s,%s,%s\n" % (fname, checksum.hexdigest(), mtime))
+ elif opts['restore']:
+ pm = file(repo.path+'/patched_mtimes', 'r')
+ for line in pm.readlines():
+ fname, checksum, mtime = line.strip().split(',')
+ cs = md5.new()
+ cs.update(file(fname, 'r').read())
+ if cs.hexdigest() != checksum:
+ ui.warn(_('Not restoring timestamp of file %s\n') % fname)
+ else:
+ st = os.stat(fname)
+ os.utime(fname, (st.st_atime, type(st.st_mtime)(mtime)))
+ else:
+ ui.warn(_("hg qtimes: either -r or -s option is needed\n"))
+ commands.help_(ui, 'qtimes')
+
+ return True
+
seriesopts = [('s', 'summary', None, _('print first line of patch
header'))]
headeropts = [
@@ -2342,6 +2381,11 @@
('b', 'backup', None, _('bundle unrelated changesets')),
('n', 'nobackup', None, _('no backups'))],
_('hg strip [-f] [-b] [-n] REV')),
+ "qtimes":
+ (times,
+ [('s', 'save', None, _('save modification times')),
+ ('r', 'restore', None, _('restore modification times'))],
+ _('hg qtimes (-s | -r)')),
"qtop": (top, [] + seriesopts, _('hg qtop [-s]')),
"qunapplied": (unapplied, [] + seriesopts, _('hg qunapplied [-s]
[PATCH]')),
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mq_qtimes.diff
Type: application/octet-stream
Size: 2927 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial/attachments/20080207/be89b276/attachment.obj
More information about the Mercurial
mailing list