[Pkg-bazaar-commits] ./bzr/unstable r8: store committer's timezone in revision and show

mbp at sourcefrog.net mbp at sourcefrog.net
Fri Apr 10 07:24:37 UTC 2009


------------------------------------------------------------
revno: 8
committer: mbp at sourcefrog.net
timestamp: Wed 2005-03-09 17:44:53 +1100
message:
  store committer's timezone in revision and show 
  in changelog
modified:
  bzr.py
  bzrlib/branch.py
  bzrlib/osutils.py
  bzrlib/revision.py
-------------- next part --------------
=== modified file 'bzr.py'
--- a/bzr.py	2005-03-09 06:19:37 +0000
+++ b/bzr.py	2005-03-09 06:44:53 +0000
@@ -394,6 +394,11 @@
 
 
 
+def cmd_local_time_offset():
+    print bzrlib.osutils.local_time_offset()
+
+
+
 def cmd_commit(message, verbose=False):
     Branch('.').commit(message, verbose=verbose)
 

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2005-03-09 04:08:15 +0000
+++ b/bzrlib/branch.py	2005-03-09 06:44:53 +0000
@@ -29,7 +29,7 @@
 from inventory import InventoryEntry, Inventory
 from osutils import isdir, quotefn, isfile, uuid, sha_file, username, chomp, \
      format_date, compact_date, pumpfile, user_email, rand_bytes, splitpath, \
-     joinpath, sha_string, file_kind
+     joinpath, sha_string, file_kind, local_time_offset
 from store import ImmutableStore
 from revision import Revision
 from errors import bailout
@@ -329,7 +329,8 @@
         return self.working_tree().unknowns()
 
 
-    def commit(self, message, timestamp=None, committer=None,
+    def commit(self, message, timestamp=None, timezone=None,
+               committer=None,
                verbose=False):
         """Commit working copy as a new revision.
         
@@ -463,8 +464,12 @@
         if committer == None:
             committer = username()
 
+        if timezone == None:
+            timezone = local_time_offset()
+
         mutter("building commit log message")
         rev = Revision(timestamp=timestamp,
+                       timezone=timezone,
                        committer=committer,
                        precursor = self.last_patch(),
                        message = message,
@@ -620,7 +625,7 @@
             ##print 'revision-hash:', p
             rev = self.get_revision(p)
             print 'committer:', rev.committer
-            print 'timestamp: %s' % (format_date(rev.timestamp, utc))
+            print 'timestamp: %s' % (format_date(rev.timestamp, rev.timezone or 0))
 
             ## opportunistic consistency check, same as check_patch_chaining
             if rev.precursor != precursor:

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2005-03-09 04:08:15 +0000
+++ b/bzrlib/osutils.py	2005-03-09 06:44:53 +0000
@@ -167,29 +167,32 @@
 
 
 
-def format_date(t, inutc=False):
+def local_time_offset():
+    if time.daylight:
+        return -time.altzone
+    else:
+        return -time.timezone
+
+    
+def format_date(t, offset=0, timezone='original'):
     ## TODO: Perhaps a global option to use either universal or local time?
     ## Or perhaps just let people set $TZ?
     import time
     
     assert isinstance(t, float)
     
-    if inutc:
+    if timezone == 'utc':
         tt = time.gmtime(t)
-        zonename = 'UTC'
         offset = 0
+    elif timezone == 'original':
+        tt = time.gmtime(t - offset)
     else:
+        assert timezone == 'local'
         tt = time.localtime(t)
-        if time.daylight:
-            zonename = time.tzname[1]
-            offset = - time.altzone
-        else:
-            zonename = time.tzname[0]
-            offset = - time.timezone
-            
+        offset = local_time_offset()
+
     return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
-            + ' ' + zonename + ' '
-            + '%+03d%02d' % (offset / 3600, (offset / 60) % 60))
+            + ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
 
 
 def compact_date(when):

=== modified file 'bzrlib/revision.py'
--- a/bzrlib/revision.py	2005-03-09 06:19:37 +0000
+++ b/bzrlib/revision.py	2005-03-09 06:44:53 +0000
@@ -17,6 +17,7 @@
 
 
 
+
 from xml import XMLMixin
 
 try:
@@ -39,6 +40,7 @@
         self.revision_id = None
         self.timestamp = None
         self.message = None
+        self.timezone = None
         self.__dict__.update(args)
 
 
@@ -50,9 +52,10 @@
     def to_element(self):
         root = Element('changeset',
                        committer = self.committer,
-                       timestamp = '%f' % self.timestamp,
+                       timestamp = '%.9f' % self.timestamp,
                        revision_id = self.revision_id,
-                       inventory_id = self.inventory_id)
+                       inventory_id = self.inventory_id,
+                       timezone = str(self.timezone))
         if self.precursor:
             root.set('precursor', self.precursor)
         root.text = '\n'
@@ -70,6 +73,9 @@
                  revision_id = root.get('revision_id'),
                  inventory_id = root.get('inventory_id'))
 
+        v = root.get('timezone')
+        cs.timezone = v and int(v)
+
         cs.message = root.findtext('message') # text of <message>
         return cs
 



More information about the Pkg-bazaar-commits mailing list