1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * anjuta
4  * Copyright (C) James Liggett 2007 <jrliggett@cox.net>
5  *
6  * anjuta is free software.
7  *
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)
11  * any later version.
12  *
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.
17  *
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.
23  */
24 
25 #include "svn-merge-command.h"
26 
27 struct _SvnMergeCommandPriv
28 {
29 	gchar *path1;
30 	gchar *path2;
31 	glong start_revision;
32 	glong end_revision;
33 	gchar *target_path;
34 	gboolean recursive;
35 	gboolean ignore_ancestry;
36 	gboolean force;
37 	gboolean dry_run;
38 };
39 
40 G_DEFINE_TYPE (SvnMergeCommand, svn_merge_command, SVN_TYPE_COMMAND);
41 
42 static void
svn_merge_command_init(SvnMergeCommand * self)43 svn_merge_command_init (SvnMergeCommand *self)
44 {
45 	self->priv = g_new0 (SvnMergeCommandPriv, 1);
46 }
47 
48 static void
svn_merge_command_finalize(GObject * object)49 svn_merge_command_finalize (GObject *object)
50 {
51 	SvnMergeCommand *self;
52 
53 	self = SVN_MERGE_COMMAND (object);
54 
55 	g_free (self->priv->path1);
56 	g_free (self->priv->path2);
57 	g_free (self->priv->target_path);
58 	g_free (self->priv);
59 
60 	G_OBJECT_CLASS (svn_merge_command_parent_class)->finalize (object);
61 }
62 
63 static guint
svn_merge_command_run(AnjutaCommand * command)64 svn_merge_command_run (AnjutaCommand *command)
65 {
66 	SvnMergeCommand *self;
67 	SvnCommand *svn_command;
68 	svn_opt_revision_t start_revision;
69 	svn_opt_revision_t end_revision;
70 	svn_error_t *error;
71 
72 	self = SVN_MERGE_COMMAND (command);
73 	svn_command = SVN_COMMAND (command);
74 
75 	if (self->priv->start_revision == SVN_MERGE_REVISION_HEAD)
76 		start_revision.kind = svn_opt_revision_head;
77 	else
78 	{
79 		start_revision.kind = svn_opt_revision_number;
80 		start_revision.value.number = self->priv->start_revision;
81 	}
82 
83 	if (self->priv->end_revision == SVN_MERGE_REVISION_HEAD)
84 		end_revision.kind = svn_opt_revision_head;
85 	else
86 	{
87 		end_revision.kind = svn_opt_revision_number;
88 		end_revision.value.number = self->priv->end_revision;
89 	}
90 
91 	error = svn_client_merge2 (self->priv->path1,
92 							   &start_revision,
93 							   self->priv->path2,
94 							   &end_revision,
95 							   self->priv->target_path,
96 							   self->priv->recursive,
97 							   self->priv->ignore_ancestry,
98 							   self->priv->force,
99 							   self->priv->dry_run,
100 							   NULL,
101 							   svn_command_get_client_context (svn_command),
102 							   svn_command_get_pool (svn_command));
103 
104 	if (error)
105 	{
106 		svn_command_set_error (svn_command, error);
107 		return 1;
108 	}
109 
110 	return 0;
111 }
112 
113 static void
svn_merge_command_class_init(SvnMergeCommandClass * klass)114 svn_merge_command_class_init (SvnMergeCommandClass *klass)
115 {
116 	GObjectClass* object_class = G_OBJECT_CLASS (klass);
117 	AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass);
118 
119 	object_class->finalize = svn_merge_command_finalize;
120 	command_class->run = svn_merge_command_run;
121 }
122 
123 SvnMergeCommand *
svn_merge_command_new(const gchar * path1,const gchar * path2,glong start_revision,glong end_revision,const gchar * target_path,gboolean recursive,gboolean ignore_ancestry,gboolean force,gboolean dry_run)124 svn_merge_command_new (const gchar *path1,
125 					   const gchar *path2,
126 					   glong start_revision,
127 					   glong end_revision,
128 					   const gchar *target_path,
129 					   gboolean recursive,
130 					   gboolean ignore_ancestry,
131 					   gboolean force,
132 					   gboolean dry_run)
133 {
134 	SvnMergeCommand *self;
135 
136 	self = g_object_new (SVN_TYPE_MERGE_COMMAND, NULL);
137 	self->priv->path1 = svn_command_make_canonical_path (SVN_COMMAND (self),
138 														path1);
139 	self->priv->path2 = svn_command_make_canonical_path (SVN_COMMAND (self),
140 														 path2);
141 	self->priv->start_revision = start_revision;
142 	self->priv->end_revision = end_revision;
143 	self->priv->target_path = svn_command_make_canonical_path (SVN_COMMAND (self),
144 															   target_path);
145 	self->priv->recursive = recursive;
146 	self->priv->ignore_ancestry = ignore_ancestry;
147 	self->priv->force = force;
148 	self->priv->dry_run = dry_run;
149 
150 	return self;
151 }
152 
153 void
svn_merge_command_destroy(SvnMergeCommand * self)154 svn_merge_command_destroy (SvnMergeCommand *self)
155 {
156 	g_object_unref (self);
157 }
158