Beispiel #1
0
void notes_handle_vcs_feedback (const ustring& directory, const ustring& feedback)
// This handles the feedback that comes from the version control system.
{
    if (directory == notes_shared_storage_folder ()) {

        unsigned int note_id = 0;

        // The following feedback indicates that somebody created a new note:
        // create mode 100644 27185458
        if (feedback.find ("create mode") != string::npos) {
            ustring s (feedback);
            s.erase (12);
            Parse parse (s);
            if (parse.words.size () == 2) {
                note_id = convert_to_int (parse.words[1]);
            }
        }

        // The following feedback indicates that somebody modified a note:
        // #	modified:   27185458
        if (feedback.find ("modified:") != string::npos) {
            ustring s (feedback);
            s.erase (12);
            note_id = convert_to_int (number_in_string (feedback));
        }

        // The following feedback indicates that somebody deleted a note:
        // #	deleted:    46473236
        if (feedback.find ("deleted:") != string::npos) {
            ustring s (feedback);
            s.erase (11);
            note_id = convert_to_int (number_in_string (feedback));
        }

        // See the following:
        // 95935882 |    9 +++++++++
        // It means that this note was edited.
        if (feedback.find (" |  ") != string::npos) {
            note_id = convert_to_int (number_in_string (feedback));
        }

        if (note_id != 0) {
            gw_message (_("Change detected for note ") + convert_to_string (note_id));
            // Update the index.
            sqlite3 *db;
            sqlite3_open(notes_index_filename ().c_str(), &db);
            sqlite3_busy_timeout(db, 1000);
            notes_store_index_entry (db, note_id);
            sqlite3_close(db);
        }
    }
}
void RemoteRepositoryAssistant::on_assistant_apply ()
{
  // Configurations.
  extern Settings *settings;
  ProjectConfiguration *projectconfig = settings->projectconfig(bible);

  // Whether to use the remote repository.
  bool use_remote_repository = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_use_repository));
  if (bible_notes_selector_bible ())
    projectconfig->git_use_remote_repository_set(use_remote_repository);
  else
    settings->genconfig.consultation_notes_git_use_remote_repository_set(use_remote_repository);

  // The remote repository URL.
  if (bible_notes_selector_bible ())
    projectconfig->git_remote_repository_url_set(repository_url_get());
  else
    settings->genconfig.consultation_notes_git_remote_repository_url_set(repository_url_get());
  
  // If the repository was cloned, move it into place.
  if (repository_was_cloned()) {
    ustring destination_data_directory;
    if (bible_notes_selector_bible ())
      destination_data_directory = project_data_directory_project(bible);
    else
      destination_data_directory = notes_shared_storage_folder ();
    unix_rmdir(destination_data_directory);
    unix_mv(persistent_clone_directory, destination_data_directory);
    // Switch rename detection off. 
    // This is necessary for the consultation notes, since git has been seen to cause spurious renames.
    GwSpawn spawn ("git");
    spawn.workingdirectory (destination_data_directory);
    spawn.arg ("config");
    spawn.arg ("--global");
    spawn.arg ("diff.renamelimit");
    spawn.arg ("0");
    spawn.run ();
  }

  if (bible_notes_selector_bible ()) {
    // Take a snapshot of the whole project.
    snapshots_shoot_project (bible);
  } else{
    // Create the index for the consultation notes.
    notes_create_index ();
  }

  // Show summary.
  gtk_assistant_set_current_page (GTK_ASSISTANT (assistant), summary_page_number);
}
Beispiel #3
0
void notes_create_index ()
// This creates an index for the notes stored in plain files.
{
    ProgressWindow progresswindow (_("Creating notes index"), false);

    // Remove any old index.
    unix_unlink (notes_index_filename ().c_str());

    // Create index database.
    sqlite3 *db;
    int rc;
    char *error = NULL;
    try {

        // Connect to the index database.
        rc = sqlite3_open(notes_index_filename ().c_str(), &db);
        if (rc)
            throw runtime_error(sqlite3_errmsg(db));
        sqlite3_busy_timeout(db, 1000);

        // Create the notes table.
        char *sql;
        sql = g_strdup_printf("create table notes (id integer, reference text, project text, category text, casefolded text, created integer, modified integer);");
        rc = sqlite3_exec(db, sql, NULL, NULL, &error);
        g_free(sql);
        // Fast writing.
        sqlite3_exec(db, "PRAGMA synchronous=OFF;", NULL, NULL, NULL);

        // Create an index for all the note files. The index will speed up note selection.
        ReadFiles note_files (notes_shared_storage_folder (), "", "");
        progresswindow.set_iterate (0, 1, note_files.files.size());
        for (unsigned int i = 0; i < note_files.files.size(); i++) {
            progresswindow.iterate ();
            notes_store_index_entry (db, convert_to_int (note_files.files[i]));
        }

    }
    catch(exception & ex) {
        gw_critical(ex.what());
        unix_unlink (notes_index_filename ().c_str());
    }

    // Close connection.
    sqlite3_close(db);
}
Beispiel #4
0
void notes_storage_verify()
// Verify / setup the project notes storage system.
{
    // Check an/or create the notes storage area.
    ustring directory;
    directory = notes_shared_storage_folder ();
    if (!g_file_test(directory.c_str(), G_FILE_TEST_IS_DIR)) {
        gw_mkdir_with_parents (directory);
    }

    // Convert old notes database to new format in separate files.
    // The reason for this is that notes in separate files can be shared through git.
    notes_convert_database_to_plain_files ();

    // If there's no index, create one.
    if (!g_file_test(notes_index_filename ().c_str(), G_FILE_TEST_IS_REGULAR)) {
        notes_create_index ();
    }
}
Beispiel #5
0
ustring notes_file_name (gint32 id)
// The filename for a note with "id".
{
    return gw_build_filename (notes_shared_storage_folder (), convert_to_string (id));
}
void RemoteRepositoryAssistant::on_button_push ()
/*
It copies the existing data, without the .git directory, into the persistent clone,
replaces any data that was there, and then pushes this data to the remote repository.
This makes the remote repository to have an exact copy of our data.
*/
{
  // Progress.
  ProgressWindow progresswindow (_("Pushing your data"), false);
  progresswindow.set_fraction (0.2);
  
  // Copy our data into a temporal location.
  ustring my_data_directory = notes_shared_storage_folder ();
  if (bible_notes_selector_bible ())
    my_data_directory = project_data_directory_project(bible);
  ustring temporal_data_directory = git_testing_directory ("mydata");
  unix_cp_r (my_data_directory, temporal_data_directory);

  // In rare cases a .git directory could have been copied along with our data. Remove that.
  unix_rmdir (gw_build_filename (temporal_data_directory, ".git"));

  // Remove all directories and all files from the persistent clone directory, but leave the .git directory
  {
    ReadDirectories rd (persistent_clone_directory, "", "");
    for (unsigned int i = 0; i < rd.directories.size(); i++) {
      if (rd.directories[i] != ".git") {
        unix_rmdir (gw_build_filename (persistent_clone_directory, rd.directories[i]));
      }
    }
    ReadFiles rf (persistent_clone_directory, "", "");
    for (unsigned int i = 0; i < rf.files.size(); i++) {
      unlink (gw_build_filename (persistent_clone_directory, rf.files[i]).c_str());
    }
  }
  
  // Move our data, from its temporal location, into the persistent clone directory.
  progresswindow.set_fraction (0.4);
  {
    ReadDirectories rd (temporal_data_directory, "", "");
    for (unsigned int i = 0; i < rd.directories.size(); i++) {
      unix_mv (gw_build_filename (temporal_data_directory, rd.directories[i]), persistent_clone_directory);
    }
    ReadFiles rf (temporal_data_directory, "", "");
    for (unsigned int i = 0; i < rf.files.size(); i++) {
      unix_mv (gw_build_filename (temporal_data_directory, rf.files[i]), persistent_clone_directory);
    }
  }

  // Commit the new data in the persistent clone directory.
  progresswindow.set_fraction (0.55);
  {
    GwSpawn spawn ("git");
    spawn.workingdirectory (persistent_clone_directory);
    spawn.arg ("add");
    spawn.arg (".");
    spawn.run ();
  }
  progresswindow.set_fraction (0.65);
  {
    GwSpawn spawn ("git");
    spawn.workingdirectory (persistent_clone_directory);
    spawn.arg ("commit");
    spawn.arg ("-a");
    spawn.arg ("-m");
    spawn.arg ("user data into repo");
    spawn.run ();
  }

  // Push our data to the remote repository.
  progresswindow.set_fraction (0.8);
  GwSpawn spawn("git");
  spawn.workingdirectory(persistent_clone_directory);
  spawn.arg ("push");
  spawn.run();

  // Take action depending on the outcome of pushing to the remote repository.
  if (spawn.exitstatus == 0) {
    // Clone okay.
    gtk_label_set_text (GTK_LABEL (label_push), _("Your data has been pushed to the remote repository"));
  } else {
    // Clone failed.
    gtk_label_set_text (GTK_LABEL (label_push), _("Your data could not be pushed to the remote repository,\nplease restart the assistant"));
    repository_unclone();
  }  
}