⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 changes-table.c

📁 linux subdivision ying gai ke yi le ba
💻 C
📖 第 1 页 / 共 2 页
字号:
      new_change->node_rev_id = svn_fs_base__id_copy (change->noderev_id,
                                                      pool);
      new_change->change_kind = change->kind;
      new_change->text_mod = change->text_mod;
      new_change->prop_mod = change->prop_mod;
      path = apr_pstrdup (pool, change->path);
    }

  /* Add (or update) this path. */
  apr_hash_set (changes, path, APR_HASH_KEY_STRING, new_change);

  return SVN_NO_ERROR;
}


svn_error_t *
svn_fs_bdb__changes_fetch (apr_hash_t **changes_p,
                           svn_fs_t *fs,
                           const char *key,
                           trail_t *trail)
{
  base_fs_data_t *bfd = fs->fsap_data;
  DBC *cursor;
  DBT query, result;
  int db_err = 0, db_c_err = 0;
  svn_error_t *err = SVN_NO_ERROR;
  apr_hash_t *changes = apr_hash_make (trail->pool);
  apr_pool_t *subpool = svn_pool_create (trail->pool);

  /* Get a cursor on the first record matching KEY, and then loop over
     the records, adding them to the return array. */
  svn_fs_base__trail_debug (trail, "changes", "cursor");
  SVN_ERR (BDB_WRAP (fs, "creating cursor for reading changes",
                     bfd->changes->cursor (bfd->changes, trail->db_txn,
                                           &cursor, 0)));

  /* Advance the cursor to the key that we're looking for. */
  svn_fs_base__str_to_dbt (&query, key);
  svn_fs_base__result_dbt (&result);
  db_err = cursor->c_get (cursor, &query, &result, DB_SET);
  if (! db_err)
    svn_fs_base__track_dbt (&result, trail->pool);

  while (! db_err)
    {
      change_t *change;
      skel_t *result_skel;

      /* RESULT now contains a change record associated with KEY.  We
         need to parse that skel into an change_t structure ...  */
      result_skel = svn_fs_base__parse_skel (result.data, result.size,
                                             subpool);
      if (! result_skel)
        {
          err = svn_error_createf (SVN_ERR_FS_CORRUPT, NULL,
                                   "Error reading changes for key '%s'", key);
          goto cleanup;
        }
      err = svn_fs_base__parse_change_skel (&change, result_skel, subpool);
      if (err)
        goto cleanup;

      /* ... and merge it with our return hash.  */
      err = fold_change (changes, change);
      if (err)
        goto cleanup;

      /* Now, if our change was a deletion or replacement, we have to
         blow away any changes thus far on paths that are (or, were)
         children of this path.
         ### i won't bother with another iteration pool here -- at
             most we talking about a few extra dups of paths into what
             is already a temporary subpool.
      */
      if ((change->kind == svn_fs_path_change_delete)
          || (change->kind == svn_fs_path_change_replace))
        {
          apr_hash_index_t *hi;

          for (hi = apr_hash_first (subpool, changes);
               hi;
               hi = apr_hash_next (hi))
            {
              /* KEY is the path. */
              const void *hashkey;
              apr_ssize_t klen;
              apr_hash_this (hi, &hashkey, &klen, NULL);

              /* If we come across our own path, ignore it. */
              if (strcmp (change->path, hashkey) == 0)
                continue;

              /* If we come across a child of our path, remove it. */
              if (svn_path_is_child (change->path, hashkey, subpool))
                apr_hash_set (changes, hashkey, klen, NULL);
            }
        }

      /* Advance the cursor to the next record with this same KEY, and
         fetch that record. */
      svn_fs_base__result_dbt (&result);
      db_err = cursor->c_get (cursor, &query, &result, DB_NEXT_DUP);
      if (! db_err)
        svn_fs_base__track_dbt (&result, trail->pool);

      /* Clear the per-iteration subpool. */
      svn_pool_clear (subpool);
    }

  /* Destroy the per-iteration subpool. */
  svn_pool_destroy (subpool);

  /* If there are no (more) change records for this KEY, we're
     finished.  Just return the (possibly empty) array.  Any other
     error, however, needs to get handled appropriately.  */
  if (db_err && (db_err != DB_NOTFOUND))
    err = BDB_WRAP (fs, "fetching changes", db_err);

 cleanup:
  /* Close the cursor. */
  db_c_err = cursor->c_close (cursor);

  /* If we had an error prior to closing the cursor, return the error. */
  if (err)
    return err;

  /* If our only error thus far was when we closed the cursor, return
     that error. */
  if (db_c_err)
    SVN_ERR (BDB_WRAP (fs, "closing changes cursor", db_c_err));

  /* Finally, set our return variable and get outta here. */
  *changes_p = changes;
  return SVN_NO_ERROR;
}


svn_error_t *
svn_fs_bdb__changes_fetch_raw (apr_array_header_t **changes_p,
                               svn_fs_t *fs,
                               const char *key,
                               trail_t *trail)
{
  base_fs_data_t *bfd = fs->fsap_data;
  DBC *cursor;
  DBT query, result;
  int db_err = 0, db_c_err = 0;
  svn_error_t *err = SVN_NO_ERROR;
  change_t *change;
  apr_array_header_t *changes = apr_array_make (trail->pool, 4,
                                                sizeof (change));

  /* Get a cursor on the first record matching KEY, and then loop over
     the records, adding them to the return array. */
  svn_fs_base__trail_debug (trail, "changes", "cursor");
  SVN_ERR (BDB_WRAP (fs, "creating cursor for reading changes",
                     bfd->changes->cursor (bfd->changes, trail->db_txn,
                                           &cursor, 0)));

  /* Advance the cursor to the key that we're looking for. */
  svn_fs_base__str_to_dbt (&query, key);
  svn_fs_base__result_dbt (&result);
  db_err = cursor->c_get (cursor, &query, &result, DB_SET);
  if (! db_err)
    svn_fs_base__track_dbt (&result, trail->pool);

  while (! db_err)
    {
      skel_t *result_skel;

      /* RESULT now contains a change record associated with KEY.  We
         need to parse that skel into an change_t structure ...  */
      result_skel = svn_fs_base__parse_skel (result.data, result.size,
                                             trail->pool);
      if (! result_skel)
        {
          err = svn_error_createf (SVN_ERR_FS_CORRUPT, NULL,
                                   "Error reading changes for key '%s'", key);
          goto cleanup;
        }
      err = svn_fs_base__parse_change_skel (&change, result_skel, trail->pool);
      if (err)
        goto cleanup;

      /* ... and add it to our return array.  */
      (*((change_t **) apr_array_push (changes))) = change;

      /* Advance the cursor to the next record with this same KEY, and
         fetch that record. */
      svn_fs_base__result_dbt (&result);
      db_err = cursor->c_get (cursor, &query, &result, DB_NEXT_DUP);
      if (! db_err)
        svn_fs_base__track_dbt (&result, trail->pool);
    }

  /* If there are no (more) change records for this KEY, we're
     finished.  Just return the (possibly empty) array.  Any other
     error, however, needs to get handled appropriately.  */
  if (db_err && (db_err != DB_NOTFOUND))
    err = BDB_WRAP (fs, "fetching changes", db_err);

 cleanup:
  /* Close the cursor. */
  db_c_err = cursor->c_close (cursor);

  /* If we had an error prior to closing the cursor, return the error. */
  if (err)
    return err;

  /* If our only error thus far was when we closed the cursor, return
     that error. */
  if (db_c_err)
    SVN_ERR (BDB_WRAP (fs, "closing changes cursor", db_c_err));

  /* Finally, set our return variable and get outta here. */
  *changes_p = changes;
  return SVN_NO_ERROR;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -