Beispiel #1
0
static svn_error_t *
alter_props(svn_fs_root_t *root,
            const char *fspath,
            apr_hash_t *props,
            apr_pool_t *scratch_pool)
{
    apr_pool_t *iterpool = svn_pool_create(scratch_pool);
    apr_hash_t *old_props;
    apr_array_header_t *propdiffs;
    int i;

    SVN_ERR(svn_fs_node_proplist(&old_props, root, fspath, scratch_pool));

    SVN_ERR(svn_prop_diffs(&propdiffs, props, old_props, scratch_pool));

    for (i = 0; i < propdiffs->nelts; ++i)
    {
        const svn_prop_t *prop = &APR_ARRAY_IDX(propdiffs, i, svn_prop_t);

        svn_pool_clear(iterpool);

        /* Add, change, or delete properties.  */
        SVN_ERR(svn_fs_change_node_prop(root, fspath, prop->name, prop->value,
                                        iterpool));
    }

    svn_pool_destroy(iterpool);
    return SVN_NO_ERROR;
}
Beispiel #2
0
/* Implements svn_wc_status_func3_t */
static svn_error_t *
diff_status_callback(void *baton,
                     const char *local_abspath,
                     const svn_wc_status3_t *status,
                     apr_pool_t *scratch_pool)
{
  struct diff_baton *eb = baton;
  svn_wc__db_t *db = eb->db;

  if (! status->versioned)
    return SVN_NO_ERROR; /* unversioned (includes dir externals) */

  if (status->node_status == svn_wc_status_conflicted
      && status->text_status == svn_wc_status_none
      && status->prop_status == svn_wc_status_none)
    {
      /* Node is an actual only node describing a tree conflict */
      return SVN_NO_ERROR;
    }

  /* Not text/prop modified, not copied. Easy out */
  if (status->node_status == svn_wc_status_normal && !status->copied)
    return SVN_NO_ERROR;

  /* Mark all directories where we are no longer inside as closed */
  while (eb->cur
         && !svn_dirent_is_ancestor(eb->cur->local_abspath, local_abspath))
    {
      struct node_state_t *ns = eb->cur;

      if (!ns->skip)
        {
          if (ns->propchanges)
            SVN_ERR(eb->processor->dir_changed(ns->relpath,
                                               ns->left_src,
                                               ns->right_src,
                                               ns->left_props,
                                               ns->right_props,
                                               ns->propchanges,
                                               ns->baton,
                                               eb->processor,
                                               ns->pool));
          else
            SVN_ERR(eb->processor->dir_closed(ns->relpath,
                                              ns->left_src,
                                              ns->right_src,
                                              ns->baton,
                                              eb->processor,
                                              ns->pool));
        }
      eb->cur = ns->parent;
      svn_pool_clear(ns->pool);
    }
  SVN_ERR(ensure_state(eb, svn_dirent_dirname(local_abspath, scratch_pool),
                       FALSE, scratch_pool));

  if (eb->cur && eb->cur->skip_children)
    return SVN_NO_ERROR;

  if (eb->changelist_hash != NULL
      && (!status->changelist
          || ! svn_hash_gets(eb->changelist_hash, status->changelist)))
    return SVN_NO_ERROR; /* Filtered via changelist */

  /* This code does about the same thing as the inner body of
     walk_local_nodes_diff() in diff_editor.c, except that
     it is already filtered by the status walker, doesn't have to
     account for remote changes (and many tiny other details) */

  {
    svn_boolean_t repos_only;
    svn_boolean_t local_only;
    svn_wc__db_status_t db_status;
    svn_boolean_t have_base;
    svn_node_kind_t base_kind;
    svn_node_kind_t db_kind = status->kind;
    svn_depth_t depth_below_here = svn_depth_unknown;

    const char *child_abspath = local_abspath;
    const char *child_relpath = svn_dirent_skip_ancestor(eb->anchor_abspath,
                                                         local_abspath);


    repos_only = FALSE;
    local_only = FALSE;

    /* ### optimize away this call using status info. Should
           be possible in almost every case (except conflict, missing, obst.)*/
    SVN_ERR(svn_wc__db_read_info(&db_status, NULL, NULL, NULL, NULL, NULL,
                                 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
                                 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
                                 NULL, NULL, NULL, NULL,
                                 &have_base, NULL, NULL,
                                 eb->db, local_abspath,
                                 scratch_pool, scratch_pool));
    if (!have_base)
      {
        local_only = TRUE; /* Only report additions */
      }
    else if (db_status == svn_wc__db_status_normal)
      {
        /* Simple diff */
        base_kind = db_kind;
      }
    else if (db_status == svn_wc__db_status_deleted)
      {
        svn_wc__db_status_t base_status;
        repos_only = TRUE;
        SVN_ERR(svn_wc__db_base_get_info(&base_status, &base_kind, NULL,
                                         NULL, NULL, NULL, NULL, NULL,
                                         NULL, NULL, NULL, NULL, NULL,
                                         NULL, NULL, NULL,
                                         eb->db, local_abspath,
                                         scratch_pool, scratch_pool));

        if (base_status != svn_wc__db_status_normal)
          return SVN_NO_ERROR;
      }
    else
      {
        /* working status is either added or deleted */
        svn_wc__db_status_t base_status;

        SVN_ERR(svn_wc__db_base_get_info(&base_status, &base_kind, NULL,
                                         NULL, NULL, NULL, NULL, NULL,
                                         NULL, NULL, NULL, NULL, NULL,
                                         NULL, NULL, NULL,
                                         eb->db, local_abspath,
                                         scratch_pool, scratch_pool));

        if (base_status != svn_wc__db_status_normal)
          local_only = TRUE;
        else if (base_kind != db_kind || !eb->ignore_ancestry)
          {
            repos_only = TRUE;
            local_only = TRUE;
          }
      }

    if (repos_only)
      {
        /* Report repository form deleted */
        if (base_kind == svn_node_file)
          SVN_ERR(svn_wc__diff_base_only_file(db, child_abspath,
                                              child_relpath,
                                              SVN_INVALID_REVNUM,
                                              eb->processor,
                                              eb->cur ? eb->cur->baton : NULL,
                                              scratch_pool));
        else if (base_kind == svn_node_dir)
          SVN_ERR(svn_wc__diff_base_only_dir(db, child_abspath,
                                             child_relpath,
                                             SVN_INVALID_REVNUM,
                                             depth_below_here,
                                             eb->processor,
                                             eb->cur ? eb->cur->baton : NULL,
                                             eb->cancel_func,
                                             eb->cancel_baton,
                                             scratch_pool));
      }
    else if (!local_only)
      {
        /* Diff base against actual */
        if (db_kind == svn_node_file)
          {
            SVN_ERR(svn_wc__diff_base_working_diff(db, child_abspath,
                                                   child_relpath,
                                                   SVN_INVALID_REVNUM,
                                                   eb->changelist_hash,
                                                   eb->processor,
                                                   eb->cur
                                                        ? eb->cur->baton
                                                        : NULL,
                                                   FALSE,
                                                   eb->cancel_func,
                                                   eb->cancel_baton,
                                                   scratch_pool));
          }
        else if (db_kind == svn_node_dir)
          {
            SVN_ERR(ensure_state(eb, local_abspath, FALSE, scratch_pool));

            if (status->prop_status != svn_wc_status_none
                && status->prop_status != svn_wc_status_normal)
              {
                apr_array_header_t *propchanges;
                SVN_ERR(svn_wc__db_base_get_props(&eb->cur->left_props,
                                                  eb->db, local_abspath,
                                                  eb->cur->pool,
                                                  scratch_pool));
                SVN_ERR(svn_wc__db_read_props(&eb->cur->right_props,
                                              eb->db, local_abspath,
                                              eb->cur->pool,
                                              scratch_pool));

                SVN_ERR(svn_prop_diffs(&propchanges,
                                       eb->cur->right_props,
                                       eb->cur->left_props,
                                       eb->cur->pool));

                eb->cur->propchanges = propchanges;
              }
          }
      }

    if (local_only && (db_status != svn_wc__db_status_deleted))
      {
        if (db_kind == svn_node_file)
          SVN_ERR(svn_wc__diff_local_only_file(db, child_abspath,
                                               child_relpath,
                                               eb->processor,
                                               eb->cur ? eb->cur->baton : NULL,
                                               eb->changelist_hash,
                                               FALSE,
                                               eb->cancel_func,
                                               eb->cancel_baton,
                                               scratch_pool));
        else if (db_kind == svn_node_dir)
          SVN_ERR(svn_wc__diff_local_only_dir(db, child_abspath,
                                              child_relpath, depth_below_here,
                                              eb->processor,
                                              eb->cur ? eb->cur->baton : NULL,
                                              eb->changelist_hash,
                                              FALSE,
                                              eb->cancel_func,
                                              eb->cancel_baton,
                                              scratch_pool));
      }

    if (db_kind == svn_node_dir && (local_only || repos_only))
      SVN_ERR(ensure_state(eb, local_abspath, TRUE /* skip */, scratch_pool));
  }

  return SVN_NO_ERROR;
}
Beispiel #3
0
static svn_error_t *
close_revision(void *baton)
{
  struct revision_baton *rb = baton;
  struct parse_baton *pb = rb->pb;
  const char *conflict_msg = NULL;
  svn_revnum_t committed_rev;
  svn_error_t *err;
  const char *txn_name = NULL;
  apr_hash_t *hooks_env;

  /* If we're skipping this revision we're done here. */
  if (rb->skipped)
    return SVN_NO_ERROR;

  if (rb->rev == 0)
    {
      /* Special case: set revision 0 properties when loading into an
         'empty' filesystem. */
      svn_revnum_t youngest_rev;

      SVN_ERR(svn_fs_youngest_rev(&youngest_rev, pb->fs, rb->pool));

      if (youngest_rev == 0)
        {
          apr_hash_t *orig_props;
          apr_hash_t *new_props;
          apr_array_header_t *diff;
          int i;

          SVN_ERR(svn_fs_revision_proplist(&orig_props, pb->fs, 0, rb->pool));
          new_props = svn_prop_array_to_hash(rb->revprops, rb->pool);
          SVN_ERR(svn_prop_diffs(&diff, new_props, orig_props, rb->pool));

          for (i = 0; i < diff->nelts; i++)
          {
              const svn_prop_t *prop = &APR_ARRAY_IDX(diff, i, svn_prop_t);

              SVN_ERR(change_rev_prop(pb->repos, 0, prop->name, prop->value,
                                      pb->validate_props, rb->pool));
          }
        }

      return SVN_NO_ERROR;
    }

  /* If the dumpstream doesn't have an 'svn:date' property and we
     aren't ignoring the dates in the dumpstream altogether, remove
     any 'svn:date' revision property that was set by FS layer when
     the TXN was created.  */
  if (! (pb->ignore_dates || rb->datestamp))
    {
      svn_prop_t *prop = &APR_ARRAY_PUSH(rb->revprops, svn_prop_t);
      prop->name = SVN_PROP_REVISION_DATE;
      prop->value = NULL;
    }

  /* Apply revision property changes. */
  if (rb->pb->validate_props)
    SVN_ERR(svn_repos_fs_change_txn_props(rb->txn, rb->revprops, rb->pool));
  else
    SVN_ERR(svn_fs_change_txn_props(rb->txn, rb->revprops, rb->pool));

  /* Get the txn name and hooks environment if they will be needed. */
  if (pb->use_pre_commit_hook || pb->use_post_commit_hook)
    {
      SVN_ERR(svn_repos__parse_hooks_env(&hooks_env, pb->repos->hooks_env_path,
                                         rb->pool, rb->pool));

      err = svn_fs_txn_name(&txn_name, rb->txn, rb->pool);
      if (err)
        {
          svn_error_clear(svn_fs_abort_txn(rb->txn, rb->pool));
          return svn_error_trace(err);
        }
    }

  /* Run the pre-commit hook, if so commanded. */
  if (pb->use_pre_commit_hook)
    {
      err = svn_repos__hooks_pre_commit(pb->repos, hooks_env,
                                        txn_name, rb->pool);
      if (err)
        {
          svn_error_clear(svn_fs_abort_txn(rb->txn, rb->pool));
          return svn_error_trace(err);
        }
    }

  /* Commit. */
  err = svn_fs_commit_txn(&conflict_msg, &committed_rev, rb->txn, rb->pool);
  if (SVN_IS_VALID_REVNUM(committed_rev))
    {
      if (err)
        {
          /* ### Log any error, but better yet is to rev
             ### close_revision()'s API to allow both committed_rev and err
             ### to be returned, see #3768. */
          svn_error_clear(err);
        }
    }
  else
    {
      svn_error_clear(svn_fs_abort_txn(rb->txn, rb->pool));
      if (conflict_msg)
        return svn_error_quick_wrap(err, conflict_msg);
      else
        return svn_error_trace(err);
    }

  /* Run post-commit hook, if so commanded.  */
  if (pb->use_post_commit_hook)
    {
      if ((err = svn_repos__hooks_post_commit(pb->repos, hooks_env,
                                              committed_rev, txn_name,
                                              rb->pool)))
        return svn_error_create
          (SVN_ERR_REPOS_POST_COMMIT_HOOK_FAILED, err,
           _("Commit succeeded, but post-commit hook failed"));
    }

  /* After a successful commit, must record the dump-rev -> in-repos-rev
     mapping, so that copyfrom instructions in the dump file can look up the
     correct repository revision to copy from. */
  set_revision_mapping(pb->rev_map, rb->rev, committed_rev);

  /* If the incoming dump stream has non-contiguous revisions (e.g. from
     using svndumpfilter --drop-empty-revs without --renumber-revs) then
     we must account for the missing gaps in PB->REV_MAP.  Otherwise we
     might not be able to map all mergeinfo source revisions to the correct
     revisions in the target repos. */
  if ((pb->last_rev_mapped != SVN_INVALID_REVNUM)
      && (rb->rev != pb->last_rev_mapped + 1))
    {
      svn_revnum_t i;

      for (i = pb->last_rev_mapped + 1; i < rb->rev; i++)
        {
          set_revision_mapping(pb->rev_map, i, pb->last_rev_mapped);
        }
    }

  /* Update our "last revision mapped". */
  pb->last_rev_mapped = rb->rev;

  /* Deltify the predecessors of paths changed in this revision. */
  SVN_ERR(svn_fs_deltify_revision(pb->fs, committed_rev, rb->pool));

  if (pb->notify_func)
    {
      /* ### TODO: Use proper scratch pool instead of pb->notify_pool */
      svn_repos_notify_t *notify = svn_repos_notify_create(
                                        svn_repos_notify_load_txn_committed,
                                        pb->notify_pool);

      notify->new_revision = committed_rev;
      notify->old_revision = ((committed_rev == rb->rev)
                                    ? SVN_INVALID_REVNUM
                                    : rb->rev);
      pb->notify_func(pb->notify_baton, notify, pb->notify_pool);
      svn_pool_clear(pb->notify_pool);
    }

  return SVN_NO_ERROR;
}
Beispiel #4
0
/* Diff the file PATH against its text base.  At this
 * stage we are dealing with a file that does exist in the working copy.
 *
 * DIR_BATON is the parent directory baton, PATH is the path to the file to
 * be compared.
 *
 * Do all allocation in POOL.
 *
 * ### TODO: Need to work on replace if the new filename used to be a
 * directory.
 */
static svn_error_t *
file_diff(struct diff_baton *eb,
          const char *local_abspath,
          const char *path,
          apr_pool_t *scratch_pool)
{
    svn_wc__db_t *db = eb->db;
    const char *empty_file;
    const char *original_repos_relpath;
    svn_wc__db_status_t status;
    svn_kind_t kind;
    svn_revnum_t revision;
    const svn_checksum_t *checksum;
    svn_boolean_t op_root;
    svn_boolean_t had_props, props_mod;
    svn_boolean_t have_base, have_more_work;
    svn_boolean_t replaced = FALSE;
    svn_boolean_t base_replace = FALSE;
    svn_wc__db_status_t base_status;
    svn_revnum_t base_revision = SVN_INVALID_REVNUM;
    const svn_checksum_t *base_checksum;
    const char *pristine_abspath;

    SVN_ERR(svn_wc__db_read_info(&status, &kind, &revision, NULL, NULL, NULL,
                                 NULL, NULL, NULL, NULL, &checksum, NULL,
                                 &original_repos_relpath, NULL, NULL, NULL,
                                 NULL, NULL, NULL, NULL, NULL,
                                 &op_root, &had_props, &props_mod,
                                 &have_base, &have_more_work, NULL,
                                 db, local_abspath, scratch_pool, scratch_pool));

    if ((status == svn_wc__db_status_added) && (have_base || have_more_work))
    {
        SVN_ERR(svn_wc__db_node_check_replace(&replaced, &base_replace,
                                              NULL, db, local_abspath,
                                              scratch_pool));

        if (replaced && base_replace /* && !have_more_work */)
        {
            svn_kind_t base_kind;
            SVN_ERR(svn_wc__db_base_get_info(&base_status, &base_kind,
                                             &base_revision,
                                             NULL, NULL, NULL, NULL, NULL, NULL,
                                             NULL, &base_checksum, NULL,
                                             NULL, NULL, NULL,
                                             db, local_abspath,
                                             scratch_pool, scratch_pool));

            if (base_status != svn_wc__db_status_normal
                    || base_kind != kind)
            {
                /* We can't show a replacement here */
                replaced = FALSE;
                base_replace = FALSE;
            }
        }
        else
        {
            /* We can't look in this middle working layer (yet).
               We just report the change itself.

               And if we could look at it, how would we report the addition
               of this middle layer (and maybe different layers below that)?

               For 1.7 we just do what we did before: Ignore this layering
               problem and just show how the current file got in your wc.
             */
            replaced = FALSE;
            base_replace = FALSE;
        }
    }

    /* Now refine ADDED to one of: ADDED, COPIED, MOVED_HERE. Note that only
       the latter two have corresponding pristine info to diff against.  */
    if (status == svn_wc__db_status_added)
        SVN_ERR(svn_wc__db_scan_addition(&status, NULL, NULL, NULL, NULL,
                                         &original_repos_relpath, NULL, NULL,
                                         NULL, NULL, NULL, db, local_abspath,
                                         scratch_pool, scratch_pool));


    SVN_ERR(get_empty_file(eb, &empty_file, scratch_pool));

    /* When we show a delete, we show a diff of the original pristine against
     * an empty file.
     * A base-replace is treated like a delete plus an add.
     *
     * For this kind of diff we prefer to show the deletion of what was checked
     * out over showing what was actually deleted (if that was defined by
     * a higher layer). */
    if (status == svn_wc__db_status_deleted ||
            (base_replace && ! eb->ignore_ancestry))
    {
        apr_hash_t *del_props;
        const svn_checksum_t *del_checksum;
        const char *del_text_abspath;
        const char *del_mimetype;

        if (base_replace && ! eb->ignore_ancestry)
        {
            /* We show a deletion of the information in the BASE layer */
            SVN_ERR(svn_wc__db_base_get_props(&del_props, db, local_abspath,
                                              scratch_pool, scratch_pool));

            del_checksum = base_checksum;
        }
        else
        {
            /* We show a deletion of what was actually deleted */
            SVN_ERR_ASSERT(status == svn_wc__db_status_deleted);

            SVN_ERR(svn_wc__get_pristine_props(&del_props, db, local_abspath,
                                               scratch_pool, scratch_pool));

            SVN_ERR(svn_wc__db_read_pristine_info(NULL, NULL, NULL, NULL, NULL,
                                                  NULL, &del_checksum, NULL,
                                                  NULL, db, local_abspath,
                                                  scratch_pool, scratch_pool));
        }

        SVN_ERR_ASSERT(del_checksum != NULL);

        SVN_ERR(svn_wc__db_pristine_get_path(&del_text_abspath, db,
                                             local_abspath, del_checksum,
                                             scratch_pool, scratch_pool));

        if (del_props == NULL)
            del_props = apr_hash_make(scratch_pool);

        del_mimetype = get_prop_mimetype(del_props);

        SVN_ERR(eb->callbacks->file_deleted(NULL, NULL, path,
                                            del_text_abspath,
                                            empty_file,
                                            del_mimetype,
                                            NULL,
                                            del_props,
                                            eb->callback_baton,
                                            scratch_pool));

        if (status == svn_wc__db_status_deleted)
        {
            /* We're here only for showing a delete, so we're done. */
            return SVN_NO_ERROR;
        }
    }

    if (checksum != NULL)
        SVN_ERR(svn_wc__db_pristine_get_path(&pristine_abspath, db, local_abspath,
                                             checksum,
                                             scratch_pool, scratch_pool));
    else if (base_replace && eb->ignore_ancestry)
        SVN_ERR(svn_wc__db_pristine_get_path(&pristine_abspath, db, local_abspath,
                                             base_checksum,
                                             scratch_pool, scratch_pool));
    else
        pristine_abspath = empty_file;

    /* Now deal with showing additions, or the add-half of replacements.
     * If the item is schedule-add *with history*, then we usually want
     * to see the usual working vs. text-base comparison, which will show changes
     * made since the file was copied.  But in case we're showing copies as adds,
     * we need to compare the copied file to the empty file. If we're doing a git
     * diff, and the file was copied, we need to report the file as added and
     * diff it against the text base, so that a "copied" git diff header, and
     * possibly a diff against the copy source, will be generated for it. */
    if ((! base_replace && status == svn_wc__db_status_added) ||
            (base_replace && ! eb->ignore_ancestry) ||
            ((status == svn_wc__db_status_copied ||
              status == svn_wc__db_status_moved_here) &&
             (eb->show_copies_as_adds || eb->use_git_diff_format)))
    {
        const char *translated = NULL;
        apr_hash_t *pristine_props;
        apr_hash_t *actual_props;
        const char *actual_mimetype;
        apr_array_header_t *propchanges;


        /* Get svn:mime-type from ACTUAL props of PATH. */
        SVN_ERR(svn_wc__get_actual_props(&actual_props, db, local_abspath,
                                         scratch_pool, scratch_pool));
        actual_mimetype = get_prop_mimetype(actual_props);

        /* Set the original properties to empty, then compute "changes" from
           that. Essentially, all ACTUAL props will be "added".  */
        pristine_props = apr_hash_make(scratch_pool);
        SVN_ERR(svn_prop_diffs(&propchanges, actual_props, pristine_props,
                               scratch_pool));

        SVN_ERR(svn_wc__internal_translated_file(
                    &translated, local_abspath, db, local_abspath,
                    SVN_WC_TRANSLATE_TO_NF | SVN_WC_TRANSLATE_USE_GLOBAL_TMP,
                    eb->cancel_func, eb->cancel_baton,
                    scratch_pool, scratch_pool));

        SVN_ERR(eb->callbacks->file_added(NULL, NULL, NULL, path,
                                          (! eb->show_copies_as_adds &&
                                           eb->use_git_diff_format &&
                                           status != svn_wc__db_status_added) ?
                                          pristine_abspath : empty_file,
                                          translated,
                                          0, revision,
                                          NULL,
                                          actual_mimetype,
                                          original_repos_relpath,
                                          SVN_INVALID_REVNUM, propchanges,
                                          pristine_props, eb->callback_baton,
                                          scratch_pool));
    }
    else
    {
        const char *translated = NULL;
        apr_hash_t *pristine_props;
        const char *pristine_mimetype;
        const char *actual_mimetype;
        apr_hash_t *actual_props;
        apr_array_header_t *propchanges;
        svn_boolean_t modified;

        /* Here we deal with showing pure modifications. */
        SVN_ERR(svn_wc__internal_file_modified_p(&modified, db, local_abspath,
                FALSE, scratch_pool));
        if (modified)
        {
            /* Note that this might be the _second_ time we translate
               the file, as svn_wc__text_modified_internal_p() might have used a
               tmp translated copy too.  But what the heck, diff is
               already expensive, translating twice for the sake of code
               modularity is liveable. */
            SVN_ERR(svn_wc__internal_translated_file(
                        &translated, local_abspath, db, local_abspath,
                        SVN_WC_TRANSLATE_TO_NF | SVN_WC_TRANSLATE_USE_GLOBAL_TMP,
                        eb->cancel_func, eb->cancel_baton,
                        scratch_pool, scratch_pool));
        }

        /* Get the properties, the svn:mime-type values, and compute the
           differences between the two.  */
        if (base_replace
                && eb->ignore_ancestry)
        {
            /* We don't want the normal pristine properties (which are
               from the WORKING tree). We want the pristines associated
               with the BASE tree, which are saved as "revert" props.  */
            SVN_ERR(svn_wc__db_base_get_props(&pristine_props,
                                              db, local_abspath,
                                              scratch_pool, scratch_pool));
        }
        else
        {
            /* We can only fetch the pristine props (from BASE or WORKING) if
               the node has not been replaced, or it was copied/moved here.  */
            SVN_ERR_ASSERT(!replaced
                           || status == svn_wc__db_status_copied
                           || status == svn_wc__db_status_moved_here);

            SVN_ERR(svn_wc__db_read_pristine_props(&pristine_props, db,
                                                   local_abspath,
                                                   scratch_pool, scratch_pool));

            /* baseprops will be NULL for added nodes */
            if (!pristine_props)
                pristine_props = apr_hash_make(scratch_pool);
        }
        pristine_mimetype = get_prop_mimetype(pristine_props);

        SVN_ERR(svn_wc__db_read_props(&actual_props, db, local_abspath,
                                      scratch_pool, scratch_pool));
        actual_mimetype = get_prop_mimetype(actual_props);

        SVN_ERR(svn_prop_diffs(&propchanges, actual_props, pristine_props,
                               scratch_pool));

        if (modified || propchanges->nelts > 0)
        {
            SVN_ERR(eb->callbacks->file_changed(NULL, NULL, NULL,
                                                path,
                                                modified ? pristine_abspath
                                                : NULL,
                                                translated,
                                                revision,
                                                SVN_INVALID_REVNUM,
                                                pristine_mimetype,
                                                actual_mimetype,
                                                propchanges,
                                                pristine_props,
                                                eb->callback_baton,
                                                scratch_pool));
        }
    }

    return SVN_NO_ERROR;
}
Beispiel #5
0
/* Produce a diff between two arbitrary files at LOCAL_ABSPATH1 and
 * LOCAL_ABSPATH2, using the diff callbacks from CALLBACKS.
 * Use PATH as the name passed to diff callbacks.
 * FILE1_IS_EMPTY and FILE2_IS_EMPTY are used as hints which diff callback
 * function to use to compare the files (added/deleted/changed).
 *
 * If ORIGINAL_PROPS_OVERRIDE is not NULL, use it as original properties
 * instead of reading properties from LOCAL_ABSPATH1. This is required when
 * a file replaces a directory, where LOCAL_ABSPATH1 is an empty file that
 * file content must be diffed against, but properties to diff against come
 * from the replaced directory. */
static svn_error_t *
do_arbitrary_files_diff(const char *local_abspath1,
                        const char *local_abspath2,
                        const char *path,
                        svn_boolean_t file1_is_empty,
                        svn_boolean_t file2_is_empty,
                        apr_hash_t *original_props_override,
                        const svn_wc_diff_callbacks4_t *callbacks,
                        void *diff_baton,
                        svn_client_ctx_t *ctx,
                        apr_pool_t *scratch_pool)
{
  apr_hash_t *original_props;
  apr_hash_t *modified_props;
  apr_array_header_t *prop_changes;
  svn_string_t *original_mime_type = NULL;
  svn_string_t *modified_mime_type = NULL;

  if (ctx->cancel_func)
    SVN_ERR(ctx->cancel_func(ctx->cancel_baton));

  /* Try to get properties from either file. It's OK if the files do not
   * have properties, or if they are unversioned. */
  if (original_props_override)
    original_props = original_props_override;
  else
    SVN_ERR(get_props(&original_props, local_abspath1, ctx->wc_ctx,
                      scratch_pool, scratch_pool));
  SVN_ERR(get_props(&modified_props, local_abspath2, ctx->wc_ctx,
                    scratch_pool, scratch_pool));

  SVN_ERR(svn_prop_diffs(&prop_changes, modified_props, original_props,
                         scratch_pool));

  /* Try to determine the mime-type of each file. */
  original_mime_type = svn_hash_gets(original_props, SVN_PROP_MIME_TYPE);
  if (!file1_is_empty && !original_mime_type)
    {
      const char *mime_type;
      SVN_ERR(svn_io_detect_mimetype2(&mime_type, local_abspath1,
                                      ctx->mimetypes_map, scratch_pool));

      if (mime_type)
        original_mime_type = svn_string_create(mime_type, scratch_pool);
    }

  modified_mime_type = svn_hash_gets(modified_props, SVN_PROP_MIME_TYPE);
  if (!file2_is_empty && !modified_mime_type)
    {
      const char *mime_type;
      SVN_ERR(svn_io_detect_mimetype2(&mime_type, local_abspath1,
                                      ctx->mimetypes_map, scratch_pool));

      if (mime_type)
        modified_mime_type = svn_string_create(mime_type, scratch_pool);
    }

  /* Produce the diff. */
  if (file1_is_empty && !file2_is_empty)
    SVN_ERR(callbacks->file_added(NULL, NULL, NULL, path,
                                  local_abspath1, local_abspath2,
                                  /* ### TODO get real revision info
                                   * for versioned files? */
                                  SVN_INVALID_REVNUM, SVN_INVALID_REVNUM,
                                  original_mime_type ?
                                    original_mime_type->data : NULL,
                                  modified_mime_type ?
                                    modified_mime_type->data : NULL,
                                  /* ### TODO get copyfrom? */
                                  NULL, SVN_INVALID_REVNUM,
                                  prop_changes, original_props,
                                  diff_baton, scratch_pool));
  else if (!file1_is_empty && file2_is_empty)
    SVN_ERR(callbacks->file_deleted(NULL, NULL, path,
                                    local_abspath1, local_abspath2,
                                    original_mime_type ?
                                      original_mime_type->data : NULL,
                                    modified_mime_type ?
                                      modified_mime_type->data : NULL,
                                    original_props,
                                    diff_baton, scratch_pool));
  else
    {
      svn_stream_t *file1;
      svn_stream_t *file2;
      svn_boolean_t same;
      svn_string_t *val;
      /* We have two files, which may or may not be the same.

         ### Our caller assumes that we should ignore symlinks here and
             handle them as normal paths. Perhaps that should change?
      */
      SVN_ERR(svn_stream_open_readonly(&file1, local_abspath1, scratch_pool,
                                       scratch_pool));

      SVN_ERR(svn_stream_open_readonly(&file2, local_abspath2, scratch_pool,
                                       scratch_pool));

      /* Wrap with normalization, etc. if necessary */
      if (original_props)
        {
          val = svn_hash_gets(original_props, SVN_PROP_EOL_STYLE);

          if (val)
            {
              svn_subst_eol_style_t style;
              const char *eol;
              svn_subst_eol_style_from_value(&style, &eol, val->data);

              /* ### Ignoring keywords */
              if (eol)
                file1 = svn_subst_stream_translated(file1, eol, TRUE,
                                                    NULL, FALSE,
                                                    scratch_pool);
            }
        }

      if (modified_props)
        {
          val = svn_hash_gets(modified_props, SVN_PROP_EOL_STYLE);

          if (val)
            {
              svn_subst_eol_style_t style;
              const char *eol;
              svn_subst_eol_style_from_value(&style, &eol, val->data);

              /* ### Ignoring keywords */
              if (eol)
                file2 = svn_subst_stream_translated(file2, eol, TRUE,
                                                    NULL, FALSE,
                                                    scratch_pool);
            }
        }

      SVN_ERR(svn_stream_contents_same2(&same, file1, file2, scratch_pool));

      if (! same || prop_changes->nelts > 0)
        {
          /* ### We should probably pass the normalized data we created using
                 the subst streams as that is what diff users expect */
          SVN_ERR(callbacks->file_changed(NULL, NULL, NULL, path,
                                          same ? NULL : local_abspath1,
                                          same ? NULL : local_abspath2,
                                          /* ### TODO get real revision info
                                           * for versioned files? */
                                          SVN_INVALID_REVNUM /* rev1 */,
                                          SVN_INVALID_REVNUM /* rev2 */,
                                          original_mime_type ?
                                            original_mime_type->data : NULL,
                                          modified_mime_type ?
                                            modified_mime_type->data : NULL,
                                          prop_changes, original_props,
                                          diff_baton, scratch_pool));
        }
    }

  return SVN_NO_ERROR;
}
Beispiel #6
0
/* Produce a diff of depth DEPTH for the directory at LOCAL_ABSPATH,
 * using information from the arbitrary_diff_walker_baton B.
 * LOCAL_ABSPATH is the path being crawled and can be on either side
 * of the diff depending on baton->recursing_within_added_subtree. */
static svn_error_t *
arbitrary_diff_this_dir(struct arbitrary_diff_walker_baton *b,
                        const char *local_abspath,
                        svn_depth_t depth,
                        apr_pool_t *scratch_pool)
{
  const char *local_abspath1;
  const char *local_abspath2;
  svn_node_kind_t kind1;
  svn_node_kind_t kind2;
  const char *child_relpath;
  apr_hash_t *dirents1;
  apr_hash_t *dirents2;
  apr_hash_t *merged_dirents;
  apr_array_header_t *sorted_dirents;
  int i;
  apr_pool_t *iterpool;

  if (b->recursing_within_adm_dir)
    {
      if (svn_dirent_skip_ancestor(b->adm_dir_abspath, local_abspath))
        return SVN_NO_ERROR;
      else
        {
          b->recursing_within_adm_dir = FALSE;
          b->adm_dir_abspath = NULL;
        }
    }
  else if (svn_wc_is_adm_dir(svn_dirent_basename(local_abspath, NULL),
                             scratch_pool))
    {
      b->recursing_within_adm_dir = TRUE;
      b->adm_dir_abspath = apr_pstrdup(b->pool, local_abspath);
      return SVN_NO_ERROR;
    }

  if (b->recursing_within_added_subtree)
    child_relpath = svn_dirent_skip_ancestor(b->root2_abspath, local_abspath);
  else
    child_relpath = svn_dirent_skip_ancestor(b->root1_abspath, local_abspath);
  if (!child_relpath)
    return SVN_NO_ERROR;

  local_abspath1 = svn_dirent_join(b->root1_abspath, child_relpath,
                                   scratch_pool);
  SVN_ERR(svn_io_check_resolved_path(local_abspath1, &kind1, scratch_pool));

  local_abspath2 = svn_dirent_join(b->root2_abspath, child_relpath,
                                   scratch_pool);
  SVN_ERR(svn_io_check_resolved_path(local_abspath2, &kind2, scratch_pool));

  if (depth > svn_depth_empty)
    {
      if (kind1 == svn_node_dir)
        SVN_ERR(svn_io_get_dirents3(&dirents1, local_abspath1,
                                    TRUE, /* only_check_type */
                                    scratch_pool, scratch_pool));
      else
        dirents1 = apr_hash_make(scratch_pool);
    }

  if (kind2 == svn_node_dir)
    {
      apr_hash_t *original_props;
      apr_hash_t *modified_props;
      apr_array_header_t *prop_changes;

      /* Show any property changes for this directory. */
      SVN_ERR(get_props(&original_props, local_abspath1, b->ctx->wc_ctx,
                        scratch_pool, scratch_pool));
      SVN_ERR(get_props(&modified_props, local_abspath2, b->ctx->wc_ctx,
                        scratch_pool, scratch_pool));
      SVN_ERR(svn_prop_diffs(&prop_changes, modified_props, original_props,
                             scratch_pool));
      if (prop_changes->nelts > 0)
        SVN_ERR(b->callbacks->dir_props_changed(NULL, NULL, child_relpath,
                                                FALSE /* was_added */,
                                                prop_changes, original_props,
                                                b->diff_baton,
                                                scratch_pool));

      if (depth > svn_depth_empty)
        {
          /* Read directory entries. */
          SVN_ERR(svn_io_get_dirents3(&dirents2, local_abspath2,
                                      TRUE, /* only_check_type */
                                      scratch_pool, scratch_pool));
        }
    }
  else if (depth > svn_depth_empty)
    dirents2 = apr_hash_make(scratch_pool);

  if (depth <= svn_depth_empty)
    return SVN_NO_ERROR;

  /* Compare dirents1 to dirents2 and show added/deleted/changed files. */
  merged_dirents = apr_hash_merge(scratch_pool, dirents1, dirents2,
                                  NULL, NULL);
  sorted_dirents = svn_sort__hash(merged_dirents,
                                  svn_sort_compare_items_as_paths,
                                  scratch_pool);
  iterpool = svn_pool_create(scratch_pool);
  for (i = 0; i < sorted_dirents->nelts; i++)
    {
      svn_sort__item_t elt = APR_ARRAY_IDX(sorted_dirents, i, svn_sort__item_t);
      const char *name = elt.key;
      svn_io_dirent2_t *dirent1;
      svn_io_dirent2_t *dirent2;
      const char *child1_abspath;
      const char *child2_abspath;

      svn_pool_clear(iterpool);

      if (b->ctx->cancel_func)
        SVN_ERR(b->ctx->cancel_func(b->ctx->cancel_baton));

      if (strcmp(name, SVN_WC_ADM_DIR_NAME) == 0)
        continue;

      dirent1 = svn_hash_gets(dirents1, name);
      if (!dirent1)
        {
          dirent1 = svn_io_dirent2_create(iterpool);
          dirent1->kind = svn_node_none;
        }
      dirent2 = svn_hash_gets(dirents2, name);
      if (!dirent2)
        {
          dirent2 = svn_io_dirent2_create(iterpool);
          dirent2->kind = svn_node_none;
        }

      child1_abspath = svn_dirent_join(local_abspath1, name, iterpool);
      child2_abspath = svn_dirent_join(local_abspath2, name, iterpool);

      if (dirent1->special)
        SVN_ERR(svn_io_check_resolved_path(child1_abspath, &dirent1->kind,
                                           iterpool));
      if (dirent2->special)
        SVN_ERR(svn_io_check_resolved_path(child1_abspath, &dirent2->kind,
                                           iterpool));

      if (dirent1->kind == svn_node_dir &&
          dirent2->kind == svn_node_dir)
        {
          if (depth == svn_depth_immediates)
            {
              /* Not using the walker, so show property diffs on these dirs. */
              SVN_ERR(do_arbitrary_dirs_diff(child1_abspath, child2_abspath,
                                             b->root1_abspath, b->root2_abspath,
                                             svn_depth_empty,
                                             b->callbacks, b->diff_baton,
                                             b->ctx, iterpool));
            }
          else
            {
              /* Either the walker will visit these directories (with
               * depth=infinity) and they will be processed as 'this dir'
               * later, or we're showing file children only (depth=files). */
              continue;
            }

        }

      /* Files that exist only in dirents1. */
      if (dirent1->kind == svn_node_file &&
          (dirent2->kind == svn_node_dir || dirent2->kind == svn_node_none))
        SVN_ERR(do_arbitrary_files_diff(child1_abspath, b->empty_file_abspath,
                                        svn_relpath_join(child_relpath, name,
                                                         iterpool),
                                        FALSE, TRUE, NULL,
                                        b->callbacks, b->diff_baton,
                                        b->ctx, iterpool));

      /* Files that exist only in dirents2. */
      if (dirent2->kind == svn_node_file &&
          (dirent1->kind == svn_node_dir || dirent1->kind == svn_node_none))
        {
          apr_hash_t *original_props;

          SVN_ERR(get_props(&original_props, child1_abspath, b->ctx->wc_ctx,
                            scratch_pool, scratch_pool));
          SVN_ERR(do_arbitrary_files_diff(b->empty_file_abspath, child2_abspath,
                                          svn_relpath_join(child_relpath, name,
                                                           iterpool),
                                          TRUE, FALSE, original_props,
                                          b->callbacks, b->diff_baton,
                                          b->ctx, iterpool));
        }

      /* Files that exist in dirents1 and dirents2. */
      if (dirent1->kind == svn_node_file && dirent2->kind == svn_node_file)
        SVN_ERR(do_arbitrary_files_diff(child1_abspath, child2_abspath,
                                        svn_relpath_join(child_relpath, name,
                                                         iterpool),
                                        FALSE, FALSE, NULL,
                                        b->callbacks, b->diff_baton,
                                        b->ctx, scratch_pool));

      /* Directories that only exist in dirents2. These aren't crawled
       * by this walker so we have to crawl them separately. */
      if (depth > svn_depth_files &&
          dirent2->kind == svn_node_dir &&
          (dirent1->kind == svn_node_file || dirent1->kind == svn_node_none))
        SVN_ERR(do_arbitrary_dirs_diff(child1_abspath, child2_abspath,
                                       b->root1_abspath, b->root2_abspath,
                                       depth <= svn_depth_immediates
                                         ? svn_depth_empty
                                         : svn_depth_infinity ,
                                       b->callbacks, b->diff_baton,
                                       b->ctx, iterpool));
    }

  svn_pool_destroy(iterpool);

  return SVN_NO_ERROR;
}
Beispiel #7
0
svn_error_t *
svn_ra__file_revs_from_log(svn_ra_session_t *ra_session,
                           const char *path,
                           svn_revnum_t start,
                           svn_revnum_t end,
                           svn_file_rev_handler_t handler,
                           void *handler_baton,
                           apr_pool_t *pool)
{
  svn_node_kind_t kind;
  const char *repos_url, *session_url, *fs_path;
  apr_array_header_t *condensed_targets;
  struct fr_log_message_baton lmb;
  struct rev *rev;
  apr_hash_t *last_props;
  svn_stream_t *last_stream;
  apr_pool_t *currpool, *lastpool;

  /* Fetch the absolute FS path associated with PATH. */
  SVN_ERR(get_fs_path(&fs_path, ra_session, path, pool));

  /* Check to make sure we're dealing with a file. */
  SVN_ERR(svn_ra_check_path(ra_session, path, end, &kind, pool));
  if (kind == svn_node_dir)
    return svn_error_createf(SVN_ERR_FS_NOT_FILE, NULL,
                             _("'%s' is not a file"), fs_path);

  condensed_targets = apr_array_make(pool, 1, sizeof(const char *));
  APR_ARRAY_PUSH(condensed_targets, const char *) = path;

  lmb.path = fs_path;
  lmb.eldest = NULL;
  lmb.pool = pool;

  /* Accumulate revision metadata by walking the revisions
     backwards; this allows us to follow moves/copies
     correctly. */
  SVN_ERR(svn_ra_get_log2(ra_session,
                          condensed_targets,
                          end, start, 0, /* no limit */
                          TRUE, FALSE, FALSE,
                          NULL, fr_log_message_receiver, &lmb,
                          pool));

  /* Reparent the session while we go back through the history. */
  SVN_ERR(svn_ra_get_session_url(ra_session, &session_url, pool));
  SVN_ERR(svn_ra_get_repos_root2(ra_session, &repos_url, pool));
  SVN_ERR(svn_ra_reparent(ra_session, repos_url, pool));

  currpool = svn_pool_create(pool);
  lastpool = svn_pool_create(pool);

  /* We want the first txdelta to be against the empty file. */
  last_props = apr_hash_make(lastpool);
  last_stream = svn_stream_empty(lastpool);

  /* Walk the revision list in chronological order, downloading each fulltext,
     diffing it with its predecessor, and calling the file_revs handler for
     each one.  Use two iteration pools rather than one, because the diff
     routines need to look at a sliding window of revisions.  Two pools gives
     us a ring buffer of sorts. */
  for (rev = lmb.eldest; rev; rev = rev->next)
    {
      const char *temp_path;
      apr_pool_t *tmppool;
      apr_hash_t *props;
      apr_file_t *file;
      svn_stream_t *stream;
      apr_array_header_t *prop_diffs;
      svn_txdelta_stream_t *delta_stream;
      svn_txdelta_window_handler_t delta_handler = NULL;
      void *delta_baton = NULL;

      svn_pool_clear(currpool);

      /* Get the contents of the file from the repository, and put them in
         a temporary local file. */
      SVN_ERR(svn_stream_open_unique(&stream, &temp_path, NULL,
                                     svn_io_file_del_on_pool_cleanup,
                                     currpool, currpool));
      SVN_ERR(svn_ra_get_file(ra_session, rev->path + 1, rev->revision,
                              stream, NULL, &props, currpool));
      SVN_ERR(svn_stream_close(stream));

      /* Open up a stream to the local file. */
      SVN_ERR(svn_io_file_open(&file, temp_path, APR_READ, APR_OS_DEFAULT,
                               currpool));
      stream = svn_stream_from_aprfile2(file, FALSE, currpool);

      /* Calculate the property diff */
      SVN_ERR(svn_prop_diffs(&prop_diffs, props, last_props, lastpool));

      /* Call the file_rev handler */
      SVN_ERR(handler(handler_baton, rev->path, rev->revision, rev->props,
                      FALSE, /* merged revision */
                      &delta_handler, &delta_baton, prop_diffs, lastpool));

      /* Compute and send delta if client asked for it. */
      if (delta_handler)
        {
          /* Get the content delta. Don't calculate checksums as we don't
           * use them. */
          svn_txdelta2(&delta_stream, last_stream, stream, FALSE, lastpool);

          /* And send. */
          SVN_ERR(svn_txdelta_send_txstream(delta_stream, delta_handler,
                                            delta_baton, lastpool));
        }

      /* Switch the pools and data for the next iteration */
      tmppool = currpool;
      currpool = lastpool;
      lastpool = tmppool;

      SVN_ERR(svn_stream_close(last_stream));
      last_stream = stream;
      last_props = props;
    }

  SVN_ERR(svn_stream_close(last_stream));
  svn_pool_destroy(currpool);
  svn_pool_destroy(lastpool);

  /* Reparent the session back to the original URL. */
  return svn_ra_reparent(ra_session, session_url, pool);
}