FreeBSD/contrib/subversion/subversion/libsvn_fs_x/low_level.c
/* Read the next entry in the changes record from file FILE and store
   the resulting change in *CHANGE_P.  If there is no next record,
   store NULL there.  Perform all allocations from POOL. */
Read the next entry in the changes record from file FILE and store
the resulting change in *CHANGE_P.  If there is no next record,
store NULL there.  Perform all allocations from POOL.
Read the next entry in the changes record from file FILE and store the resulting change in * CHANGE_P . If there is no next record store NULL there . Perform all allocations from POOL .
static svn_error_t *
read_change(svn_fs_x__change_t **change_p,
            svn_stream_t *stream,
            apr_pool_t *result_pool,
            apr_pool_t *scratch_pool)
{
  svn_stringbuf_t *line;
  svn_boolean_t eof = TRUE;
  svn_fs_x__change_t *change;
  char *str, *last_str, *kind_str;
  *change_p = NULL;
  SVN_ERR(svn_stream_readline(stream, &line, "\n", &eof, scratch_pool));
  if (eof || (line->len == 0))
    return SVN_NO_ERROR;
  change = apr_pcalloc(result_pool, sizeof(*change));
  last_str = line->data;
  str = svn_cstring_tokenize(" ", &last_str);
  if (str == NULL)
    return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                            _("Invalid changes line in rev-file"));
  SVN_ERR(svn_fs_x__id_parse(&change->noderev_id, str));
  str = svn_cstring_tokenize(" ", &last_str);
  if (str == NULL)
    return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                            _("Invalid changes line in rev-file"));
  change->node_kind = svn_node_unknown;
  kind_str = strchr(str, '-');
  if (kind_str)
    {
      *kind_str = '\0';
      kind_str++;
      if (strcmp(kind_str, SVN_FS_X__KIND_FILE) == 0)
        change->node_kind = svn_node_file;
      else if (strcmp(kind_str, SVN_FS_X__KIND_DIR) == 0)
        change->node_kind = svn_node_dir;
      else
        return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                                _("Invalid changes line in rev-file"));
    }
  if (strcmp(str, ACTION_MODIFY) == 0)
    {
      change->change_kind = svn_fs_path_change_modify;
    }
  else if (strcmp(str, ACTION_ADD) == 0)
    {
      change->change_kind = svn_fs_path_change_add;
    }
  else if (strcmp(str, ACTION_DELETE) == 0)
    {
      change->change_kind = svn_fs_path_change_delete;
    }
  else if (strcmp(str, ACTION_REPLACE) == 0)
    {
      change->change_kind = svn_fs_path_change_replace;
    }
  else if (strcmp(str, ACTION_RESET) == 0)
    {
      change->change_kind = svn_fs_path_change_reset;
    }
  else
    {
      return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                              _("Invalid change kind in rev file"));
    }
  str = svn_cstring_tokenize(" ", &last_str);
  if (str == NULL)
    return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                            _("Invalid changes line in rev-file"));
  if (strcmp(str, FLAG_TRUE) == 0)
    {
      change->text_mod = TRUE;
    }
  else if (strcmp(str, FLAG_FALSE) == 0)
    {
      change->text_mod = FALSE;
    }
  else
    {
      return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                              _("Invalid text-mod flag in rev-file"));
    }
  str = svn_cstring_tokenize(" ", &last_str);
  if (str == NULL)
    return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                            _("Invalid changes line in rev-file"));
  if (strcmp(str, FLAG_TRUE) == 0)
    {
      change->prop_mod = TRUE;
    }
  else if (strcmp(str, FLAG_FALSE) == 0)
    {
      change->prop_mod = FALSE;
    }
  else
    {
      return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                              _("Invalid prop-mod flag in rev-file"));
    }
  str = svn_cstring_tokenize(" ", &last_str);
  if (str == NULL)
    return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                            _("Invalid changes line in rev-file"));
  if (strcmp(str, FLAG_TRUE) == 0)
    {
      change->mergeinfo_mod = svn_tristate_true;
    }
  else if (strcmp(str, FLAG_FALSE) == 0)
    {
      change->mergeinfo_mod = svn_tristate_false;
    }
  else
    {
      return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                              _("Invalid mergeinfo-mod flag in rev-file"));
    }
  if (!svn_fspath__is_canonical(last_str))
    return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                            _("Invalid path in changes line"));
  change->path.data = auto_unescape_path(apr_pstrmemdup(result_pool,
                                                        last_str,
                                                        strlen(last_str)),
                                         result_pool);
  change->path.len = strlen(change->path.data);
  SVN_ERR(svn_stream_readline(stream, &line, "\n", &eof, result_pool));
  change->copyfrom_known = TRUE;
  if (eof || line->len == 0)
    {
      change->copyfrom_rev = SVN_INVALID_REVNUM;
      change->copyfrom_path = NULL;
    }
  else
    {
      last_str = line->data;
      SVN_ERR(parse_revnum(&change->copyfrom_rev, (const char **)&last_str));
      if (!svn_fspath__is_canonical(last_str))
        return svn_error_create(SVN_ERR_FS_CORRUPT, NULL,
                                _("Invalid copy-from path in changes line"));
      change->copyfrom_path = auto_unescape_path(last_str, result_pool);
    }
  *change_p = change;
  return SVN_NO_ERROR;
}
static svn_error_t * read_change ( svn_fs_x__change_t * * change_p , svn_stream_t * stream , apr_pool_t * result_pool , apr_pool_t * scratch_pool ) { svn_stringbuf_t * line ; svn_boolean_t eof = TRUE ; svn_fs_x__change_t * change ; char * str , * last_str , * kind_str ; * change_p = NULL ; SVN_ERR ( svn_stream_readline ( stream , & line , " \n " , & eof , scratch_pool ) ) ; if ( eof || ( line -> len == 0 ) ) return SVN_NO_ERROR ; change = apr_pcalloc ( result_pool , sizeof ( * change ) ) ; last_str = line -> data ; str = svn_cstring_tokenize ( " " , & last_str ) ; if ( str == NULL ) return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; SVN_ERR ( svn_fs_x__id_parse ( & change -> noderev_id , str ) ) ; str = svn_cstring_tokenize ( " " , & last_str ) ; if ( str == NULL ) return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; change -> node_kind = svn_node_unknown ; kind_str = strchr ( str , ' ' ) ; if ( kind_str ) { * kind_str = ' \0 ' ; kind_str ++ ; if ( strcmp ( kind_str , SVN_FS_X__KIND_FILE ) == 0 ) change -> node_kind = svn_node_file ; else if ( strcmp ( kind_str , SVN_FS_X__KIND_DIR ) == 0 ) change -> node_kind = svn_node_dir ; else return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; } if ( strcmp ( str , ACTION_MODIFY ) == 0 ) { change -> change_kind = svn_fs_path_change_modify ; } else if ( strcmp ( str , ACTION_ADD ) == 0 ) { change -> change_kind = svn_fs_path_change_add ; } else if ( strcmp ( str , ACTION_DELETE ) == 0 ) { change -> change_kind = svn_fs_path_change_delete ; } else if ( strcmp ( str , ACTION_REPLACE ) == 0 ) { change -> change_kind = svn_fs_path_change_replace ; } else if ( strcmp ( str , ACTION_RESET ) == 0 ) { change -> change_kind = svn_fs_path_change_reset ; } else { return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; } str = svn_cstring_tokenize ( " " , & last_str ) ; if ( str == NULL ) return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; if ( strcmp ( str , FLAG_TRUE ) == 0 ) { change -> text_mod = TRUE ; } else if ( strcmp ( str , FLAG_FALSE ) == 0 ) { change -> text_mod = FALSE ; } else { return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; } str = svn_cstring_tokenize ( " " , & last_str ) ; if ( str == NULL ) return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; if ( strcmp ( str , FLAG_TRUE ) == 0 ) { change -> prop_mod = TRUE ; } else if ( strcmp ( str , FLAG_FALSE ) == 0 ) { change -> prop_mod = FALSE ; } else { return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; } str = svn_cstring_tokenize ( " " , & last_str ) ; if ( str == NULL ) return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; if ( strcmp ( str , FLAG_TRUE ) == 0 ) { change -> mergeinfo_mod = svn_tristate_true ; } else if ( strcmp ( str , FLAG_FALSE ) == 0 ) { change -> mergeinfo_mod = svn_tristate_false ; } else { return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; } if ( ! svn_fspath__is_canonical ( last_str ) ) return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; change -> path . data = auto_unescape_path ( apr_pstrmemdup ( result_pool , last_str , strlen ( last_str ) ) , result_pool ) ; change -> path . len = strlen ( change -> path . data ) ; SVN_ERR ( svn_stream_readline ( stream , & line , " \n " , & eof , result_pool ) ) ; change -> copyfrom_known = TRUE ; if ( eof || line -> len == 0 ) { change -> copyfrom_rev = SVN_INVALID_REVNUM ; change -> copyfrom_path = NULL ; } else { last_str = line -> data ; SVN_ERR ( parse_revnum ( & change -> copyfrom_rev , ( const char * * ) & last_str ) ) ; if ( ! svn_fspath__is_canonical ( last_str ) ) return svn_error_create ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " ) ) ; change -> copyfrom_path = auto_unescape_path ( last_str , result_pool ) ; } * change_p = change ; return SVN_NO_ERROR ; }
Read the next entry in the changes record from file FILE and store
the resulting change in *CHANGE_P.
Read the next entry in the changes record from file FILE and store the resulting change in * CHANGE_P .
/* Default return value. */ /* Check for a blank line. */ /* Get the node-id of the change. */ /* Get the change type. */ /* Don't bother to check the format number before looking for
   * node-kinds: just read them if you find them. */ /* Cap off the end of "str" (the action). */ /* Get the text-mod flag. */ /* Get the prop-mod flag. */ /* Get the mergeinfo-mod flag. */ /* Get the changed path. */ /* Read the next line, the copyfrom line. */