[Pkg-bazaar-commits] ./bzr/unstable r245: - control files always in utf-8-unix format

mbp at sourcefrog.net mbp at sourcefrog.net
Fri Apr 10 07:51:32 UTC 2009


------------------------------------------------------------
revno: 245
committer: mbp at sourcefrog.net
timestamp: Wed 2005-04-13 14:07:00 +1000
message:
  - control files always in utf-8-unix format
  - command line arguments interpreted as locale encoding
modified:
  NEWS
  bzrlib/branch.py
  bzrlib/commands.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2005-04-13 02:13:10 +0000
+++ b/NEWS	2005-04-13 04:07:00 +0000
@@ -15,6 +15,8 @@
 
     * Make commit safe for hardlinked bzr trees.
 
+    * Some Unicode/locale fixes.
+
 
   INTERNAL:
 

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2005-04-13 02:13:10 +0000
+++ b/bzrlib/branch.py	2005-04-13 04:07:00 +0000
@@ -152,8 +152,25 @@
 
 
     def controlfile(self, file_or_path, mode='r'):
-        """Open a control file for this branch"""
-        return file(self.controlfilename(file_or_path), mode)
+        """Open a control file for this branch.
+
+        There are two classes of file in the control directory: text
+        and binary.  binary files are untranslated byte streams.  Text
+        control files are stored with Unix newlines and in UTF-8, even
+        if the platform or locale defaults are different.
+        """
+
+        fn = self.controlfilename(file_or_path)
+
+        if mode == 'rb' or mode == 'wb':
+            return file(fn, mode)
+        elif mode == 'r' or mode == 'w':
+            # open in binary mode anyhow so there's no newline translation
+            import codecs
+            return codecs.open(fn, mode + 'b', 'utf-8')
+        else:
+            raise BzrError("invalid controlfile mode %r" % mode)
+
 
 
     def _make_control(self):
@@ -161,7 +178,7 @@
         self.controlfile('README', 'w').write(
             "This is a Bazaar-NG control directory.\n"
             "Do not change any files in this directory.")
-        self.controlfile('branch-format', 'wb').write(BZR_BRANCH_FORMAT)
+        self.controlfile('branch-format', 'w').write(BZR_BRANCH_FORMAT)
         for d in ('text-store', 'inventory-store', 'revision-store'):
             os.mkdir(self.controlfilename(d))
         for f in ('revision-history', 'merged-patches',
@@ -182,7 +199,7 @@
         # This ignores newlines so that we can open branches created
         # on Windows from Linux and so on.  I think it might be better
         # to always make all internal files in unix format.
-        fmt = self.controlfile('branch-format', 'rb').read()
+        fmt = self.controlfile('branch-format', 'r').read()
         fmt.replace('\r\n', '')
         if fmt != BZR_BRANCH_FORMAT:
             bailout('sorry, branch format %r not supported' % fmt,
@@ -193,7 +210,9 @@
     def read_working_inventory(self):
         """Read the working inventory."""
         before = time.time()
-        inv = Inventory.read_xml(self.controlfile('inventory', 'r'))
+        # ElementTree does its own conversion from UTF-8, so open in
+        # binary.
+        inv = Inventory.read_xml(self.controlfile('inventory', 'rb'))
         mutter("loaded inventory of %d items in %f"
                % (len(inv), time.time() - before))
         return inv
@@ -208,7 +227,7 @@
         ## TODO: factor out to atomicfile?  is rename safe on windows?
         ## TODO: Maybe some kind of clean/dirty marker on inventory?
         tmpfname = self.controlfilename('inventory.tmp')
-        tmpf = file(tmpfname, 'w')
+        tmpf = file(tmpfname, 'wb')
         inv.write_xml(tmpf)
         tmpf.close()
         inv_fname = self.controlfilename('inventory')
@@ -612,7 +631,7 @@
         >>> ScratchBranch().revision_history()
         []
         """
-        return [chomp(l) for l in self.controlfile('revision-history').readlines()]
+        return [chomp(l) for l in self.controlfile('revision-history', 'r').readlines()]
 
 
     def revno(self):

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-04-13 02:13:10 +0000
+++ b/bzrlib/commands.py	2005-04-13 04:07:00 +0000
@@ -935,8 +935,13 @@
     """Execute a command.
 
     This is similar to main(), but without all the trappings for
-    logging and error handling.
+    logging and error handling.  
     """
+
+    import locale
+    enc = locale.getpreferredencoding()
+    argv = [a.decode(enc) for a in argv]
+    
     try:
         args, opts = parse_args(argv[1:])
         if 'help' in opts:



More information about the Pkg-bazaar-commits mailing list