eden/fs/store/hg/HgImporter.cpp
/**
 * Internal helper function for use by getImportHelperPath().
 *
 * Callers should use getImportHelperPath() rather than directly calling this
 * function.
 */
Internal helper function for use by getImportHelperPath().
Callers should use getImportHelperPath() rather than directly calling this
function.
Internal helper function for use by getImportHelperPath () . Callers should use getImportHelperPath () rather than directly calling this function .
AbsolutePath findImportHelperPath() {
  if (!FLAGS_hgImportHelper.empty()) {
    return realpath(FLAGS_hgImportHelper);
  }
  const char* argv0 = gflags::GetArgv0();
  if (argv0 == nullptr) {
    throw std::runtime_error(
        "unable to find hg_import_helper.py script: "
        "unable to determine edenfs executable path");
  }
  auto programPath = realpath(argv0);
  XLOG(DBG4) << "edenfs path: " << programPath;
  auto programDir = programPath.dirname();
  auto isHelper = [](const AbsolutePath& path) {
    XLOG(DBG8) << "checking for hg_import_helper at \"" << path << "\"";
    return access(path.value().c_str(), X_OK) == 0;
  };
#ifdef _WIN32
  AbsolutePath dir{"C:\\eden\\hg_import_helper\\hg_import_helper.exe"};
  return dir;
#else
  auto path = programDir.dirname().dirname() +
      RelativePathPiece{"bin/hg_import_helper.py"};
  if (isHelper(path)) {
    return path;
  }
  path = programDir + PathComponentPiece{"hg_import_helper.py"};
  if (isHelper(path)) {
    return path;
  }
  AbsolutePathPiece dir = programDir;
  RelativePathPiece helperPath{"eden/fs/store/hg/hg_import_helper.py"};
  while (true) {
    path = dir + helperPath;
    if (isHelper(path)) {
      return path;
    }
    auto parent = dir.dirname();
    if (parent == dir) {
      throw std::runtime_error("unable to find hg_import_helper.py script");
    }
    dir = parent;
  }
#endif
}
AbsolutePath findImportHelperPath ( ) { if ( ! FLAGS_hgImportHelper . empty ( ) ) { return realpath ( FLAGS_hgImportHelper ) ; } const char * argv0 = gflags :: GetArgv0 ( ) ; if ( argv0 == nullptr ) { throw std :: runtime_error ( " " " " ) ; } auto programPath = realpath ( argv0 ) ; XLOG ( DBG4 ) << " " << programPath ; auto programDir = programPath . dirname ( ) ; auto isHelper = [ ] ( const AbsolutePath & path ) { XLOG ( DBG8 ) << " \" " << path << " \" " ; return access ( path . value ( ) . c_str ( ) , X_OK ) == 0 ; } ; #ifdef _WIN32 AbsolutePath dir { " \\ \\ \\ " } ; return dir ; #else auto path = programDir . dirname ( ) . dirname ( ) + RelativePathPiece { " " } ; if ( isHelper ( path ) ) { return path ; } path = programDir + PathComponentPiece { " " } ; if ( isHelper ( path ) ) { return path ; } AbsolutePathPiece dir = programDir ; RelativePathPiece helperPath { " " } ; while ( true ) { path = dir + helperPath ; if ( isHelper ( path ) ) { return path ; } auto parent = dir . dirname ( ) ; if ( parent == dir ) { throw std :: runtime_error ( " " ) ; } dir = parent ; } #endif }
Internal helper function for use by getImportHelperPath().
Internal helper function for use by getImportHelperPath () .
// If a path was specified on the command line, use that // TODO EDENWIN: Remove the hardcoded path and use isHelper to find // Check in ../../bin/ relative to the directory containing the edenfs binary. // This is where we expect to find the helper script in normal // deployments. // Check in the directory containing the edenfs binary as well. // edenfs and hg_import_helper.py used to be installed in the same directory // in the past.  We don't normally expect them to be kept in the same // directory any more, but continue searching here just in case.  This may // also make it easier to move hg_import_helper.py in the future if we ever // want to do so.  (However we will likely just switch to invoking // "hg debugedenimporthelper" instead.) // Now check in all parent directories of the directory containing our // binary.  This is where we will find the helper program if we are running // from the build output directory in a source code repository.