~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/clients/cmdline/import-cmd.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * import-cmd.c -- Import a file or tree into the repository.
 
3
 *
 
4
 * ====================================================================
 
5
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
6
 *
 
7
 * This software is licensed as described in the file COPYING, which
 
8
 * you should have received as part of this distribution.  The terms
 
9
 * are also available at http://subversion.tigris.org/license-1.html.
 
10
 * If newer versions of this license are posted there, you may use a
 
11
 * newer version instead, at your option.
 
12
 *
 
13
 * This software consists of voluntary contributions made by many
 
14
 * individuals.  For exact contribution history, see the revision
 
15
 * history and logs, available at http://subversion.tigris.org/.
 
16
 * ====================================================================
 
17
 */
 
18
 
 
19
/* ==================================================================== */
 
20
 
 
21
 
 
22
 
 
23
/*** Includes. ***/
 
24
 
 
25
#include "svn_client.h"
 
26
#include "svn_path.h"
 
27
#include "svn_error.h"
 
28
#include "cl.h"
 
29
 
 
30
#include "svn_private_config.h"
 
31
 
 
32
 
 
33
/*** Code. ***/
 
34
 
 
35
/* This implements the `svn_opt_subcommand_t' interface. */
 
36
svn_error_t *
 
37
svn_cl__import (apr_getopt_t *os,
 
38
                void *baton,
 
39
                apr_pool_t *pool)
 
40
{
 
41
  svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
 
42
  svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
 
43
  apr_array_header_t *targets;
 
44
  const char *path;
 
45
  const char *url;
 
46
  svn_client_commit_info_t *commit_info = NULL;
 
47
 
 
48
  /* Import takes two arguments, for example
 
49
   *
 
50
   *   $ svn import projects/test file:///home/jrandom/repos/trunk
 
51
   *                ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
52
   *                 (source)       (repository)
 
53
   *
 
54
   * or
 
55
   *
 
56
   *   $ svn import file:///home/jrandom/repos/some/subdir
 
57
   *
 
58
   * What is the nicest behavior for import, from the user's point of
 
59
   * view?  This is a subtle question.  Seemingly intuitive answers
 
60
   * can lead to weird situations, such never being able to create
 
61
   * non-directories in the top-level of the repository.
 
62
   *
 
63
   * If 'source' is a file then the basename of 'url' is used as the
 
64
   * filename in the repository.  If 'source' is a directory then the
 
65
   * import happens directly in the repository target dir, creating
 
66
   * however many new entries are necessary.  If some part of 'url'
 
67
   * does not exist in the repository then parent directories are created
 
68
   * as necessary.
 
69
   *
 
70
   * In the case where no 'source' is given '.' (the current directory)
 
71
   * is implied.
 
72
   *
 
73
   * ### kff todo: review above behaviors.
 
74
   */
 
75
 
 
76
  SVN_ERR (svn_opt_args_to_target_array2 (&targets, os, 
 
77
                                          opt_state->targets, pool));
 
78
 
 
79
  if (targets->nelts < 1)
 
80
    return svn_error_create
 
81
      (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
 
82
       _("Repository URL required when importing"));
 
83
  else if (targets->nelts > 2)
 
84
    return svn_error_create
 
85
      (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
 
86
       _("Too many arguments to import command"));
 
87
  else if (targets->nelts == 1)
 
88
    {
 
89
      url = ((const char **) (targets->elts))[0];
 
90
      path = "";
 
91
    }
 
92
  else
 
93
    {
 
94
      path = ((const char **) (targets->elts))[0];
 
95
      url = ((const char **) (targets->elts))[1];
 
96
    }
 
97
 
 
98
  if (! svn_path_is_url (url))
 
99
    return svn_error_createf
 
100
      (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
 
101
       _("Invalid URL '%s'"), url);
 
102
 
 
103
  if (! opt_state->quiet)
 
104
    svn_cl__get_notifier (&ctx->notify_func2, &ctx->notify_baton2,
 
105
                          FALSE, FALSE, FALSE, pool);
 
106
 
 
107
  SVN_ERR (svn_cl__make_log_msg_baton (&(ctx->log_msg_baton), opt_state, 
 
108
                                       NULL, ctx->config, pool));
 
109
  SVN_ERR (svn_cl__cleanup_log_msg 
 
110
           (ctx->log_msg_baton, svn_client_import (&commit_info,
 
111
                                                   path,
 
112
                                                   url,
 
113
                                                   opt_state->nonrecursive,
 
114
                                                   ctx,
 
115
                                                   pool)));
 
116
 
 
117
  if (commit_info && ! opt_state->quiet)
 
118
    SVN_ERR (svn_cl__print_commit_info (commit_info, pool));
 
119
 
 
120
  return SVN_NO_ERROR;
 
121
}