[PATCH] add qtimes command to save and restore modification times

Andrei Vermel avermel at mail.ru
Mon Jul 30 15:04:48 CDT 2007


The patch allows to save and restore modification times of files patched by mq,
so that qpop / qpush wouldn't require unnecessary rebuild.

Example of usage:

hg qpush -a
hg qtimes -s # save modification times of files affected by patches
hg qpop -a
hg pull -u
hg qpush -a
hg qtimes -r # restore modification times of files affected by patches. times of updated files are not restored

Andrei

# HG changeset patch
# User Andrei Vermel <avermel at mail.ru>
# Date 1185825287 -14400
# Node ID e75604e5fcfaeec4f684b0903deb37d7d5500aa7
# Parent  23d2c9b863f8a26e01cefac012c1a4b7ebce93d5
mq: add qtimes command to save and restore modification times

diff -r 23d2c9b863f8 -r e75604e5fcfa hgext/mq.py
--- a/hgext/mq.py Thu Jul 26 22:34:38 2007 +0400
+++ b/hgext/mq.py Mon Jul 30 23:54:47 2007 +0400
@@ -2120,6 +2120,50 @@ def reposetup(ui, repo):
     if repo.local():
         repo.__class__ = mqrepo
         repo.mq = queue(ui, repo.join(""))
+
+import md5, string
+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.write(_('no patches applied'))
+      return True
+    #all = opts['all']
+    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,
+                             #list_ignored=all or opts['ignored'],
+                             #list_clean=all or opts['clean']
+                             )]
+    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 = string.split(string.strip(line), ',')
+         cs = md5.new()
+         cs.update(file(fname, 'r').read())
+         if cs.hexdigest() != checksum:
+           ui.write(_('checksum differs for 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 -n option is needed\n"))
+      commands.help_(ui, 'qtimes')
+
+    return True
 
 seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
 
@@ -2244,6 +2288,11 @@ cmdtable = {
           ('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/20070731/33b36d1a/attachment.obj 


More information about the Mercurial mailing list