1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2007 <jrliggett@cox.net>
6 * anjuta is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include "svn-copy-command.h"
27 struct _SvnCopyCommandPriv
30 glong source_revision
;
35 G_DEFINE_TYPE (SvnCopyCommand
, svn_copy_command
, SVN_TYPE_COMMAND
);
38 on_log_callback (const char **log_msg
,
39 const char **tmp_file
,
40 apr_array_header_t
*commit_items
,
47 self
= SVN_COPY_COMMAND (baton
);
49 *log_msg
= self
->priv
->log_message
;
56 svn_copy_command_init (SvnCopyCommand
*self
)
58 svn_client_ctx_t
*client_context
;
60 self
->priv
= g_new0 (SvnCopyCommandPriv
, 1);
61 client_context
= svn_command_get_client_context (SVN_COMMAND (self
));
63 client_context
->log_msg_func
= on_log_callback
;
64 client_context
->log_msg_baton
= self
;
68 svn_copy_command_finalize (GObject
*object
)
72 self
= SVN_COPY_COMMAND (object
);
74 g_free (self
->priv
->source_path
);
75 g_free (self
->priv
->dest_path
);
76 g_free (self
->priv
->log_message
);
79 G_OBJECT_CLASS (svn_copy_command_parent_class
)->finalize (object
);
83 svn_copy_command_run (AnjutaCommand
*command
)
86 SvnCommand
*svn_command
;
87 svn_opt_revision_t revision
;
88 svn_commit_info_t
*commit_info
;
89 gchar
*revision_message
;
92 self
= SVN_COPY_COMMAND (command
);
93 svn_command
= SVN_COMMAND (command
);
95 switch (self
->priv
->source_revision
)
97 case SVN_COPY_REVISION_WORKING
:
98 revision
.kind
= svn_opt_revision_working
;
100 case SVN_COPY_REVISION_HEAD
:
101 revision
.kind
= svn_opt_revision_head
;
104 revision
.kind
= svn_opt_revision_number
;
105 revision
.value
.number
= self
->priv
->source_revision
;
109 error
= svn_client_copy3 (&commit_info
,
110 self
->priv
->source_path
,
112 self
->priv
->dest_path
,
113 svn_command_get_client_context (svn_command
),
114 svn_command_get_pool (svn_command
));
118 svn_command_set_error (svn_command
, error
);
123 svn_path_is_url (self
->priv
->dest_path
))
125 revision_message
= g_strdup_printf ("Committed revision %ld.",
126 commit_info
->revision
);
127 svn_command_push_info (SVN_COMMAND (command
), revision_message
);
128 g_free (revision_message
);
135 svn_copy_command_class_init (SvnCopyCommandClass
*klass
)
137 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
138 AnjutaCommandClass
* command_class
= ANJUTA_COMMAND_CLASS (klass
);
140 object_class
->finalize
= svn_copy_command_finalize
;
141 command_class
->run
= svn_copy_command_run
;
145 svn_copy_command_new (gchar
*source_path
, glong source_revision
,
146 gchar
*dest_path
, gchar
*log_message
)
148 SvnCopyCommand
*self
;
150 self
= g_object_new (SVN_TYPE_COPY_COMMAND
, NULL
);
152 self
->priv
->source_path
= svn_command_make_canonical_path (SVN_COMMAND (self
),
154 self
->priv
->source_revision
= source_revision
;
155 self
->priv
->dest_path
= svn_command_make_canonical_path (SVN_COMMAND (self
),
157 self
->priv
->log_message
= g_strdup (log_message
);
163 svn_copy_command_destroy (SvnCopyCommand
*self
)
165 g_object_unref (self
);