Rev 2: When printing out that a file was updated, include the timestamp info in http://bzr.arbash-meinel.com/plugins/rebuild_hash_cache

John Arbash Meinel john at arbash-meinel.com
Thu May 10 17:58:56 BST 2007


At http://bzr.arbash-meinel.com/plugins/rebuild_hash_cache

------------------------------------------------------------
revno: 2
revision-id: john at arbash-meinel.com-20070510165854-e8aswktn738n8d2e
parent: john at arbash-meinel.com-20070510164423-ftnwrmz6bp9t7fa7
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: rebuild_hash_cache
timestamp: Thu 2007-05-10 11:58:54 -0500
message:
  When printing out that a file was updated, include the timestamp info
modified:
  __init__.py                    __init__.py-20070510163923-c34sctk7g574a37g-1
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2007-05-10 16:44:23 +0000
+++ b/__init__.py	2007-05-10 16:58:54 +0000
@@ -16,9 +16,12 @@
 """Make sure all sha hashes are up to date"""
 
 import os
+import struct
+import time
 
 from bzrlib import (
     commands,
+    dirstate,
     errors,
     workingtree,
     )
@@ -50,14 +53,22 @@
                 abspath = wt.abspath(path)
                 stat_value = os.lstat(abspath)
                 # Information about the working tree
-                minikind, link_or_sha1, size, executable, stat = entry[1][0]
+                minikind, link_or_sha1, size, executable, packedstat = entry[1][0]
                 if minikind == 'f':
                     cur_sha1 = link_or_sha1
+                    size, mtime, ctime, dev, ino, mode = unpack_stat(packedstat)
                     dirstate.update_entry(entry, abspath, stat_value)
                     new_sha1 = entry[1][0][1]
                     if cur_sha1 != new_sha1:
-                        self.outf.write(u'Updated %s (%s => %s)\n'
-                                        % (path, cur_sha1, new_sha1))
+                        self.outf.write(u'Updated %s:\n' % (path,))
+                        self.outf.write('  sha: %r => %r\n'
+                                        % (cur_sha1, new_sha1))
+                        self.outf.write('  mtime: %s => %s\n'
+                                        % (format_time(mtime),
+                                           format_time(stat_value.st_mtime)))
+                        self.outf.write('  ctime: %s => %s\n'
+                                        % (format_time(ctime),
+                                           format_time(stat_value.st_ctime)))
                         update_count += 1
             self.outf.write('Updated %d entries\n' % (update_count,))
             if update_count > 0:
@@ -67,3 +78,18 @@
 
 
 commands.register_command(cmd_rebuild_hash_cache)
+
+
+def unpack_stat(packed):
+    """Take a packed stat and break it back into its parts."""
+    if packed == dirstate.DirState.NULLSTAT:
+        return 0, 0, 0, 0, 0, 0
+    size, mtime, ctime, dev, ino, mode = struct.unpack('>LLLLLL',
+                                                       packed.decode('base64'))
+    return size, mtime, ctime, dev, ino, mode
+
+
+def format_time(timestamp):
+    if timestamp == 0:
+        return 'None'
+    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))



More information about the bazaar-commits mailing list