📄 replay.c
字号:
/* * replay.c : entry point for replay RA functions for ra_serf * * ==================================================================== * Copyright (c) 2006 CollabNet. All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://subversion.tigris.org/license-1.html. * If newer versions of this license are posted there, you may use a * newer version instead, at your option. * * This software consists of voluntary contributions made by many * individuals. For exact contribution history, see the revision * history and replays, available at http://subversion.tigris.org/. * ==================================================================== */#include <apr_uri.h>#include <expat.h>#include <serf.h>#include "svn_pools.h"#include "svn_ra.h"#include "svn_dav.h"#include "svn_xml.h"#include "../libsvn_ra/ra_loader.h"#include "svn_config.h"#include "svn_delta.h"#include "svn_base64.h"#include "svn_version.h"#include "svn_path.h"#include "svn_private_config.h"#include "ra_serf.h"/* * This enum represents the current state of our XML parsing. */typedef enum { NONE = 0, REPORT, OPEN_DIR, ADD_DIR, OPEN_FILE, ADD_FILE, DELETE_ENTRY, APPLY_TEXTDELTA, CHANGE_PROP,} replay_state_e;typedef struct replay_info_t replay_info_t;struct replay_info_t { apr_pool_t *pool; void *baton; svn_stream_t *stream; replay_info_t *parent;};typedef svn_error_t *(*change_prop_t)(void *baton, const char *name, const svn_string_t *value, apr_pool_t *pool);typedef struct { apr_pool_t *pool; change_prop_t change; const char *name; svn_boolean_t del_prop; const char *data; apr_size_t len; replay_info_t *parent;} prop_info_t;typedef struct { apr_pool_t *pool; /* are we done? */ svn_boolean_t done; /* replay receiver function and baton */ const svn_delta_editor_t *editor; void *editor_baton;} replay_context_t;static void *push_state(svn_ra_serf__xml_parser_t *parser, replay_context_t *replay_ctx, replay_state_e state){ svn_ra_serf__xml_push_state(parser, state); if (state == OPEN_DIR || state == ADD_DIR || state == OPEN_FILE || state == ADD_FILE) { replay_info_t *info; info = apr_palloc(parser->state->pool, sizeof(*info)); info->pool = parser->state->pool; info->parent = parser->state->private; info->baton = NULL; info->stream = NULL; parser->state->private = info; } else if (state == CHANGE_PROP) { prop_info_t *info; info = apr_pcalloc(parser->state->pool, sizeof(*info)); info->pool = parser->state->pool; info->parent = parser->state->private; parser->state->private = info; } return parser->state->private;}static svn_error_t *start_replay(svn_ra_serf__xml_parser_t *parser, void *userData, svn_ra_serf__dav_props_t name, const char **attrs){ replay_context_t *ctx = userData; replay_state_e state; state = parser->state->current_state; if (state == NONE && strcmp(name.name, "editor-report") == 0) { push_state(parser, ctx, REPORT); } else if (state == REPORT && strcmp(name.name, "target-revision") == 0) { const char *rev; rev = svn_ra_serf__find_attr(attrs, "rev"); if (!rev) { return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Missing revision attr in target-revision element")); } SVN_ERR(ctx->editor->set_target_revision(ctx->editor_baton, SVN_STR_TO_REV(rev), parser->state->pool)); } else if (state == REPORT && strcmp(name.name, "open-root") == 0) { const char *rev; replay_info_t *info; rev = svn_ra_serf__find_attr(attrs, "rev"); if (!rev) { return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Missing revision attr in open-root element")); } info = push_state(parser, ctx, OPEN_DIR); SVN_ERR(ctx->editor->open_root(ctx->editor_baton, SVN_STR_TO_REV(rev), parser->state->pool, &info->baton)); } else if ((state == OPEN_DIR || state == ADD_DIR) && strcmp(name.name, "delete-entry") == 0) { const char *file_name, *rev; replay_info_t *info; file_name = svn_ra_serf__find_attr(attrs, "name"); if (!file_name) { return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Missing name attr in delete-entry element")); } rev = svn_ra_serf__find_attr(attrs, "rev"); if (!rev) { return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Missing revision attr in delete-entry element")); } info = push_state(parser, ctx, DELETE_ENTRY); SVN_ERR(ctx->editor->delete_entry(file_name, SVN_STR_TO_REV(rev), info->baton, parser->state->pool)); svn_ra_serf__xml_pop_state(parser); } else if ((state == OPEN_DIR || state == ADD_DIR) && strcmp(name.name, "open-directory") == 0) { const char *rev, *dirname; replay_info_t *info; dirname = svn_ra_serf__find_attr(attrs, "name"); if (!dirname) { return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Missing name attr in open-directory element")); } rev = svn_ra_serf__find_attr(attrs, "rev"); if (!rev) { return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Missing revision attr in open-directory element")); } info = push_state(parser, ctx, OPEN_DIR); SVN_ERR(ctx->editor->open_directory(dirname, info->parent->baton, SVN_STR_TO_REV(rev), parser->state->pool, &info->baton)); } else if ((state == OPEN_DIR || state == ADD_DIR) && strcmp(name.name, "add-directory") == 0) { const char *dir_name, *copyfrom, *copyrev; svn_revnum_t rev; replay_info_t *info; dir_name = svn_ra_serf__find_attr(attrs, "name"); if (!dir_name) { return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Missing name attr in add-directory element")); } copyfrom = svn_ra_serf__find_attr(attrs, "copyfrom-path"); copyrev = svn_ra_serf__find_attr(attrs, "copyfrom-rev"); if (copyrev) rev = SVN_STR_TO_REV(copyrev); else rev = SVN_INVALID_REVNUM; info = push_state(parser, ctx, ADD_DIR); SVN_ERR(ctx->editor->add_directory(dir_name, info->parent->baton, copyfrom, rev, parser->state->pool, &info->baton)); } else if ((state == OPEN_DIR || state == ADD_DIR) && strcmp(name.name, "close-directory") == 0) { replay_info_t *info = parser->state->private; SVN_ERR(ctx->editor->close_directory(info->baton, parser->state->pool)); svn_ra_serf__xml_pop_state(parser); } else if ((state == OPEN_DIR || state == ADD_DIR) && strcmp(name.name, "open-file") == 0) { const char *file_name, *rev; replay_info_t *info; file_name = svn_ra_serf__find_attr(attrs, "name"); if (!file_name) { return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Missing name attr in open-file element")); } rev = svn_ra_serf__find_attr(attrs, "rev"); if (!rev) { return svn_error_create(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL, _("Missing revision attr in open-file element")); } info = push_state(parser, ctx, OPEN_FILE); SVN_ERR(ctx->editor->open_file(file_name, info->parent->baton, SVN_STR_TO_REV(rev),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -