# # # add_file "localized_file_io.cc" # content [a224f91ef63f02d73e12173351f918b30c526075] # # add_file "localized_file_io.hh" # content [d522c19b24e2b9298ec80828f2b4503f656dc7fa] # # patch "ChangeLog" # from [9d48a6925823f964e9a54d74c749a8f36aa0b010] # to [370663977be26921f4776ab93b7ec53f6f8aee8d] # # patch "Makefile.am" # from [dff9212d58d7f5530cd3474b073ebb03114922f4] # to [14af4c728a8cdfc6154741d88841de958b71a7df] # # patch "cmd_diff_log.cc" # from [e4ee11b436926500bb79a452886c3570dad608af] # to [31fe8c5d41bd88bd58dae13ad2b21a8839b5a415] # # patch "cmd_files.cc" # from [6979ad01ab19f55ea0fa0a119cef5c4b7a6c4bdc] # to [d8a4d7557dacbd31b9d9b7b15b62d231dcfbfe43] # # patch "cmd_ws_commit.cc" # from [0eb0d600382530e3322fc941aeb221b313569de4] # to [130ebf460f4770ca6b39dd7c5d2b8dbf39405656] # # patch "diff_patch.cc" # from [aa0b86873084492d817470968a14537d56168bce] # to [c538374230aa5c4eb9c455418cfa55e443af7244] # # patch "file_io.cc" # from [76f4b114209f9e82c86a7af82cea0f36a75bf447] # to [7fc3a9cac7cb770a2a4fa826d3a23797cda1242e] # # patch "file_io.hh" # from [5a36a8b92ea826d425d361ffa0b34cfc65ca01ae] # to [36dc8411e9bf01109fc5f42d7ece84c2f7a03635] # # patch "roster.cc" # from [0aa31818d4a5c43136c8b6fe3ff2e0ba9f3aa751] # to [7fcb961614cdf6ae31327fd80ac9f25648fee6bd] # # patch "work.cc" # from [53ac432f1fc3241c5e2b3141bbbe01fe96ce7401] # to [0d47dba0c23494d21067c094cca9cba8acd71f3b] # ============================================================ --- localized_file_io.cc a224f91ef63f02d73e12173351f918b30c526075 +++ localized_file_io.cc a224f91ef63f02d73e12173351f918b30c526075 @@ -0,0 +1,125 @@ +#include "lua_hooks.hh" +#include "file_io.hh" +#include "localized_file_io.hh" + +#include "botan/botan.h" + +#include "transforms.hh" +#include "simplestring_xform.hh" +#include "charset.hh" +#include "paths.hh" +#include "platform.hh" + +using std::string; + +bool +ident_existing_file(file_path const & p, file_id & ident, lua_hooks & lua) +{ + switch (get_path_status(p)) + { + case path::nonexistent: + return false; + case path::file: + break; + case path::directory: + W(F("expected file '%s', but it is a directory.") % p); + return false; + } + + hexenc id; + calculate_ident(p, id, lua); + ident = file_id(id); + + return true; +} + +void +read_localized_data(file_path const & path, + data & dat, + lua_hooks & lua) +{ + string db_linesep, ext_linesep; + string db_charset, ext_charset; + + bool do_lineconv = (lua.hook_get_linesep_conv(path, db_linesep, ext_linesep) + && db_linesep != ext_linesep); + + bool do_charconv = (lua.hook_get_charset_conv(path, db_charset, ext_charset) + && db_charset != ext_charset); + + data tdat; + read_data(path, tdat); + + string tmp1, tmp2; + tmp2 = tdat(); + if (do_charconv) { + tmp1 = tmp2; + charset_convert(ext_charset, db_charset, tmp1, tmp2); + } + if (do_lineconv) { + tmp1 = tmp2; + line_end_convert(db_linesep, tmp1, tmp2); + } + dat = tmp2; +} + +void +write_localized_data(file_path const & path, + data const & dat, + lua_hooks & lua) +{ + string db_linesep, ext_linesep; + string db_charset, ext_charset; + + bool do_lineconv = (lua.hook_get_linesep_conv(path, db_linesep, ext_linesep) + && db_linesep != ext_linesep); + + bool do_charconv = (lua.hook_get_charset_conv(path, db_charset, ext_charset) + && db_charset != ext_charset); + + string tmp1, tmp2; + tmp2 = dat(); + if (do_lineconv) { + tmp1 = tmp2; + line_end_convert(ext_linesep, tmp1, tmp2); + } + if (do_charconv) { + tmp1 = tmp2; + charset_convert(db_charset, ext_charset, tmp1, tmp2); + } + + write_data(path, data(tmp2)); +} + +void +calculate_ident(file_path const & file, + hexenc & ident, + lua_hooks & lua) +{ + string db_linesep, ext_linesep; + string db_charset, ext_charset; + + bool do_lineconv = (lua.hook_get_linesep_conv(file, db_linesep, ext_linesep) + && db_linesep != ext_linesep); + + bool do_charconv = (lua.hook_get_charset_conv(file, db_charset, ext_charset) + && db_charset != ext_charset); + + if (do_charconv || do_lineconv) + { + data dat; + read_localized_data(file, dat, lua); + calculate_ident(dat, ident); + } + else + { + // no conversions necessary, use streaming form + // Best to be safe and check it isn't a dir. + assert_path_is_file(file); + Botan::Pipe p(new Botan::Hash_Filter("SHA-160"), new Botan::Hex_Encoder()); + Botan::DataSource_Stream infile(file.as_external(), true); + p.process_msg(infile); + + ident = lowercase(p.read_all_as_string()); + } +} ============================================================ --- localized_file_io.hh d522c19b24e2b9298ec80828f2b4503f656dc7fa +++ localized_file_io.hh d522c19b24e2b9298ec80828f2b4503f656dc7fa @@ -0,0 +1,24 @@ +#ifndef __LOCALIZED_FILE_IO_HH__ +#define __LOCALIZED_FILE_IO_HH__ +// This gets it's own file because it depends on lua_hooks and +// therefore app_state. Otherwise it would be in file_io.{cc,hh} +// This separation is based entirely on dependencies, not functionality. + +#include "paths.hh" +#include "vocab.hh" + +struct lua_hooks; + +void read_localized_data(file_path const & path, + data & dat, + lua_hooks & lua); +bool ident_existing_file(file_path const & p, file_id & ident, lua_hooks & lua); +void calculate_ident(file_path const & file, + hexenc & ident, + lua_hooks & lua); + +void write_localized_data(file_path const & path, + data const & dat, + lua_hooks & lua); + +#endif ============================================================ --- ChangeLog 9d48a6925823f964e9a54d74c749a8f36aa0b010 +++ ChangeLog 370663977be26921f4776ab93b7ec53f6f8aee8d @@ -1,5 +1,13 @@ 2006-05-22 Timothy Brownawell + * file_io.{cc,hh} localized_file_io.{cc,hh}: Split off the functions + that use lua_hooks (to get localization settings) into a separate file. + * Makefile.am: Adjust for having new files. + * roster.cc work.cc diff_patch.cc cmd_diff_log.cc: + * cmd_files.cc cmd_ws_commit.cc: Adjust includes. + +2006-05-22 Timothy Brownawell + * transforms.{cc,hh} charset.{cc,hh} simplestring_xform.{cc,hh}: Split up transforms.cc . Hex, base64, gzip, and ident stay in transforms. Simple string stuff (no botan or idna) goes in ============================================================ --- Makefile.am dff9212d58d7f5530cd3474b073ebb03114922f4 +++ Makefile.am 14af4c728a8cdfc6154741d88841de958b71a7df @@ -18,7 +18,7 @@ cert.cc cert.hh \ database.cc database.hh \ key_store.cc key_store.hh \ - file_io.cc file_io.hh \ + file_io.cc file_io.hh localized_file_io.cc localized_file_io.hh\ keys.cc keys.hh \ packet.cc packet.hh \ sanity.cc sanity.hh \ ============================================================ --- cmd_diff_log.cc e4ee11b436926500bb79a452886c3570dad608af +++ cmd_diff_log.cc 31fe8c5d41bd88bd58dae13ad2b21a8839b5a415 @@ -1,9 +1,10 @@ #include "cmd.hh" #include "diff_patch.hh" #include "revision.hh" #include "transforms.hh" #include "simplestring_xform.hh" #include "restrictions.hh" +#include "localized_file_io.hh" using std::set; #include ============================================================ --- cmd_files.cc 6979ad01ab19f55ea0fa0a119cef5c4b7a6c4bdc +++ cmd_files.cc d8a4d7557dacbd31b9d9b7b15b62d231dcfbfe43 @@ -5,6 +5,7 @@ #include "packet.hh" #include "annotate.hh" #include "diff_patch.hh" +#include "localized_file_io.hh" #include using std::cout; ============================================================ --- cmd_ws_commit.cc 0eb0d600382530e3322fc941aeb221b313569de4 +++ cmd_ws_commit.cc 130ebf460f4770ca6b39dd7c5d2b8dbf39405656 @@ -6,6 +6,7 @@ #include "revision.hh" #include "transforms.hh" #include "work.hh" +#include "localized_file_io.hh" #include using std::map; ============================================================ --- diff_patch.cc aa0b86873084492d817470968a14537d56168bce +++ diff_patch.cc c538374230aa5c4eb9c455418cfa55e443af7244 @@ -27,6 +27,7 @@ #include "vocab.hh" #include "revision.hh" #include "constants.hh" +#include "localized_file_io.hh" using namespace std; using boost::shared_ptr; ============================================================ --- file_io.cc 76f4b114209f9e82c86a7af82cea0f36a75bf447 +++ file_io.cc 7fc3a9cac7cb770a2a4fa826d3a23797cda1242e @@ -14,9 +14,7 @@ #include "botan/botan.h" #include "file_io.hh" -#include "lua_hooks.hh" #include "sanity.hh" -#include "transforms.hh" #include "simplestring_xform.hh" #include "charset.hh" #include "platform.hh" @@ -105,27 +103,6 @@ return get_path_status(p) == path::file; } -bool -ident_existing_file(file_path const & p, file_id & ident, lua_hooks & lua) -{ - switch (get_path_status(p)) - { - case path::nonexistent: - return false; - case path::file: - break; - case path::directory: - W(F("expected file '%s', but it is a directory.") % p); - return false; - } - - hexenc id; - calculate_ident(p, id, lua); - ident = file_id(id); - - return true; -} - static bool did_char_is_binary_init; static bool char_is_binary[256]; @@ -319,36 +296,6 @@ dat = pipe.read_all_as_string(); } -void -read_localized_data(file_path const & path, - data & dat, - lua_hooks & lua) -{ - string db_linesep, ext_linesep; - string db_charset, ext_charset; - - bool do_lineconv = (lua.hook_get_linesep_conv(path, db_linesep, ext_linesep) - && db_linesep != ext_linesep); - - bool do_charconv = (lua.hook_get_charset_conv(path, db_charset, ext_charset) - && db_charset != ext_charset); - - data tdat; - read_data(path, tdat); - - string tmp1, tmp2; - tmp2 = tdat(); - if (do_charconv) { - tmp1 = tmp2; - charset_convert(ext_charset, db_charset, tmp1, tmp2); - } - if (do_lineconv) { - tmp1 = tmp2; - line_end_convert(db_linesep, tmp1, tmp2); - } - dat = tmp2; -} - void read_directory(any_path const & path, std::vector & files, std::vector & dirs) @@ -453,34 +400,6 @@ write_data_impl(path, dat); } -void -write_localized_data(file_path const & path, - data const & dat, - lua_hooks & lua) -{ - string db_linesep, ext_linesep; - string db_charset, ext_charset; - - bool do_lineconv = (lua.hook_get_linesep_conv(path, db_linesep, ext_linesep) - && db_linesep != ext_linesep); - - bool do_charconv = (lua.hook_get_charset_conv(path, db_charset, ext_charset) - && db_charset != ext_charset); - - string tmp1, tmp2; - tmp2 = dat(); - if (do_lineconv) { - tmp1 = tmp2; - line_end_convert(ext_linesep, tmp1, tmp2); - } - if (do_charconv) { - tmp1 = tmp2; - charset_convert(db_charset, ext_charset, tmp1, tmp2); - } - - write_data(path, data(tmp2)); -} - void write_data(system_path const & path, data const & data, @@ -490,39 +409,6 @@ get_process_id()).str()); } -void -calculate_ident(file_path const & file, - hexenc & ident, - lua_hooks & lua) -{ - string db_linesep, ext_linesep; - string db_charset, ext_charset; - - bool do_lineconv = (lua.hook_get_linesep_conv(file, db_linesep, ext_linesep) - && db_linesep != ext_linesep); - - bool do_charconv = (lua.hook_get_charset_conv(file, db_charset, ext_charset) - && db_charset != ext_charset); - - if (do_charconv || do_lineconv) - { - data dat; - read_localized_data(file, dat, lua); - calculate_ident(dat, ident); - } - else - { - // no conversions necessary, use streaming form - // Best to be safe and check it isn't a dir. - assert_path_is_file(file); - Botan::Pipe p(new Botan::Hash_Filter("SHA-160"), new Botan::Hex_Encoder()); - Botan::DataSource_Stream infile(file.as_external(), true); - p.process_msg(infile); - - ident = lowercase(p.read_all_as_string()); - } -} - tree_walker::~tree_walker() {} static void ============================================================ --- file_io.hh 5a36a8b92ea826d425d361ffa0b34cfc65ca01ae +++ file_io.hh 36dc8411e9bf01109fc5f42d7ece84c2f7a03635 @@ -19,8 +19,6 @@ // level for us to say whether applying them in any given case is valid or // not. -struct lua_hooks; - // use I() void assert_path_is_nonexistent(any_path const & path); void assert_path_is_file(any_path const & path); @@ -43,7 +41,6 @@ // returns true if there is a file at 'path' bool file_exists(any_path const & path); -bool ident_existing_file(file_path const & p, file_id & ident, lua_hooks & lua); // returns true if the string content is binary according to monotone heuristic bool guess_binary(std::string const & s); @@ -68,9 +65,6 @@ any_path const & new_path); void read_data(any_path const & path, data & data); -void read_localized_data(file_path const & path, - data & dat, - lua_hooks & lua); void read_directory(any_path const & path, std::vector & files, @@ -79,10 +73,6 @@ // This function knows that "-" means "stdin". void read_data_for_command_line(utf8 const & path, data & dat); -void calculate_ident(file_path const & file, - hexenc & ident, - lua_hooks & lua); - // These are not any_path's because we make our write somewhat atomic -- we // first write to a temp file in _MTN/ (and it must be in _MTN/, not like /tmp // or something, because we can't necessarily atomic rename from /tmp to the @@ -90,9 +80,6 @@ // workspace. void write_data(file_path const & path, data const & data); void write_data(bookkeeping_path const & path, data const & data); -void write_localized_data(file_path const & path, - data const & dat, - lua_hooks & lua); // Version that takes a system_path. To work with the "somewhat atomic" // goal, it also takes as an argument the place to put the temp file. Whoever ============================================================ --- roster.cc 0aa31818d4a5c43136c8b6fe3ff2e0ba9f3aa751 +++ roster.cc 7fcb961614cdf6ae31327fd80ac9f25648fee6bd @@ -20,6 +20,7 @@ #include "vocab.hh" #include "transforms.hh" #include "simplestring_xform.hh" +#include "localized_file_io.hh" #include "parallel_iter.hh" #include "restrictions.hh" #include "safe_map.hh" ============================================================ --- work.cc 53ac432f1fc3241c5e2b3141bbbe01fe96ce7401 +++ work.cc 0d47dba0c23494d21067c094cca9cba8acd71f3b @@ -13,7 +13,7 @@ #include "app_state.hh" #include "basic_io.hh" #include "cset.hh" -#include "file_io.hh" +#include "localized_file_io.hh" #include "platform.hh" #include "restrictions.hh" #include "sanity.hh"