# # patch "ChangeLog" # from [9df23a2baa3247a55342a6188809040957bcb7f1] # to [dd5fc6917d93552b2ee40af4cfdb366cb813e958] # # patch "NEWS" # from [268ca8125a4334aa28342b250b3ecef5cdebb69d] # to [2bbd024be3bbebcea0325685bf322b148aa7abff] # # patch "app_state.cc" # from [cc0de5fca6542f8df529f9232a06ffe32f8b5366] # to [2d2ae92dc7b832ea49a1aa4a59871975ae25efc2] # # patch "platform.hh" # from [0e9458d97c4e769618fe133d1f1185990121e88a] # to [53e52a54ed1b569636c150010edf0a3381c9305f] # # patch "unix/fs.cc" # from [6b71610c94a70ecabfecdcf10f0aa0d880fffc7f] # to [e353582dd31c2d083e95fba1aa3c7321761a3843] # # patch "win32/fs.cc" # from [2ecc23a1ab514df19d2da8453fbd2a366837709b] # to [9ce58de1f6f841bb8bd66a3f99d465978a92df9f] # ======================================================================== --- ChangeLog 9df23a2baa3247a55342a6188809040957bcb7f1 +++ ChangeLog dd5fc6917d93552b2ee40af4cfdb366cb813e958 @@ -1,3 +1,18 @@ +2005-11-21 Matthew Gregan + + * NEWS: Minor spelling tweaks. + * platform.hh: Add get_default_confdir(). + * app_state.cc (app_state::app_state): Call get_default_confdir() + to initialize confdir. + * unix/fs.cc (get_default_confdir): Use the home directory as the + base of the default configuration dir. + * win32/fs.cc (get_default_confdir): Use either %APPDATA% or the + result of querying SHGetFolderPath() for CISDL_APPDATA as the base + of the default configuration dir. + (get_homedir): More consistent method for deciding what the user's + home directory is. Behaviour based on the documentation for Qt's + QDir::home(). + 2005-11-21 Nathaniel Smith * NEWS: Initial draft of 0.24 release notes. ======================================================================== --- NEWS 268ca8125a4334aa28342b250b3ecef5cdebb69d +++ NEWS 2bbd024be3bbebcea0325685bf322b148aa7abff @@ -7,17 +7,17 @@ be some complicated and varying function of %HOME%, %USERPROFILE%, %HOMEDRIVE%\%HOMEPATH%, whether you were running in mingw/cygwin, etc. It is now, always, - %APPDATA%\Monotone. For instance, if your configuration + %APPDATA%\monotone. For instance, if your configuration file used to be named - ...\Documents and Settings\.monotone\monotonerc + ...\Documents and Settings\user\.monotone\monotonerc it will now be named - ...\???\Monotone\monotonerc + ...\Documents and Settings\user\Application Data\monotone\monotonerc Please rename files appropriately. Major key management changes: - Private keys are no longer stored in your database. They are stored in ~/.monotone/keys/ (Unix, OS X) or - %APPDATA%\Monotone\keys\ (Windows). 'db migrate' will + %APPDATA%\monotone\keys\ (Windows). 'db migrate' will automatically move your keys out of your database and into their proper location. Consequences: - 'genkey' no longer requires a database. Simply run it @@ -40,7 +40,7 @@ monotone serve my.host.com "*" becomes monotone serve --bind=my.host.com "*" - or simple + or simply monotone serve "*" (to serve on the default port, on all interfaces). - Speaking of which, we can now bind to all interfaces; run ======================================================================== --- app_state.cc cc0de5fca6542f8df529f9232a06ffe32f8b5366 +++ app_state.cc 2d2ae92dc7b832ea49a1aa4a59871975ae25efc2 @@ -40,7 +40,7 @@ depth(-1), last(-1), diff_format(unified_diff), diff_args_provided(false), use_lca(false), execute(false), bind_address(""), bind_port(""), missing(false), unknown(false), - confdir(system_path(get_homedir()) / ".monotone"), have_set_key_dir(false) + confdir(get_default_confdir()), have_set_key_dir(false) { db.set_app(this); lua.set_app(this); ======================================================================== --- platform.hh 0e9458d97c4e769618fe133d1f1185990121e88a +++ platform.hh 53e52a54ed1b569636c150010edf0a3381c9305f @@ -49,6 +49,7 @@ // 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(); namespace path { ======================================================================== --- unix/fs.cc 6b71610c94a70ecabfecdcf10f0aa0d880fffc7f +++ unix/fs.cc e353582dd31c2d083e95fba1aa3c7321761a3843 @@ -18,20 +18,28 @@ #include "sanity.hh" #include "platform.hh" -std::string get_current_working_dir() +std::string +get_current_working_dir() { char buffer[4096]; E(getcwd(buffer, 4096), F("cannot get working directory: %s") % std::strerror(errno)); return std::string(buffer); } - -void change_current_working_dir(any_path const & to) + +void +change_current_working_dir(any_path const & to) { E(!chdir(to.as_external().c_str()), F("cannot change to directory %s: %s") % to % std::strerror(errno)); } +system_path +get_default_confdir() +{ + return system_path(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) @@ -42,12 +50,13 @@ if (home != NULL) return std::string(home); - struct passwd * pw = getpwuid(getuid()); + struct passwd * pw = getpwuid(getuid()); N(pw != NULL, F("could not find home directory for uid %d") % getuid()); return std::string(pw->pw_dir); } -utf8 tilde_expand(utf8 const & in) +utf8 +tilde_expand(utf8 const & in) { if (in().empty() || in()[0] != '~') return in; ======================================================================== --- win32/fs.cc 2ecc23a1ab514df19d2da8453fbd2a366837709b +++ win32/fs.cc 9ce58de1f6f841bb8bd66a3f99d465978a92df9f @@ -1,11 +1,11 @@ // copyright (C) 2005 nathaniel smith // all rights reserved. // licensed to the public under the terms of the GNU GPL (>= 2) // see the file COPYING for details +#define WIN32_LEAN_AND_MEAN #include #include -#define WIN32_LEAN_AND_MEAN #include #include @@ -17,7 +17,8 @@ #include "sanity.hh" #include "platform.hh" -std::string get_current_working_dir() +std::string +get_current_working_dir() { char buffer[4096]; E(getcwd(buffer, 4096), @@ -25,12 +26,31 @@ return std::string(buffer); } -void change_current_working_dir(any_path const & to) +void +change_current_working_dir(any_path const & to) { E(!chdir(to.as_external().c_str()), F("cannot change to directory %s: %s") % to % strerror(errno)); } +system_path +get_default_confdir() +{ + std::string base; + char * appdata; + appdata = getenv("APPDATA"); + if (appdata != NULL) + base = appdata; + else + { + TCHAR szPath[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath))) + base = szPath; + } + N(!base.empty(), F("could not determine configuration path")); + return system_path(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) @@ -38,52 +58,28 @@ get_homedir() { // Windows is fun! - // See thread on monotone-devel: - // Message-Id: - // URL: http://lists.gnu.org/archive/html/monotone-devel/2005-02/msg00241.html - // Since the discussion above, the code has been reverted to use always - // HOME if it is set. We now use APPDATA (e.g. C:\Documents And - // Settings\user\Application Data) rather than USERPROFILE so that we're a - // better behaved Windows application. There is still one potentially - // confusing case where a user is switching between Cygwin/MinGW shells - // and a Windows command prompt where HOME is only set up inside the - // Cygwin/MinGW shells and not globally--in this case, monotone will use - // HOME inside the Cygwin/MinGW shell and something else (probably - // APPDATA) when run in the Windows command prompt. In many ways, it's - // tempting to simplify this code to always and only use APPDATA. + // There has been much discussion about the correct way to do this, and a + // couple of methods have been tried (look at previous versions of this + // file for the discussion). For consistency, we now calculate the user's + // home path using the same technique that Qt's QDir::homePath() uses on + // Windows. char * home; - L(F("Searching for home directory\n")); - // First try MONOTONE_HOME, to give people a way out in case the cruft below - // doesn't work for them. - home = getenv("MONOTONE_HOME"); - if (home != NULL) - { - L(F("Home directory from MONOTONE_HOME\n")); - return std::string(home); - } - // Try HOME next: home = getenv("HOME"); if (home != NULL) { L(F("Home directory from HOME\n")); return std::string(home); } - // Otherwise, try APPDATA: - home = getenv("APPDATA"); - if (home != NULL) + // Otherwise, try USERPROFILE. We could also use SHGetFolderPath() to get + // at USERPROFILE without requiring it to be set as an environment + // variable, but Qt doesn't, so we won't either. + char * userprofile = getenv("USERPROFILE"); + if (userprofile != NULL) { - L(F("Home directory from APPDATA\n")); - return std::string(home); + L(F("Home directory from USERPROFILE\n")); + return std::string(userprofile); } - // Try a second method to get APPDATA: - TCHAR szPath[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath))) - { - L(F("Home directory from APPDATA (via SHGetFolderPath)\n")); - return std::string(szPath); - } - // Finally, if even that doesn't work (old version of Windows, I think?), - // try the HOMEDRIVE/HOMEPATH combo: + // Try concatenating HOMEDRIVE and HOMEPATH char * homedrive = getenv("HOMEDRIVE"); char * homepath = getenv("HOMEPATH"); if (homedrive != NULL && homepath != NULL) @@ -91,9 +87,13 @@ L(F("Home directory from HOMEDRIVE+HOMEPATH\n")); return std::string(homedrive) + std::string(homepath); } - // And if things _still_ didn't work, give up. - N(false, F("could not find home directory (tried MONOTONE_HOME, HOME, " - "APPDATA, HOMEDRIVE/HOMEPATH")); + char * systemdrive = getenv("SystemDrive"); + if (systemdrive != NULL) + { + L(F("Home directory from SystemDrive\n")); + return std::string(systemdrive); + } + return std::string("C:"); } utf8