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

📄 load.c

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* load.c --- parsing a 'dumpfile'-formatted stream. * * ==================================================================== * Copyright (c) 2000-2004 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 logs, available at http://subversion.tigris.org/. * ==================================================================== */#include "svn_private_config.h"#include "svn_pools.h"#include "svn_error.h"#include "svn_fs.h"#include "svn_repos.h"#include "svn_string.h"#include "svn_path.h"#include "svn_props.h"#include "repos.h"#include "svn_private_config.h"#include <apr_lib.h>/*----------------------------------------------------------------------*//** Batons used herein **/struct parse_baton{  svn_repos_t *repos;  svn_fs_t *fs;  svn_boolean_t use_history;  svn_boolean_t use_pre_commit_hook;  svn_boolean_t use_post_commit_hook;  svn_stream_t *outstream;  enum svn_repos_load_uuid uuid_action;  const char *parent_dir;  apr_pool_t *pool;  apr_hash_t *rev_map;};struct revision_baton{  svn_revnum_t rev;  svn_fs_txn_t *txn;  svn_fs_root_t *txn_root;  const svn_string_t *datestamp;  apr_int32_t rev_offset;  struct parse_baton *pb;  apr_pool_t *pool;};struct node_baton{  const char *path;  svn_node_kind_t kind;  enum svn_node_action action;  const char *md5_checksum;     /* null, if not available */  svn_revnum_t copyfrom_rev;  const char *copyfrom_path;  struct revision_baton *rb;  apr_pool_t *pool;};/*----------------------------------------------------------------------*//** A conversion function between the two vtable types. **/static svn_repos_parse_fns2_t *fns2_from_fns(const svn_repos_parser_fns_t *fns,              apr_pool_t *pool){  svn_repos_parse_fns2_t *fns2;  fns2 = apr_palloc(pool, sizeof(*fns2));  fns2->new_revision_record = fns->new_revision_record;  fns2->uuid_record = fns->uuid_record;  fns2->new_node_record = fns->new_node_record;  fns2->set_revision_property = fns->set_revision_property;  fns2->set_node_property = fns->set_node_property;  fns2->remove_node_props = fns->remove_node_props;  fns2->set_fulltext = fns->set_fulltext;  fns2->close_node = fns->close_node;  fns2->close_revision = fns->close_revision;  fns2->delete_node_property = NULL;  fns2->apply_textdelta = NULL;  return fns2;}/*----------------------------------------------------------------------*//** The parser and related helper funcs **/static svn_error_t *stream_ran_dry(void){  return svn_error_create(SVN_ERR_INCOMPLETE_DATA, NULL,                          _("Premature end of content data in dumpstream"));}static svn_error_t *stream_malformed(void){  return svn_error_create(SVN_ERR_STREAM_MALFORMED_DATA, NULL,                          _("Dumpstream data appears to be malformed"));}/* Allocate a new hash *HEADERS in POOL, and read a series of   RFC822-style headers from STREAM.  Duplicate each header's name and   value into POOL and store in hash as a const char * ==> const char *.   The headers are assumed to be terminated by a single blank line,   which will be permanently sucked from the stream and tossed.   If the caller has already read in the first header line, it should   be passed in as FIRST_HEADER.  If not, pass NULL instead. */static svn_error_t *read_header_block(svn_stream_t *stream,                  svn_stringbuf_t *first_header,                  apr_hash_t **headers,                  apr_pool_t *pool){  *headers = apr_hash_make(pool);    while (1)    {      svn_stringbuf_t *header_str;      const char *name, *value;       svn_boolean_t eof;      apr_size_t i = 0;      if (first_header != NULL)        {          header_str = first_header;          first_header = NULL;  /* so we never visit this block again. */          eof = FALSE;        }      else        /* Read the next line into a stringbuf. */        SVN_ERR(svn_stream_readline(stream, &header_str, "\n", &eof, pool));      if (svn_stringbuf_isempty(header_str))        break;    /* end of header block */      else if (eof)        return stream_ran_dry();      /* Find the next colon in the stringbuf. */      while (header_str->data[i] != ':')        {          if (header_str->data[i] == '\0')            return svn_error_createf(SVN_ERR_STREAM_MALFORMED_DATA, NULL,                                     _("Dump stream contains a malformed "                                       "header (with no ':') at '%.20s'"),                                     header_str->data);          i++;        }      /* Create a 'name' string and point to it. */      header_str->data[i] = '\0';      name = header_str->data;      /* Skip over the NULL byte and the space following it.  */      i += 2;      if (i > header_str->len)        return svn_error_createf(SVN_ERR_STREAM_MALFORMED_DATA, NULL,                                 _("Dump stream contains a malformed "                                   "header (with no value) at '%.20s'"),                                 header_str->data);      /* Point to the 'value' string. */      value = header_str->data + i;            /* Store name/value in hash. */      apr_hash_set(*headers, name, APR_HASH_KEY_STRING, value);    }  return SVN_NO_ERROR;}/* Set *PBUF to a string of length LEN, allocated in POOL, read from STREAM.   Also read a newline from STREAM and increase *ACTUAL_LEN by the total   number of bytes read from STREAM.  */static svn_error_t *read_key_or_val(char **pbuf,                svn_filesize_t *actual_length,                svn_stream_t *stream,                apr_size_t len,                apr_pool_t *pool){  char *buf = apr_pcalloc(pool, len + 1);  apr_size_t numread;  char c;  numread = len;  SVN_ERR(svn_stream_read(stream, buf, &numread));  *actual_length += numread;  if (numread != len)    return stream_ran_dry();  buf[len] = '\0';  /* Suck up extra newline after key data */  numread = 1;  SVN_ERR(svn_stream_read(stream, &c, &numread));  *actual_length += numread;  if (numread != 1)    return stream_ran_dry();  if (c != '\n')    return stream_malformed();  *pbuf = buf;  return SVN_NO_ERROR;}/* Read CONTENT_LENGTH bytes from STREAM, parsing the bytes as an   encoded Subversion properties hash, and making multiple calls to   PARSE_FNS->set_*_property on RECORD_BATON (depending on the value   of IS_NODE.)   Set *ACTUAL_LENGTH to the number of bytes consumed from STREAM.   If an error is returned, the value of *ACTUAL_LENGTH is undefined.   Use POOL for all allocations.  */static svn_error_t *parse_property_block(svn_stream_t *stream,                     svn_filesize_t content_length,                     const svn_repos_parse_fns2_t *parse_fns,                     void *record_baton,                     svn_boolean_t is_node,                     svn_filesize_t *actual_length,                     apr_pool_t *pool){  svn_stringbuf_t *strbuf;  *actual_length = 0;  while (content_length != *actual_length)    {      char *buf;  /* a pointer into the stringbuf's data */      svn_boolean_t eof;      /* Read a key length line.  (Actually, it might be PROPS_END). */      SVN_ERR(svn_stream_readline(stream, &strbuf, "\n", &eof, pool));      if (eof)        {          /* We could just use stream_ran_dry() or stream_malformed(),             but better to give a non-generic property block error. */           return svn_error_create            (SVN_ERR_STREAM_MALFORMED_DATA, NULL,             _("Incomplete or unterminated property block"));        }      *actual_length += (strbuf->len + 1); /* +1 because we read a \n too. */      buf = strbuf->data;      if (! strcmp(buf, "PROPS-END"))        break; /* no more properties. */      else if ((buf[0] == 'K') && (buf[1] == ' '))        {          char *keybuf;          SVN_ERR(read_key_or_val(&keybuf, actual_length,                                  stream, atoi(buf + 2), pool));          /* Read a val length line */          SVN_ERR(svn_stream_readline(stream, &strbuf, "\n", &eof, pool));          if (eof)            return stream_ran_dry();          *actual_length += (strbuf->len + 1); /* +1 because we read \n too */          buf = strbuf->data;          if ((buf[0] == 'V') && (buf[1] == ' '))            {              svn_string_t propstring;              char *valbuf;              propstring.len = atoi(buf + 2);              SVN_ERR(read_key_or_val(&valbuf, actual_length,                                      stream, propstring.len, pool));              propstring.data = valbuf;              /* Now, send the property pair to the vtable! */              if (is_node)                SVN_ERR(parse_fns->set_node_property(record_baton,                                                     keybuf,                                                     &propstring));              else                SVN_ERR(parse_fns->set_revision_property(record_baton,                                                         keybuf,                                                         &propstring));            }          else            return stream_malformed(); /* didn't find expected 'V' line */        }      else if ((buf[0] == 'D') && (buf[1] == ' '))        {          char *keybuf;          SVN_ERR(read_key_or_val(&keybuf, actual_length,                                  stream, atoi(buf + 2), pool));          /* We don't expect these in revision properties, and if we see             one when we don't have a delete_node_property callback,             then we're seeing a v3 feature in a v2 dump. */          if (!is_node || !parse_fns->delete_node_property)            return stream_malformed();          SVN_ERR(parse_fns->delete_node_property(record_baton, keybuf));        }      else        return stream_malformed(); /* didn't find expected 'K' line */          } /* while (1) */  return SVN_NO_ERROR;}                  /* Read CONTENT_LENGTH bytes from STREAM, and use   PARSE_FNS->set_fulltext to push those bytes as replace fulltext for   a node.  Use BUFFER/BUFLEN to push the fulltext in "chunks".   Use POOL for all allocations.  */static svn_error_t *parse_text_block(svn_stream_t *stream,                 svn_filesize_t content_length,                 svn_boolean_t is_delta,                 const svn_repos_parse_fns2_t *parse_fns,                 void *record_baton,                 char *buffer,                 apr_size_t buflen,                 apr_pool_t *pool){  svn_stream_t *text_stream = NULL;  apr_size_t num_to_read, rlen, wlen;  if (is_delta)    {      svn_txdelta_window_handler_t wh;      void *whb;      SVN_ERR(parse_fns->apply_textdelta(&wh, &whb, record_baton));      if (wh)        text_stream = svn_txdelta_parse_svndiff(wh, whb, TRUE, pool);    }  else    {      /* Get a stream to which we can push the data. */      SVN_ERR(parse_fns->set_fulltext(&text_stream, record_baton));    }  /* If there are no contents to read, just write an empty buffer     through our callback. */  if (content_length == 0)    {      wlen = 0;      if (text_stream)        SVN_ERR(svn_stream_write(text_stream, "", &wlen));    }  /* Regardless of whether or not we have a sink for our data, we     need to read it. */  while (content_length)    {      if (content_length >= buflen)        rlen = buflen;      else        rlen = (apr_size_t) content_length;            num_to_read = rlen;      SVN_ERR(svn_stream_read(stream, buffer, &rlen));      content_length -= rlen;      if (rlen != num_to_read)        return stream_ran_dry();            if (text_stream)        {          /* write however many bytes you read. */          wlen = rlen;          SVN_ERR(svn_stream_write(text_stream, buffer, &wlen));          if (wlen != rlen)            {              /* Uh oh, didn't write as many bytes as we read. */              return svn_error_create(SVN_ERR_STREAM_UNEXPECTED_EOF, NULL,                                      _("Unexpected EOF writing contents"));            }        }    }    /* If we opened a stream, we must close it. */  if (text_stream)    SVN_ERR(svn_stream_close(text_stream));  return SVN_NO_ERROR;}/* Parse VERSIONSTRING and verify that we support the dumpfile format   version number, setting *VERSION appropriately. */static svn_error_t *parse_format_version(const char *versionstring, int *version){  static const int magic_len = sizeof(SVN_REPOS_DUMPFILE_MAGIC_HEADER) - 1;  const char *p = strchr(versionstring, ':');  int value;  if (p == NULL      || p != (versionstring + magic_len)      || strncmp(versionstring,                 SVN_REPOS_DUMPFILE_MAGIC_HEADER,                 magic_len))    return svn_error_create(SVN_ERR_STREAM_MALFORMED_DATA, NULL,                            _("Malformed dumpfile header"));  value = atoi(p+1);  if (value > SVN_REPOS_DUMPFILE_FORMAT_VERSION)    return svn_error_createf(SVN_ERR_STREAM_MALFORMED_DATA, NULL,                             _("Unsupported dumpfile version: %d"),                             value);  *version = value;  return SVN_NO_ERROR;}/* The Main Parser Logic */svn_error_t *svn_repos_parse_dumpstream2(svn_stream_t *stream,                            const svn_repos_parse_fns2_t *parse_fns,                            void *parse_baton,                            svn_cancel_func_t cancel_func,

⌨️ 快捷键说明

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