2
2
* editorp.c : Driving and consuming an editor across an svn connection
4
4
* ====================================================================
5
* Copyright (c) 2000-2006, 2008 CollabNet. All rights reserved.
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.
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/.
5
* Licensed to the Apache Software Foundation (ASF) under one
6
* or more contributor license agreements. See the NOTICE file
7
* distributed with this work for additional information
8
* regarding copyright ownership. The ASF licenses this file
9
* to you under the Apache License, Version 2.0 (the
10
* "License"); you may not use this file except in compliance
11
* with the License. You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing,
16
* software distributed under the License is distributed on an
17
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18
* KIND, either express or implied. See the License for the
19
* specific language governing permissions and limitations
16
21
* ====================================================================
80
88
field in this structure is vestigial for files, and we use it for a
81
89
different purpose instead: at apply-textdelta time, we set it to a
82
90
subpool of the file pool, which is destroyed in textdelta-end. */
91
typedef struct ra_svn_token_entry_t {
86
94
svn_boolean_t is_file;
308
316
diff_stream = svn_stream_create(b, pool);
309
317
svn_stream_set_write(diff_stream, ra_svn_svndiff_handler);
310
318
svn_stream_set_close(diff_stream, ra_svn_svndiff_close_handler);
311
if (svn_ra_svn_has_capability(b->conn, SVN_RA_SVN_CAP_SVNDIFF1))
312
svn_txdelta_to_svndiff2(wh, wh_baton, diff_stream, 1, pool);
320
/* If the connection does not support SVNDIFF1 or if we don't want to use
321
* compression, use the non-compressing "version 0" implementation */
322
if ( svn_ra_svn_compression_level(b->conn) > 0
323
&& svn_ra_svn_has_capability(b->conn, SVN_RA_SVN_CAP_SVNDIFF1))
324
svn_txdelta_to_svndiff3(wh, wh_baton, diff_stream, 1,
325
b->conn->compression_level, pool);
314
svn_txdelta_to_svndiff2(wh, wh_baton, diff_stream, 0, pool);
327
svn_txdelta_to_svndiff3(wh, wh_baton, diff_stream, 0,
328
b->conn->compression_level, pool);
315
329
return SVN_NO_ERROR;
457
471
static svn_error_t *ra_svn_handle_target_rev(svn_ra_svn_conn_t *conn,
458
472
apr_pool_t *pool,
459
apr_array_header_t *params,
473
const apr_array_header_t *params,
460
474
ra_svn_driver_state_t *ds)
462
476
svn_revnum_t rev;
469
483
static svn_error_t *ra_svn_handle_open_root(svn_ra_svn_conn_t *conn,
470
484
apr_pool_t *pool,
471
apr_array_header_t *params,
485
const apr_array_header_t *params,
472
486
ra_svn_driver_state_t *ds)
474
488
svn_revnum_t rev;
487
501
static svn_error_t *ra_svn_handle_delete_entry(svn_ra_svn_conn_t *conn,
488
502
apr_pool_t *pool,
489
apr_array_header_t *params,
503
const apr_array_header_t *params,
490
504
ra_svn_driver_state_t *ds)
492
506
const char *path, *token;
496
510
SVN_ERR(svn_ra_svn_parse_tuple(params, pool, "c(?r)c", &path, &rev, &token));
497
511
SVN_ERR(lookup_token(ds, token, FALSE, &entry));
498
path = svn_path_canonicalize(path, pool);
512
path = svn_relpath_canonicalize(path, pool);
499
513
SVN_CMD_ERR(ds->editor->delete_entry(path, rev, entry->baton, pool));
500
514
return SVN_NO_ERROR;
503
517
static svn_error_t *ra_svn_handle_add_dir(svn_ra_svn_conn_t *conn,
504
518
apr_pool_t *pool,
505
apr_array_header_t *params,
519
const apr_array_header_t *params,
506
520
ra_svn_driver_state_t *ds)
508
522
const char *path, *token, *child_token, *copy_path;
515
529
&child_token, ©_path, ©_rev));
516
530
SVN_ERR(lookup_token(ds, token, FALSE, &entry));
517
531
subpool = svn_pool_create(entry->pool);
518
path = svn_path_canonicalize(path, pool);
532
path = svn_relpath_canonicalize(path, pool);
534
/* Some operations pass COPY_PATH as a full URL (commits, etc.).
535
Others (replay, e.g.) deliver an fspath. That's ... annoying. */
520
copy_path = svn_path_canonicalize(copy_path, pool);
538
if (svn_path_is_url(copy_path))
539
copy_path = svn_uri_canonicalize(copy_path, pool);
541
copy_path = svn_fspath__canonicalize(copy_path, pool);
521
544
SVN_CMD_ERR(ds->editor->add_directory(path, entry->baton, copy_path,
522
545
copy_rev, subpool, &child_baton));
523
546
store_token(ds, child_baton, child_token, FALSE, subpool);
527
550
static svn_error_t *ra_svn_handle_open_dir(svn_ra_svn_conn_t *conn,
528
551
apr_pool_t *pool,
529
apr_array_header_t *params,
552
const apr_array_header_t *params,
530
553
ra_svn_driver_state_t *ds)
532
555
const char *path, *token, *child_token;
539
562
&child_token, &rev));
540
563
SVN_ERR(lookup_token(ds, token, FALSE, &entry));
541
564
subpool = svn_pool_create(entry->pool);
542
path = svn_path_canonicalize(path, pool);
565
path = svn_relpath_canonicalize(path, pool);
543
566
SVN_CMD_ERR(ds->editor->open_directory(path, entry->baton, rev, subpool,
545
568
store_token(ds, child_baton, child_token, FALSE, subpool);
549
572
static svn_error_t *ra_svn_handle_change_dir_prop(svn_ra_svn_conn_t *conn,
550
573
apr_pool_t *pool,
551
apr_array_header_t *params,
574
const apr_array_header_t *params,
552
575
ra_svn_driver_state_t *ds)
554
577
const char *token, *name;
566
589
static svn_error_t *ra_svn_handle_close_dir(svn_ra_svn_conn_t *conn,
567
590
apr_pool_t *pool,
568
apr_array_header_t *params,
591
const apr_array_header_t *params,
569
592
ra_svn_driver_state_t *ds)
571
594
const char *token;
585
608
static svn_error_t *ra_svn_handle_absent_dir(svn_ra_svn_conn_t *conn,
586
609
apr_pool_t *pool,
587
apr_array_header_t *params,
610
const apr_array_header_t *params,
588
611
ra_svn_driver_state_t *ds)
590
613
const char *path;
603
626
static svn_error_t *ra_svn_handle_add_file(svn_ra_svn_conn_t *conn,
604
627
apr_pool_t *pool,
605
apr_array_header_t *params,
628
const apr_array_header_t *params,
606
629
ra_svn_driver_state_t *ds)
608
631
const char *path, *token, *file_token, *copy_path;
613
636
&file_token, ©_path, ©_rev));
614
637
SVN_ERR(lookup_token(ds, token, FALSE, &entry));
616
path = svn_path_canonicalize(path, pool);
639
path = svn_relpath_canonicalize(path, pool);
641
/* Some operations pass COPY_PATH as a full URL (commits, etc.).
642
Others (replay, e.g.) deliver an fspath. That's ... annoying. */
618
copy_path = svn_path_canonicalize(copy_path, pool);
645
if (svn_path_is_url(copy_path))
646
copy_path = svn_uri_canonicalize(copy_path, pool);
648
copy_path = svn_fspath__canonicalize(copy_path, pool);
619
651
file_entry = store_token(ds, NULL, file_token, TRUE, ds->file_pool);
620
652
SVN_CMD_ERR(ds->editor->add_file(path, entry->baton, copy_path, copy_rev,
621
653
ds->file_pool, &file_entry->baton));
625
657
static svn_error_t *ra_svn_handle_open_file(svn_ra_svn_conn_t *conn,
626
658
apr_pool_t *pool,
627
apr_array_header_t *params,
659
const apr_array_header_t *params,
628
660
ra_svn_driver_state_t *ds)
630
662
const char *path, *token, *file_token;
635
667
&file_token, &rev));
636
668
SVN_ERR(lookup_token(ds, token, FALSE, &entry));
638
path = svn_path_canonicalize(path, pool);
670
path = svn_relpath_canonicalize(path, pool);
639
671
file_entry = store_token(ds, NULL, file_token, TRUE, ds->file_pool);
640
672
SVN_CMD_ERR(ds->editor->open_file(path, entry->baton, rev, ds->file_pool,
641
673
&file_entry->baton));
645
677
static svn_error_t *ra_svn_handle_apply_textdelta(svn_ra_svn_conn_t *conn,
646
678
apr_pool_t *pool,
647
apr_array_header_t *params,
679
const apr_array_header_t *params,
648
680
ra_svn_driver_state_t *ds)
650
682
const char *token;
670
702
static svn_error_t *ra_svn_handle_textdelta_chunk(svn_ra_svn_conn_t *conn,
671
703
apr_pool_t *pool,
672
apr_array_header_t *params,
704
const apr_array_header_t *params,
673
705
ra_svn_driver_state_t *ds)
675
707
const char *token;
689
721
static svn_error_t *ra_svn_handle_textdelta_end(svn_ra_svn_conn_t *conn,
690
722
apr_pool_t *pool,
691
apr_array_header_t *params,
723
const apr_array_header_t *params,
692
724
ra_svn_driver_state_t *ds)
694
726
const char *token;
709
741
static svn_error_t *ra_svn_handle_change_file_prop(svn_ra_svn_conn_t *conn,
710
742
apr_pool_t *pool,
711
apr_array_header_t *params,
743
const apr_array_header_t *params,
712
744
ra_svn_driver_state_t *ds)
714
746
const char *token, *name;
725
757
static svn_error_t *ra_svn_handle_close_file(svn_ra_svn_conn_t *conn,
726
758
apr_pool_t *pool,
727
apr_array_header_t *params,
759
const apr_array_header_t *params,
728
760
ra_svn_driver_state_t *ds)
730
762
const char *token;
747
779
static svn_error_t *ra_svn_handle_absent_file(svn_ra_svn_conn_t *conn,
748
780
apr_pool_t *pool,
749
apr_array_header_t *params,
781
const apr_array_header_t *params,
750
782
ra_svn_driver_state_t *ds)
752
784
const char *path;
765
797
static svn_error_t *ra_svn_handle_close_edit(svn_ra_svn_conn_t *conn,
766
798
apr_pool_t *pool,
767
apr_array_header_t *params,
799
const apr_array_header_t *params,
768
800
ra_svn_driver_state_t *ds)
770
802
SVN_CMD_ERR(ds->editor->close_edit(ds->edit_baton, pool));
777
809
static svn_error_t *ra_svn_handle_abort_edit(svn_ra_svn_conn_t *conn,
778
810
apr_pool_t *pool,
779
apr_array_header_t *params,
811
const apr_array_header_t *params,
780
812
ra_svn_driver_state_t *ds)
789
821
static svn_error_t *ra_svn_handle_finish_replay(svn_ra_svn_conn_t *conn,
790
822
apr_pool_t *pool,
791
apr_array_header_t *params,
823
const apr_array_header_t *params,
792
824
ra_svn_driver_state_t *ds)
794
826
if (!ds->for_replay)
804
836
static const struct {
806
838
svn_error_t *(*handler)(svn_ra_svn_conn_t *conn, apr_pool_t *pool,
807
apr_array_header_t *params,
839
const apr_array_header_t *params,
808
840
ra_svn_driver_state_t *ds);
809
841
} ra_svn_edit_cmds[] = {
810
842
{ "target-rev", ra_svn_handle_target_rev },
883
915
if (ra_svn_edit_cmds[i].cmd)
884
916
err = (*ra_svn_edit_cmds[i].handler)(conn, subpool, params, &state);
917
else if (strcmp(cmd, "failure") == 0)
919
/* While not really an editor command this can occur when
920
reporter->finish_report() fails before the first editor command */
923
err = svn_ra_svn__handle_failure_status(params, pool);
924
return svn_error_compose_create(
926
editor->abort_edit(edit_baton, subpool));
887
930
err = svn_error_createf(SVN_ERR_RA_SVN_UNKNOWN_CMD, NULL,