import-cmd.c revision 256281
1337414Skevans/* 2337414Skevans * import-cmd.c -- Import a file or tree into the repository. 3336668Skevans * 4336668Skevans * ==================================================================== 5337414Skevans * Licensed to the Apache Software Foundation (ASF) under one 6346429Skevans * or more contributor license agreements. See the NOTICE file 7336668Skevans * distributed with this work for additional information 8336668Skevans * regarding copyright ownership. The ASF licenses this file 9336668Skevans * to you under the Apache License, Version 2.0 (the 10336668Skevans * "License"); you may not use this file except in compliance 11336668Skevans * with the License. You may obtain a copy of the License at 12336668Skevans * 13336668Skevans * http://www.apache.org/licenses/LICENSE-2.0 14336668Skevans * 15336668Skevans * Unless required by applicable law or agreed to in writing, 16336668Skevans * software distributed under the License is distributed on an 17336668Skevans * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18336668Skevans * KIND, either express or implied. See the License for the 19336668Skevans * specific language governing permissions and limitations 20336668Skevans * under the License. 21336668Skevans * ==================================================================== 22336668Skevans */ 23336668Skevans 24336668Skevans/* ==================================================================== */ 25336668Skevans 26336668Skevans 27336668Skevans 28336668Skevans/*** Includes. ***/ 29336668Skevans 30337416Skevans#include "svn_client.h" 31337416Skevans#include "svn_path.h" 32337416Skevans#include "svn_error.h" 33355662Skevans#include "cl.h" 34355662Skevans 35336668Skevans#include "svn_private_config.h" 36336668Skevans 37336668Skevans 38336729Skevans/*** Code. ***/ 39336729Skevans 40336729Skevans/* This implements the `svn_opt_subcommand_t' interface. */ 41336729Skevanssvn_error_t * 42336729Skevanssvn_cl__import(apr_getopt_t *os, 43346429Skevans void *baton, 44346429Skevans apr_pool_t *pool) 45346429Skevans{ 46346429Skevans svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state; 47346429Skevans svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx; 48346429Skevans apr_array_header_t *targets; 49347170Skevans const char *path; 50346429Skevans const char *url; 51346429Skevans 52336729Skevans /* Import takes two arguments, for example 53336729Skevans * 54336729Skevans * $ svn import projects/test file:///home/jrandom/repos/trunk 55336729Skevans * ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 56336729Skevans * (source) (repository) 57336729Skevans * 58336729Skevans * or 59336729Skevans * 60336729Skevans * $ svn import file:///home/jrandom/repos/some/subdir 61336729Skevans * 62336729Skevans * What is the nicest behavior for import, from the user's point of 63336729Skevans * view? This is a subtle question. Seemingly intuitive answers 64336729Skevans * can lead to weird situations, such never being able to create 65346429Skevans * non-directories in the top-level of the repository. 66336729Skevans * 67336729Skevans * If 'source' is a file then the basename of 'url' is used as the 68346429Skevans * filename in the repository. If 'source' is a directory then the 69336729Skevans * import happens directly in the repository target dir, creating 70336729Skevans * however many new entries are necessary. If some part of 'url' 71336729Skevans * does not exist in the repository then parent directories are created 72336668Skevans * as necessary. 73346429Skevans * 74346429Skevans * In the case where no 'source' is given '.' (the current directory) 75346429Skevans * is implied. 76346429Skevans * 77346429Skevans * ### kff todo: review above behaviors. 78346429Skevans */ 79346429Skevans 80346429Skevans SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os, 81346429Skevans opt_state->targets, 82346429Skevans ctx, FALSE, pool)); 83346429Skevans 84346429Skevans if (targets->nelts < 1) 85346429Skevans return svn_error_create 86346429Skevans (SVN_ERR_CL_INSUFFICIENT_ARGS, NULL, 87346429Skevans _("Repository URL required when importing")); 88346429Skevans else if (targets->nelts > 2) 89346429Skevans return svn_error_create 90346429Skevans (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, 91346429Skevans _("Too many arguments to import command")); 92350344Skevans else if (targets->nelts == 1) 93350344Skevans { 94350344Skevans url = APR_ARRAY_IDX(targets, 0, const char *); 95350344Skevans path = ""; 96350344Skevans } 97350344Skevans else 98350344Skevans { 99350344Skevans path = APR_ARRAY_IDX(targets, 0, const char *); 100350344Skevans url = APR_ARRAY_IDX(targets, 1, const char *); 101350344Skevans } 102350344Skevans 103346429Skevans SVN_ERR(svn_cl__check_target_is_local_path(path)); 104350344Skevans 105350344Skevans if (! svn_path_is_url(url)) 106350344Skevans return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL, 107346429Skevans _("Invalid URL '%s'"), url); 108347170Skevans 109350344Skevans if (opt_state->depth == svn_depth_unknown) 110350344Skevans opt_state->depth = svn_depth_infinity; 111350344Skevans 112350344Skevans SVN_ERR(svn_cl__make_log_msg_baton(&(ctx->log_msg_baton3), opt_state, 113347170Skevans NULL, ctx->config, pool)); 114350344Skevans 115348133Skevans SVN_ERR(svn_cl__cleanup_log_msg 116346429Skevans (ctx->log_msg_baton3, 117346429Skevans svn_client_import5(path, 118346429Skevans url, 119346429Skevans opt_state->depth, 120347170Skevans opt_state->no_ignore, 121346429Skevans opt_state->no_autoprops, 122357001Skevans opt_state->force, 123347170Skevans opt_state->revprop_table, 124347170Skevans NULL, NULL, /* filter callback / baton */ 125347170Skevans (opt_state->quiet 126347170Skevans ? NULL : svn_cl__print_commit_info), 127347170Skevans NULL, 128347170Skevans ctx, 129347170Skevans pool), pool)); 130347170Skevans 131347170Skevans return SVN_NO_ERROR; 132347170Skevans} 133347170Skevans