Exemple #1
0
  void
  Client::get(Path & dstPath,
              const Path & path,
              const Revision & revision,
              const Revision & peg_revision) throw(ClientException)
  {
    Pool pool;

    // create a new file and suppose we only want
    // this users to be able to read and write the file

    apr_file_t * file = openTempFile(dstPath, path, revision, pool);

    // now create a stream and let svn_client_cat write to the
    // stream
    svn_stream_t * stream = svn_stream_from_aprfile(file, pool);
    if (stream != 0)
    {
      svn_error_t * error = svn_client_cat2(
                              stream,
                              path.c_str(),
                              peg_revision.revision() ,
                              revision.revision(),
                              *m_context,
                              pool);

      if (error != 0)
        throw ClientException(error);

      svn_stream_close(stream);
    }

    // finalize stuff
    apr_file_close(file);
  }
/* This implements the `svn_opt_subcommand_t' interface. */
svn_error_t *
svn_cl__cat(apr_getopt_t *os,
            void *baton,
            apr_pool_t *pool)
{
  svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
  svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
  apr_array_header_t *targets;
  int i;
  svn_stream_t *out;
  apr_pool_t *subpool = svn_pool_create(pool);
  svn_boolean_t seen_nonexistent_target = FALSE;

  SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
                                                      opt_state->targets,
                                                      ctx, FALSE, pool));

  /* Cat cannot operate on an implicit '.' so a filename is required */
  if (! targets->nelts)
    return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);

  SVN_ERR(svn_stream_for_stdout(&out, pool));

  for (i = 0; i < targets->nelts; i++)
    {
      const char *target = APR_ARRAY_IDX(targets, i, const char *);
      const char *truepath;
      svn_opt_revision_t peg_revision;
      svn_boolean_t success;

      svn_pool_clear(subpool);
      SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));

      /* Get peg revisions. */
      SVN_ERR(svn_opt_parse_path(&peg_revision, &truepath, target,
                                 subpool));

      SVN_ERR(svn_cl__try(svn_client_cat2(out, truepath, &peg_revision,
                                          &(opt_state->start_revision),
                                          ctx, subpool),
                           &success, opt_state->quiet,
                           SVN_ERR_UNVERSIONED_RESOURCE,
                           SVN_ERR_ENTRY_NOT_FOUND,
                           SVN_ERR_CLIENT_IS_DIRECTORY,
                           SVN_ERR_FS_NOT_FOUND,
                           SVN_NO_ERROR));
      if (! success)
        seen_nonexistent_target = TRUE;
    }
  svn_pool_destroy(subpool);

  if (seen_nonexistent_target)
    return svn_error_create(
      SVN_ERR_ILLEGAL_TARGET, NULL,
      _("Could not cat all targets because some targets don't exist"));
  else
    return SVN_NO_ERROR;
}
Exemple #3
0
/* This implements the `svn_opt_subcommand_t' interface. */
svn_error_t *
svn_cl__cat(apr_getopt_t *os,
            void *baton,
            apr_pool_t *pool)
{
  svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
  svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
  apr_array_header_t *targets;
  int i;
  svn_stream_t *out;
  apr_pool_t *subpool = svn_pool_create(pool);

  SVN_ERR(svn_opt_args_to_target_array2(&targets, os,
                                        opt_state->targets, pool));

  /* Cat cannot operate on an implicit '.' so a filename is required */
  if (! targets->nelts)
    return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);

  SVN_ERR(svn_stream_for_stdout(&out, pool));

  for (i = 0; i < targets->nelts; i++)
    {
      const char *target = ((const char **) (targets->elts))[i];
      const char *truepath;
      svn_opt_revision_t peg_revision;

      svn_pool_clear(subpool);
      SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));

      /* Get peg revisions. */
      SVN_ERR(svn_opt_parse_path(&peg_revision, &truepath, target,
                                 subpool));
      
      SVN_ERR(svn_cl__try( svn_client_cat2(out, truepath, &peg_revision,
                                           &(opt_state->start_revision),
                                           ctx, subpool),
                           NULL, opt_state->quiet,
                           SVN_ERR_UNVERSIONED_RESOURCE,
                           SVN_ERR_ENTRY_NOT_FOUND,
                           SVN_ERR_CLIENT_IS_DIRECTORY,
                           SVN_NO_ERROR));
    }
  svn_pool_destroy(subpool);

  return SVN_NO_ERROR;
}
Exemple #4
0
static int
l_cat (lua_State *L) {
	const char *path = luaL_checkstring (L, 1);

	svn_opt_revision_t peg_revision;
	svn_opt_revision_t revision;

	peg_revision.kind = svn_opt_revision_unspecified;

	if (lua_gettop (L) < 2 || lua_isnil (L, 2)) {
		revision.kind = get_revision_kind (path);
	} else {
		revision.kind = svn_opt_revision_number;
		revision.value.number = lua_tointeger (L, 2);
	}

	apr_pool_t *pool;
	svn_error_t *err;
	svn_client_ctx_t *ctx;

	init_function (&ctx, &pool, L);

	path = svn_path_canonicalize (path, pool);

	svn_stream_t *stream;

	stream = svn_stream_empty (pool);
	svn_stream_set_write (stream, write_fn);

	svn_stringbuf_t *buffer = svn_stringbuf_create ("\0", pool);

	svn_stream_set_baton (stream, buffer);

	err = svn_client_cat2 (stream, path, &peg_revision, &revision, ctx, pool);
	IF_ERROR_RETURN (err, pool, L);

	lua_pushstring (L, buffer->data);

	svn_pool_destroy (pool);

	return 1;
}
Exemple #5
0
/* fonction simulant la commande svn cat */  
apr_array_header_t *svn_support_cat_call(char *file_path, 
                                         int revision, 
                                         apr_pool_t *subpool){
  svn_error_t *err;
  svn_opt_revision_t rev;
  svn_stream_t *out;
  
  // -- Initialisation de la révision --
  if (revision != -1) {
    rev.kind = svn_opt_revision_number;
    rev.value.number = revision;
  }
  else 
    rev.kind = svn_opt_revision_unspecified;
 
  // -- Initialisation du tableau et du buffer de résultats -- 
  apr_array_header_t *list_result = apr_array_make(subpool, 1, sizeof (const char *));
  svn_stringbuf_t *res = svn_stringbuf_create("",subpool);	
  
  // -- Initialisation du flux de sortie --
  out = svn_stream_from_stringbuf(res,subpool);
  
  err = svn_client_cat2(out, 
                        file_path,
                        &rev,
                        &rev,
                        ctx,
                        subpool);
  if (err) {
    svn_handle_error2 (err, stderr, FALSE, "svn_support_cat: ");
    svn_pool_destroy(subpool);
    return NULL;
  }

  svn_cstring_split_endline_append(list_result,res->data,subpool);
  svn_pool_destroy(subpool);
  return list_result;
}
Exemple #6
0
  std::string
  Client::cat(const Path & path,
              const Revision & revision,
              const Revision & peg_revision) throw(ClientException)
  {
    Pool pool;

    svn_stringbuf_t * stringbuf = svn_stringbuf_create("", pool);
    svn_stream_t * stream = svn_stream_from_stringbuf(stringbuf, pool);

    svn_error_t * error;
    error = svn_client_cat2(stream,
                            path.c_str(),
                            peg_revision.revision(),
                            revision.revision(),
                            *m_context,
                            pool);

    if (error != 0)
      throw ClientException(error);

    return std::string(stringbuf->data, stringbuf->len);
  }
Exemple #7
0
static guint
svn_cat_command_run (AnjutaCommand *command)
{
	SvnCatCommand *self;
	SvnCommand *svn_command;
	svn_opt_revision_t revision;
	svn_opt_revision_t peg_revision;
	svn_stream_t *cat_stream;
	apr_file_t *cat_input;
	apr_file_t *cat_output;
	apr_size_t read_size;
	gchar *line;
	svn_error_t *error;
	apr_status_t apr_error;
	
	self = SVN_CAT_COMMAND (command);
	svn_command = SVN_COMMAND (command);
	
	apr_file_pipe_create (&cat_output, &cat_input, 
						  svn_command_get_pool (svn_command));
	apr_file_pipe_timeout_set (cat_output, 0);
	apr_file_pipe_timeout_set (cat_input, 0);
	cat_stream = svn_stream_from_aprfile2 (cat_input, FALSE, 
										   svn_command_get_pool (svn_command));
	
	revision.kind = svn_opt_revision_number;
	revision.value.number = self->priv->revision;
	peg_revision.kind = svn_opt_revision_unspecified;
	
	error = svn_client_cat2 (cat_stream,
							 self->priv->path,
							 &peg_revision,
							 &revision,
							 svn_command_get_client_context (svn_command),
							 svn_command_get_pool (svn_command));
	
	if (error)
	{
		svn_command_set_error (svn_command, error);
		return 1;
	}
	
	while (apr_file_eof (cat_output) != APR_EOF)
	{
		read_size = 80;
		line = g_new0 (gchar, (read_size + 1));
		
		apr_error = apr_file_read (cat_output, line, &read_size);
		
		if (apr_error)
			break;
		
		if (strlen (line))
		{
			anjuta_async_command_lock (ANJUTA_ASYNC_COMMAND (command));
			g_queue_push_tail (self->priv->output, g_strdup (line));
			anjuta_async_command_unlock (ANJUTA_ASYNC_COMMAND (command));
			
			g_free (line);
			
			anjuta_command_notify_data_arrived (command);
		}
	}
								 
	return 0;
}