On Thu, 2006-07-13 at 01:43 -0700, Nathaniel Smith wrote:
> On Wed, Jul 12, 2006 at 01:09:19AM -0500, Timothy Brownawell wrote:
> > The new testsuite seems to be "done" now, but some things aren't optimal
> > yet. In particular I'd like to make tester fairly independent from the
> > rest of monotone by factoring out sanity.{cc,hh} and dependencies into a
> > libsanity or similar, and by making tester (and libsanity) not depend on
> > paths.{cc,hh} or the vocab* files (or constants.{cc,hh}).
> > 
> > So far it looks like sanity and dependencies make very minimal use of
> > these files, so this shouldn't be (much of) a problem. I'll post again
> > when I have a better idea of exactly how much would need to be changed.
> 
> I can't really tell how important these refactorings are from your
> description, but that's okay, because I trust your taste.  I do want
> to just double-check that you're not doing more work in this
> particular direction than you otherwise would, just because it's what
> you wrote up for SoC -- IIUC, last year some of your time ended up
> being used less effectively than it might have, because the project
> you were worked on was superceded by the unfolding roster design
> plans, but you kept on to make sure you fulfilled the SoC
> requirements.  So, just re-emphasizing that if you feel like calling
> the testsuite good enough and starting working on per-file DAGs or
> building a better automate or whatever else, cool; and if not (or not
> yet), cool too.

The reason behind the refactorings is that tester seems like it could be
a very useful project on its own. But, if it's all tangled up with the
rest of the monotone sources, having it be independent becomes a bit of
a pain.

So far I have sanity dependencies reduced to ui, quick_alloc, platform,
simplestring_xform, constants, and numeric_vocab. constants is only used
for default_encoding by split_into_lines, and for log_line_sz in
sanity.cc.

The lua extensions still depend on paths, transforms, and vocab.

Changes to get this are:
        * add a platform_wrapped.hh, so the platform-specific functions can
take strings instead of paths. Should be ok, since they don't do path
operations on them.
        * sanity::filename becomes a string instead of a system_path
        * display_width moves from charset to ui, and now takes a string.
Almost every place it was used, it was called as
display_width(utf8(whatever)). I'm considering instead to make sanity
not depend on ui, in which case this can be put back. (this particular
change may be slightly questionable)
        * ui.redirect_log_to now takes a string instead of a system_path. This
can also be put back if I make sanity not depend on ui.

What I have so far is attached as a diff, and is available on
nvm.tbrownaw.tester-spinoff .

Tim

# 
# old_revision [ca4b9c36ceec4c8485e7b81a222da045d1b6bfeb]
# 
# add_file "platform-wrapped.hh"
#  content [3e6a8b07b4a95429f95456a6de1424066e91eb77]
# 
# patch "ChangeLog"
#  from [8ec3d679b83d6b3a196d35543b94494e2834943c]
#    to [8a351fe5db23bb84ae8e0a571a94d9d5b38f8421]
# 
# patch "Makefile.am"
#  from [5e3ee4929ec349644742ff29ab02d1132d709065]
#    to [1e29076102800e28443e93011a2923444da83874]
# 
# patch "app_state.cc"
#  from [da582b88452d7a7f2b94fc389ea0d402d12b81cc]
#    to [b1bc0c4beed9227f28aa34bcddfe8a76ff9d9837]
# 
# patch "charset.cc"
#  from [f7b71f28c5f99965532a3fcac9580df7026d829c]
#    to [9b101e3bf300e2dd4332aee282ffd38e5e7e0393]
# 
# patch "charset.hh"
#  from [25884bb58fda092bc5dc4a34ad2ad963ccda180a]
#    to [5f90820ea70ef2c6e67aaf3ce1de0c4ca78e6638]
# 
# patch "commands.cc"
#  from [40263fe4929d57fb3a37a7c4efcbdd5dc45d588e]
#    to [0d57c5fa77ac650ffb6115cb75a8b2e4c840dc10]
# 
# patch "file_io.cc"
#  from [420b99ba06117525c991c07c5ee45eb9e1908826]
#    to [da954957486c417075659279ffdd3dc4f3a293c9]
# 
# patch "localized_file_io.cc"
#  from [848b7e4272312c3c2f2c14f660edae442f072515]
#    to [4cad41827577db94bbbaa0ce2966fee24eef9548]
# 
# patch "mkstemp.cc"
#  from [5a022575a388280c876ebcf9c398765932d4d31d]
#    to [a9c32c60895ce4375715348086be72968b41c453]
# 
# patch "mkstemp.hh"
#  from [49272da85bf48976f23a1aa2356f2478f9a5f223]
#    to [09d0fe618fa2247434b7995c3a736a5e706e2c6c]
# 
# patch "monotone.cc"
#  from [3ce745694b161a9c0e3a0d22af01a23f5db4a26c]
#    to [1006bd53670108b50985a73c1ec2cc0d3f084824]
# 
# patch "paths.cc"
#  from [4c98560ebccf3c70cfa26b985403a0a3fd66fb90]
#    to [78f969042bfc3a796ff835b15d8c4cfcf09b03d4]
# 
# patch "platform.hh"
#  from [72407170e732b62141b8a384539242e5962ebdb7]
#    to [bbfc7eea9a26a5a8d24ec268fc2a870308ebe5f5]
# 
# patch "rcs_import.cc"
#  from [661696993d2c2e824323ce3f060d7da35b6951e5]
#    to [526b1b4b9a25b6c3dfbcfd4454dfb279695200de]
# 
# patch "roster.cc"
#  from [11db51bb0cfb000c9ae885ad56380534823fd56c]
#    to [645cc0aed02ac3164d68bd76b232bf4bbd501c6e]
# 
# patch "sanity.cc"
#  from [8f3a76c6b8fb31c61d396288e92de81edbea655f]
#    to [ac14205ce27a5f5ac202b0538ee05e2ec64aad6b]
# 
# patch "sanity.hh"
#  from [c812da629224b2ebf80e0f576f6dee8aeb7afd2c]
#    to [3185cbfcd3b450d949cd44cd4ff996d52039d8fb]
# 
# patch "ui.cc"
#  from [0895d4dec27f70e997259a7a6f21b3a9df1c518f]
#    to [6d441fc0d08866bff3407cfb4eeb989964d90e96]
# 
# patch "ui.hh"
#  from [e9960fb439a4ab5f7d21b8ccda0346d290174c4e]
#    to [b8401231f681c6e18ef804329a13bc90d74b4bc0]
# 
# patch "unix/fs.cc"
#  from [5833b5cb00e799e0560372454fe9fd80f424c4c2]
#    to [dd87db18852e89c3a51bb98b7f211208d321f819]
# 
# patch "unix/inodeprint.cc"
#  from [69978997d67e2cc2e60e4fc2c1ba0a6179348525]
#    to [4dcec3bb5d73edb593fc4d1118b99253edde7469]
# 
# patch "win32/fs.cc"
#  from [974c8e8ba333902ed1b4ce95f3a2a4e1089efb92]
#    to [fb7ab5fe20474c60f6c46622308276f23a0fbdb5]
# 
# patch "win32/inodeprint.cc"
#  from [0c2f874048a2f4346078307114137aacd8a885be]
#    to [8790ea958d2bc0088d72f2d7fb0aa0d062cae9f5]
# 
# patch "work.cc"
#  from [05710dd0c0854ce19635a8e78178472d64491031]
#    to [acf08d2c3ad9a44e5ea090d2496a7de5f2971148]
# 
============================================================
--- platform-wrapped.hh 3e6a8b07b4a95429f95456a6de1424066e91eb77
+++ platform-wrapped.hh 3e6a8b07b4a95429f95456a6de1424066e91eb77
@@ -0,0 +1,38 @@
+#ifndef __PLATFORM_WRAPPED_HH__
+#define __PLATFORM_WRAPPED_HH__
+
+#include "paths.hh"
+#include "platform.hh"
+#include "transforms.hh"
+#include "vocab.hh"
+
+inline bool inodeprint_file(file_path const & file, hexenc<inodeprint> & ip)
+{
+  std::string out;
+  bool ret = inodeprint_file(file.as_external(), out);
+  inodeprint ip_raw(out);
+  encode_hexenc(ip_raw, ip);
+  return ret;
+}
+
+inline utf8 tilde_expand(utf8 const & path)
+{
+  return tilde_expand(path());
+}
+
+inline void change_current_working_dir(any_path const & to)
+{
+  change_current_working_dir(to.as_external());
+}
+
+inline path::status get_path_status(any_path const & path)
+{
+  return get_path_status(path.as_external());
+}
+
+inline void rename_clobberingly(any_path const & from, any_path const & to)
+{
+  rename_clobberingly(from.as_external(), to.as_external());
+}
+
+#endif
============================================================
--- ChangeLog   8ec3d679b83d6b3a196d35543b94494e2834943c
+++ ChangeLog   8a351fe5db23bb84ae8e0a571a94d9d5b38f8421
@@ -1,3 +1,9 @@
+2006-07-11  Timothy Brownawell  <[EMAIL PROTECTED]>
+
+       * sanity.{cc,hh} app_state.cc monotone.cc: sanity::filename is now
+       a string.
+       * ui.{cc,hh}: ui::redirect_log_to() now takes a string.
+
 2006-07-08  Richard Levitte  <[EMAIL PROTECTED]>
 
        * cmd_files.cc (CMD(fdiff)): Make the synopsis match the
============================================================
--- Makefile.am 5e3ee4929ec349644742ff29ab02d1132d709065
+++ Makefile.am 1e29076102800e28443e93011a2923444da83874
@@ -8,18 +8,20 @@
 
 SANITY_CORE_SOURCES =                                                  \
        sanity.cc sanity.hh ui.cc ui.hh quick_alloc.hh                  \
-       vocab.hh vocab.cc vocab_terms.hh vocab_macros.hh                \
-       charset.cc charset.hh                                           \
        simplestring_xform.cc simplestring_xform.hh                     \
-       constants.cc constants.hh numeric_vocab.hh paths.cc paths.hh    \
-       interner.hh hash_map.hh platform.hh
+       constants.cc constants.hh numeric_vocab.hh                      \
+       platform.hh
 
+
 LUAEXT_SOURCES =                                                       \
+       vocab.hh vocab.cc vocab_terms.hh vocab_macros.hh                \
+       charset.cc charset.hh paths.cc paths.hh                         \
+       interner.hh hash_map.hh                                         \
        lua.cc lua.hh mkstemp.cc mkstemp.hh file_io.cc file_io.hh       \
        globish.cc globish.hh basic_io.cc basic_io.hh
 
 MOST_SOURCES =                                                         \
-        $(SANITY_CORE_SOURCES) $(LUAEXT_SOURCES)                       \
+        $(SANITY_CORE_SOURCES) $(LUAEXT_SOURCES) platform-wrapped.hh   \
         app_state.cc app_state.hh                                      \
          commands.cc commands.hh $(CMD_SOURCES)                                
\
          diff_patch.cc diff_patch.hh                                   \
============================================================
--- app_state.cc        da582b88452d7a7f2b94fc389ea0d402d12b81cc
+++ app_state.cc        b1bc0c4beed9227f28aa34bcddfe8a76ff9d9837
@@ -100,7 +100,7 @@
           // The 'true' means that, e.g., if we're running checkout,
           // then it's okay for dumps to go into our starting working
           // dir's _MTN rather than the new workspace dir's _MTN.
-          global_sanity.filename = system_path(dump_path, false);
+          global_sanity.filename = system_path(dump_path, false).as_external();
         }
     }
   load_rcfiles();
============================================================
--- charset.cc  f7b71f28c5f99965532a3fcac9580df7026d829c
+++ charset.cc  9b101e3bf300e2dd4332aee282ffd38e5e7e0393
@@ -68,34 +68,6 @@
   utf = out;
 }
 
-size_t
-display_width(utf8 const & utf)
-{
-  string const & u = utf();
-  size_t sz = 0;
-  string::const_iterator i = u.begin();
-  while (i != u.end())
-    {
-      if (UNLIKELY(static_cast<u8>(*i) & static_cast<u8>(0x80)))
-        {
-          // A UTF-8 escape: consume the full escape.
-          ++i;
-          ++sz;
-          while (i != u.end()
-                 && (static_cast<u8>(*i) & static_cast<u8>(0x80))
-                 && (!(static_cast<u8>(*i) & static_cast<u8>(0x40))))
-            ++i;
-        }
-      else
-        {
-          // An ASCII-like character in the range 0..0x7F.
-          ++i;
-          ++sz;
-        }
-    }
-  return sz;
-}
-
 // Lots of gunk to avoid charset conversion as much as possible.  Running
 // iconv over every element of every path in a 30,000 file manifest takes
 // multiple seconds, which then is a minimum bound on pretty much any
============================================================
--- charset.hh  25884bb58fda092bc5dc4a34ad2ad963ccda180a
+++ charset.hh  5f90820ea70ef2c6e67aaf3ce1de0c4ca78e6638
@@ -25,9 +25,6 @@
 void utf8_to_ace(utf8 const & utf, ace & a);
 bool utf8_validate(utf8 const & utf);
 
-// Returns length in characters (not bytes).
-size_t display_width(utf8 const & utf);
-
 // Specific internal / external conversions for various vocab terms.
 void internalize_cert_name(utf8 const & utf, cert_name & c);
 void internalize_cert_name(external const & ext, cert_name & c);
============================================================
--- commands.cc 40263fe4929d57fb3a37a7c4efcbdd5dc45d588e
+++ commands.cc 0d57c5fa77ac650ffb6115cb75a8b2e4c840dc10
@@ -10,11 +10,12 @@
 #include <map>
 #include <algorithm>
 
-#include "transforms.hh"
+#include "cert.hh"
+#include "inodeprint.hh"
+#include "platform-wrapped.hh"
 #include "simplestring_xform.hh"
-#include "charset.hh"
-#include "inodeprint.hh"
-#include "cert.hh"
+#include "transforms.hh"
+#include "ui.hh"
 
 #include "cmd.hh"
 
@@ -178,7 +179,7 @@
     size_t col2 = 0;
     for (size_t i = 0; i < sorted.size(); ++i)
       {
-        size_t cmp = display_width(utf8(safe_gettext(idx(sorted, 
i)->cmdgroup.c_str())));
+        size_t cmp = display_width(safe_gettext(idx(sorted, 
i)->cmdgroup.c_str()));
         col2 = col2 > cmp ? col2 : cmp;
       }
 
@@ -189,7 +190,7 @@
             curr_group = idx(sorted, i)->cmdgroup;
             out << endl;
             out << "  " << safe_gettext(idx(sorted, i)->cmdgroup.c_str());
-            col = display_width(utf8(safe_gettext(idx(sorted, 
i)->cmdgroup.c_str()))) + 2;
+            col = display_width(safe_gettext(idx(sorted, 
i)->cmdgroup.c_str())) + 2;
             while (col++ < (col2 + 3))
               out << ' ';
           }
============================================================
--- file_io.cc  420b99ba06117525c991c07c5ee45eb9e1908826
+++ file_io.cc  da954957486c417075659279ffdd3dc4f3a293c9
@@ -20,7 +20,7 @@
 #include "sanity.hh"
 #include "simplestring_xform.hh"
 #include "charset.hh"
-#include "platform.hh"
+#include "platform-wrapped.hh"
 #include "numeric_vocab.hh"
 
 // this file deals with talking to the filesystem, loading and
============================================================
--- localized_file_io.cc        848b7e4272312c3c2f2c14f660edae442f072515
+++ localized_file_io.cc        4cad41827577db94bbbaa0ce2966fee24eef9548
@@ -8,7 +8,7 @@
 #include "simplestring_xform.hh"
 #include "charset.hh"
 #include "paths.hh"
-#include "platform.hh"
+#include "platform-wrapped.hh"
 
 using std::string;
 
============================================================
--- mkstemp.cc  5a022575a388280c876ebcf9c398765932d4d31d
+++ mkstemp.cc  a9c32c60895ce4375715348086be72968b41c453
@@ -16,7 +16,6 @@
 #include <errno.h>
 #include <unistd.h>
 
-#include "file_io.hh"
 #include "botan/botan.h"
 
 #ifndef O_BINARY
============================================================
--- mkstemp.hh  49272da85bf48976f23a1aa2356f2478f9a5f223
+++ mkstemp.hh  09d0fe618fa2247434b7995c3a736a5e706e2c6c
@@ -1,6 +1,8 @@
 #ifndef __MKSTEMP_HH__
 #define __MKSTEMP_HH__
 
+#include <string>
+
 int
 monotone_mkstemp(std::string &tmpl);
 
============================================================
--- monotone.cc 3ce745694b161a9c0e3a0d22af01a23f5db4a26c
+++ monotone.cc 1006bd53670108b50985a73c1ec2cc0d3f084824
@@ -372,11 +372,11 @@
               break;
 
             case OPT_DUMP:
-              global_sanity.filename = system_path(argstr);
+              global_sanity.filename = system_path(argstr).as_external();
               break;
 
             case OPT_LOG:
-              ui.redirect_log_to(system_path(argstr));
+              ui.redirect_log_to(system_path(argstr).as_external());
               break;
 
             case OPT_DB_NAME:
============================================================
--- paths.cc    4c98560ebccf3c70cfa26b985403a0a3fd66fb90
+++ paths.cc    78f969042bfc3a796ff835b15d8c4cfcf09b03d4
@@ -17,7 +17,7 @@
 
 #include "constants.hh"
 #include "paths.hh"
-#include "platform.hh"
+#include "platform-wrapped.hh"
 #include "sanity.hh"
 #include "interner.hh"
 #include "charset.hh"
============================================================
--- platform.hh 72407170e732b62141b8a384539242e5962ebdb7
+++ platform.hh bbfc7eea9a26a5a8d24ec268fc2a870308ebe5f5
@@ -17,9 +17,6 @@
 
 #include <string>
 
-#include "vocab.hh"
-#include "paths.hh"
-
 void read_password(std::string const & prompt, char * buf, size_t bufsz);
 void get_system_flavour(std::string & ident);
 bool is_executable(const char *path);
@@ -49,7 +46,7 @@
 // returns 'true' if it has generated a valid inodeprint; returns 'false' if
 // there was a problem, in which case we should act as if the inodeprint has
 // changed.
-bool inodeprint_file(file_path const & file, hexenc<inodeprint> & ip);
+bool inodeprint_file(std::string const & file, std::string & out);
 
 // for netsync 'serve' pidfile support
 pid_t get_process_id();
@@ -58,17 +55,17 @@
 // FIXME: BUG: this returns a string in the filesystem charset/encoding
 std::string get_current_working_dir();
 // calls N() if fails
-void change_current_working_dir(any_path const & to);
-utf8 tilde_expand(utf8 const & path);
-system_path get_default_confdir();
-utf8 get_homedir();
+void change_current_working_dir(std::string const & to);
+std::string tilde_expand(std::string const & path);
+std::string get_default_confdir();
+std::string get_homedir();
 namespace path
 {
   typedef enum { nonexistent, directory, file } status;
 };
-path::status get_path_status(any_path const & path);
+path::status get_path_status(std::string const & path);
 
-void rename_clobberingly(any_path const & from, any_path const & to);
+void rename_clobberingly(std::string const & from, std::string const & to);
 
 // strerror wrapper for OS-specific errors (e.g. use FormatMessage on Win32)
 std::string os_strerror(os_err_t errnum);
============================================================
--- rcs_import.cc       661696993d2c2e824323ce3f060d7da35b6951e5
+++ rcs_import.cc       526b1b4b9a25b6c3dfbcfd4454dfb279695200de
@@ -37,7 +37,7 @@
 #include "keys.hh"
 #include "packet.hh"
 #include "paths.hh"
-#include "platform.hh"
+#include "platform-wrapped.hh"
 #include "rcs_file.hh"
 #include "revision.hh"
 #include "safe_map.hh"
============================================================
--- roster.cc   11db51bb0cfb000c9ae885ad56380534823fd56c
+++ roster.cc   645cc0aed02ac3164d68bd76b232bf4bbd501c6e
@@ -18,6 +18,7 @@
 #include "basic_io.hh"
 #include "cset.hh"
 #include "inodeprint.hh"
+#include "platform-wrapped.hh"
 #include "roster.hh"
 #include "revision.hh"
 #include "vocab.hh"
============================================================
--- sanity.cc   8f3a76c6b8fb31c61d396288e92de81edbea655f
+++ sanity.cc   ac14205ce27a5f5ac202b0538ee05e2ec64aad6b
@@ -60,7 +60,7 @@
 {
   if (!filename.empty())
     {
-      ofstream out(filename.as_external().c_str());
+      ofstream out(filename.c_str());
       if (out)
         {
           copy(logbuf.begin(), logbuf.end(), ostream_iterator<char>(out));
============================================================
--- sanity.hh   c812da629224b2ebf80e0f576f6dee8aeb7afd2c
+++ sanity.hh   3185cbfcd3b450d949cd44cd4ff996d52039d8fb
@@ -22,7 +22,6 @@
 
 #include "i18n.h"
 #include "mt-stdint.h"
-#include "paths.hh"
 #include "quick_alloc.hh" // to get the QA() macro
 
 #ifdef __GNUC__
@@ -66,7 +65,7 @@
   bool reallyquiet;
   bool relaxed;
   boost::circular_buffer<char> logbuf;
-  system_path filename;
+  std::string filename;
   std::string gasp_dump;
   bool already_dumping;
   bool clean_shutdown;
@@ -482,6 +481,9 @@
 #define MM(obj) /* */
 #endif
 
+template <typename T>
+void dump(T const &, std::string &);
+
 template <> void dump(std::string const & obj, std::string & out);
 
 //////////////////////////////////////////////////////////////////////////
============================================================
--- ui.cc       0895d4dec27f70e997259a7a6f21b3a9df1c518f
+++ ui.cc       6d441fc0d08866bff3407cfb4eeb989964d90e96
@@ -13,12 +13,11 @@
 
 #include "config.h"
 
+#include "constants.hh"
 #include "platform.hh"
 #include "sanity.hh"
-#include "ui.hh"
-#include "charset.hh"
 #include "simplestring_xform.hh"
-#include "constants.hh"
+#include "ui.hh"
 
 #include <iostream>
 #include <fstream>
@@ -181,8 +180,8 @@
               // pad out this field to that eventual size to avoid
               // spurious re-issuing of the tick titles as we expand to
               // the goal.
-              tick->set_count_size(display_width(utf8(compose_count(tick,
-                                                                    
tick->total))));
+              tick->set_count_size(display_width(compose_count(tick,
+                                                               tick->total)));
               tick->previous_total = tick->total;
             }
           else
@@ -192,15 +191,15 @@
               // compose_count create the count string for that.  Use the
               // size of the returned count string as an initial size for
               // this tick.
-              tick->set_count_size(display_width(utf8(compose_count(tick,
-                                                                    
1048575))));
+              tick->set_count_size(display_width(compose_count(tick,
+                                                               1048575)));
             }
         }
 
       string count(compose_count(tick));
 
-      size_t title_width = display_width(utf8(tick->name));
-      size_t count_width = display_width(utf8(count));
+      size_t title_width = display_width(tick->name);
+      size_t count_width = display_width(count);
 
       if (count_width > tick->count_size)
         {
@@ -254,7 +253,7 @@
       tickline2 += ui.tick_trailer;
     }
 
-  size_t curr_sz = display_width(utf8(tickline2));
+  size_t curr_sz = display_width(tickline2);
   if (curr_sz < last_tick_len)
     tickline2.append(last_tick_len - curr_sz, ' ');
   last_tick_len = curr_sz;
@@ -265,7 +264,7 @@
       if (ui.last_write_was_a_tick)
         clog << "\n";
 
-      if (tw && display_width(utf8(tickline1)) > tw)
+      if (tw && display_width(tickline1) > tw)
         {
           // FIXME: may chop off more than necessary (because we chop by
           // bytes, not by characters)
@@ -273,7 +272,7 @@
         }
       clog << tickline1 << "\n";
     }
-  if (tw && display_width(utf8(tickline2)) > tw)
+  if (tw && display_width(tickline2) > tw)
     {
       // FIXME: may chop off more than necessary (because we chop by
       // bytes, not by characters)
@@ -484,12 +483,12 @@
 }
 
 void
-user_interface::redirect_log_to(system_path const & filename)
+user_interface::redirect_log_to(std::string const & filename)
 {
   static ofstream filestr;
   if (filestr.is_open())
     filestr.close();
-  filestr.open(filename.as_external().c_str(), ofstream::out | ofstream::app);
+  filestr.open(filename.c_str(), ofstream::out | ofstream::app);
   E(filestr.is_open(), F("failed to open log file '%s'") % filename);
   clog.rdbuf(filestr.rdbuf());
 }
@@ -513,6 +512,33 @@
   return w;
 }
 
+size_t
+display_width(std::string const & u)
+{
+  size_t sz = 0;
+  string::const_iterator i = u.begin();
+  while (i != u.end())
+    {
+      if (UNLIKELY(static_cast<u8>(*i) & static_cast<u8>(0x80)))
+        {
+          // A UTF-8 escape: consume the full escape.
+          ++i;
+          ++sz;
+          while (i != u.end()
+                 && (static_cast<u8>(*i) & static_cast<u8>(0x80))
+                 && (!(static_cast<u8>(*i) & static_cast<u8>(0x40))))
+            ++i;
+        }
+      else
+        {
+          // An ASCII-like character in the range 0..0x7F.
+          ++i;
+          ++sz;
+        }
+    }
+  return sz;
+}
+
 const locale &
 get_user_locale()
 {
============================================================
--- ui.hh       e9960fb439a4ab5f7d21b8ccda0346d290174c4e
+++ ui.hh       b8401231f681c6e18ef804329a13bc90d74b4bc0
@@ -97,7 +97,7 @@
   void set_tick_trailer(std::string const & trailer);
   void set_tick_writer(tick_writer * t_writer);
   void ensure_clean_line();
-  void redirect_log_to(system_path const & filename);
+  void redirect_log_to(std::string const & filename);
 
   void set_prog_name(std::string const & name);
   std::string output_prefix();
@@ -126,6 +126,9 @@
 // (even if there is no terminal)
 unsigned int guess_terminal_width();
 
+// Returns length in characters (not bytes).
+size_t display_width(std::string const & u);
+
 // returns the a default user locale value
 const std::locale & get_user_locale();
 
============================================================
--- unix/fs.cc  5833b5cb00e799e0560372454fe9fd80f424c4c2
+++ unix/fs.cc  dd87db18852e89c3a51bb98b7f211208d321f819
@@ -19,6 +19,8 @@
 #include "sanity.hh"
 #include "platform.hh"
 
+namespace fs = boost::filesystem;
+
 std::string
 get_current_working_dir()
 {
@@ -29,22 +31,22 @@
 }
 
 void
-change_current_working_dir(any_path const & to)
+change_current_working_dir(std::string const & to)
 {
-  E(!chdir(to.as_external().c_str()),
+  E(!chdir(to.c_str()),
     F("cannot change to directory %s: %s") % to % os_strerror(errno));
 }
 
-system_path
+std::string
 get_default_confdir()
 {
-  return system_path(get_homedir()) / ".monotone";
+  return get_homedir() + "/.monotone";
 }
 
 // FIXME: BUG: this probably mangles character sets
 // (as in, we're treating system-provided data as utf8, but it's probably in
 // the filesystem charset)
-utf8
+std::string
 get_homedir()
 {
   char * home = getenv("HOME");
@@ -56,19 +58,19 @@
   return std::string(pw->pw_dir);
 }
 
-utf8
-tilde_expand(utf8 const & in)
+std::string
+tilde_expand(std::string const & in)
 {
-  if (in().empty() || in()[0] != '~')
+  if (in.empty() || in[0] != '~')
     return in;
-  fs::path tmp(in(), fs::native);
+  fs::path tmp(in, fs::native);
   fs::path::iterator i = tmp.begin();
   if (i != tmp.end())
     {
       fs::path res;
       if (*i == "~")
         {
-          res /= get_homedir()();
+          res /= get_homedir();
           ++i;
         }
       else if (i->size() > 1 && i->at(0) == '~')
@@ -92,11 +94,11 @@
 }
 
 path::status
-get_path_status(any_path const & path)
+get_path_status(std::string const & path)
 {
   struct stat buf;
   int res;
-  res = stat(path.as_external().c_str(), &buf);
+  res = stat(path.c_str(), &buf);
   if (res < 0)
     {
       if (errno == ENOENT)
@@ -116,8 +118,8 @@
 }
 
 void
-rename_clobberingly(any_path const & from, any_path const & to)
+rename_clobberingly(std::string const & from, std::string const & to)
 {
-  E(!rename(from.as_external().c_str(), to.as_external().c_str()),
+  E(!rename(from.c_str(), to.c_str()),
     F("renaming '%s' to '%s' failed: %s") % from % to % os_strerror(errno));
 }
============================================================
--- unix/inodeprint.cc  69978997d67e2cc2e60e4fc2c1ba0a6179348525
+++ unix/inodeprint.cc  4dcec3bb5d73edb593fc4d1118b99253edde7469
@@ -70,10 +70,10 @@
   return difftime(now, then) > 0;
 }
 
-bool inodeprint_file(file_path const & file, hexenc<inodeprint> & ip)
+bool inodeprint_file(std::string const & file, std::string & out)
 {
   struct stat st;
-  if (stat(file.as_external().c_str(), &st) < 0)
+  if (stat(file.c_str(), &st) < 0)
     return false;
 
   time_t now;
@@ -121,8 +121,6 @@
 
   char digest[constants::sha1_digest_length];
   hash.final(reinterpret_cast<Botan::byte *>(digest));
-  std::string out(digest, constants::sha1_digest_length);
-  inodeprint ip_raw(out);
-  encode_hexenc(ip_raw, ip);
+  out = std::string(digest, constants::sha1_digest_length);
   return true;
 }
============================================================
--- win32/fs.cc 974c8e8ba333902ed1b4ce95f3a2a4e1089efb92
+++ win32/fs.cc fb7ab5fe20474c60f6c46622308276f23a0fbdb5
@@ -18,6 +18,8 @@
 #include "sanity.hh"
 #include "platform.hh"
 
+//namespace fs = boost::filesystem;
+
 std::string
 get_current_working_dir()
 {
@@ -31,13 +33,13 @@
 }
 
 void
-change_current_working_dir(any_path const & to)
+change_current_working_dir(std::string const & to)
 {
-  E(!chdir(to.as_external().c_str()),
+  E(!chdir(to.c_str()),
     F("cannot change to directory %s: %s") % to % strerror(errno));
 }
 
-system_path
+std::string
 get_default_confdir()
 {
   std::string base;
@@ -52,13 +54,13 @@
         base = szPath;
     }
   N(!base.empty(), F("could not determine configuration path"));
-  return system_path(base) / "monotone";
+  return base + "\\monotone");
 }
 
 // FIXME: BUG: this probably mangles character sets
 // (as in, we're treating system-provided data as utf8, but it's probably in
 // the filesystem charset)
-utf8
+std::string
 get_homedir()
 {
   // Windows is fun!
@@ -100,19 +102,19 @@
   return std::string("C:");
 }
 
-utf8
-tilde_expand(utf8 const & in)
+std::string
+tilde_expand(std::string const & in)
 {
-  if (in().empty() || in()[0] != '~')
+  if (in.empty() || in[0] != '~')
     return in;
-  fs::path tmp(in(), fs::native);
+  fs::path tmp(in, fs::native);
   fs::path::iterator i = tmp.begin();
   if (i != tmp.end())
     {
       fs::path res;
       if (*i == "~" || i->size() > 1 && i->at(0) == '~')
         {
-          fs::path restmp(get_homedir()(), fs::native);
+          fs::path restmp(get_homedir(), fs::native);
           res /= restmp;
           ++i;
         }
@@ -125,9 +127,9 @@
 }
 
 path::status
-get_path_status(any_path const & path)
+get_path_status(std::string const & path)
 {
-  fs::path p(path.as_external(), fs::native);
+  fs::path p(path, fs::native);
   if (!fs::exists(p))
     return path::nonexistent;
   else if (fs::is_directory(p))
@@ -173,7 +175,7 @@
 }
 
 void
-rename_clobberingly(any_path const & from, any_path const & to)
+rename_clobberingly(std::string const & from, std::string const & to)
 {
   static const int renameAttempts = 16;
   DWORD sleepTime = 1;
@@ -184,7 +186,7 @@
   // around the common problem where another process (e.g. a virus checker)
   // will exclusive open a file you've just touched.
   for (int i = 0; i < renameAttempts; ++i) {
-    if (rename_clobberingly_impl(from.as_external().c_str(), 
to.as_external().c_str()))
+    if (rename_clobberingly_impl(from.c_str(), to.c_str()))
       return;
     lastError = GetLastError();
     L(FL("attempted rename of '%s' to '%s' failed: (%s) %d")
============================================================
--- win32/inodeprint.cc 0c2f874048a2f4346078307114137aacd8a885be
+++ win32/inodeprint.cc 8790ea958d2bc0088d72f2d7fb0aa0d062cae9f5
@@ -26,10 +26,10 @@
   }
 };
 
-bool inodeprint_file(file_path const & file, hexenc<inodeprint> & ip)
+bool inodeprint_file(std::string const & file, std::string & out)
 {
   struct _stati64 st;
-  if (_stati64(file.as_external().c_str(), &st) < 0)
+  if (_stati64(file.c_str(), &st) < 0)
     return false;
 
   Botan::SHA_160 hash;
@@ -60,8 +60,6 @@
   I(hash.OUTPUT_LENGTH == 20);
   char digest[20];
   hash.final(reinterpret_cast<Botan::byte *>(digest));
-  std::string out(digest, hash.OUTPUT_LENGTH);
-  inodeprint ip_raw(out);
-  encode_hexenc(ip_raw, ip);
+  out = std::string(digest, hash.OUTPUT_LENGTH);
   return true;
 }
============================================================
--- work.cc     05710dd0c0854ce19635a8e78178472d64491031
+++ work.cc     acf08d2c3ad9a44e5ea090d2496a7de5f2971148
@@ -17,7 +17,7 @@
 #include "basic_io.hh"
 #include "cset.hh"
 #include "localized_file_io.hh"
-#include "platform.hh"
+#include "platform-wrapped.hh"
 #include "restrictions.hh"
 #include "sanity.hh"
 #include "safe_map.hh"
_______________________________________________
Monotone-devel mailing list
Monotone-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/monotone-devel

Reply via email to