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-switch-command.h"
27 struct _SvnSwitchCommandPriv
29 gchar
*working_copy_path
;
35 G_DEFINE_TYPE (SvnSwitchCommand
, svn_switch_command
, SVN_TYPE_COMMAND
);
38 svn_switch_command_init (SvnSwitchCommand
*self
)
40 self
->priv
= g_new0 (SvnSwitchCommandPriv
, 1);
44 svn_switch_command_finalize (GObject
*object
)
46 SvnSwitchCommand
*self
;
48 self
= SVN_SWITCH_COMMAND (object
);
50 g_free (self
->priv
->working_copy_path
);
51 g_free (self
->priv
->branch_url
);
54 G_OBJECT_CLASS (svn_switch_command_parent_class
)->finalize (object
);
58 svn_switch_command_run (AnjutaCommand
*command
)
60 SvnSwitchCommand
*self
;
61 SvnCommand
*svn_command
;
62 svn_opt_revision_t revision
;
63 svn_revnum_t switched_revision
;
64 gchar
*revision_message
;
67 self
= SVN_SWITCH_COMMAND (command
);
68 svn_command
= SVN_COMMAND (command
);
70 if (self
->priv
->revision
== SVN_SWITCH_REVISION_HEAD
)
71 revision
.kind
= svn_opt_revision_head
;
74 revision
.kind
= svn_opt_revision_number
;
75 revision
.value
.number
= self
->priv
->revision
;
78 error
= svn_client_switch (&switched_revision
,
79 self
->priv
->working_copy_path
,
80 self
->priv
->branch_url
,
82 self
->priv
->recursive
,
83 svn_command_get_client_context (svn_command
),
84 svn_command_get_pool (svn_command
));
88 svn_command_set_error (svn_command
, error
);
92 revision_message
= g_strdup_printf ("Switched to revision %ld.",
95 svn_command_push_info (svn_command
, revision_message
);
96 g_free (revision_message
);
102 svn_switch_command_class_init (SvnSwitchCommandClass
*klass
)
104 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
105 AnjutaCommandClass
* command_class
= ANJUTA_COMMAND_CLASS (klass
);
107 object_class
->finalize
= svn_switch_command_finalize
;
108 command_class
->run
= svn_switch_command_run
;
112 svn_switch_command_new (gchar
*working_copy_path
, gchar
*branch_url
,
113 glong revision
, gboolean recursive
)
115 SvnSwitchCommand
*self
;
117 self
= g_object_new (SVN_TYPE_SWITCH_COMMAND
, NULL
);
118 self
->priv
->working_copy_path
= svn_command_make_canonical_path (SVN_COMMAND (self
),
120 self
->priv
->branch_url
= g_strdup (branch_url
);
121 self
->priv
->revision
= revision
;
122 self
->priv
->recursive
= recursive
;
128 svn_switch_command_destroy (SvnSwitchCommand
*self
)
130 g_object_unref (self
);