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-cat-command.h"
27 struct _SvnCatCommandPriv
34 G_DEFINE_TYPE (SvnCatCommand
, svn_cat_command
, SVN_TYPE_COMMAND
);
37 svn_cat_command_init (SvnCatCommand
*self
)
39 self
->priv
= g_new0 (SvnCatCommandPriv
, 1);
43 svn_cat_command_finalize (GObject
*object
)
46 GList
*current_output
;
48 self
= SVN_CAT_COMMAND (object
);
50 g_free (self
->priv
->path
);
52 current_output
= self
->priv
->output
->head
;
54 while (current_output
)
56 g_free (current_output
->data
);
57 current_output
= g_list_next (current_output
);
60 g_queue_free (self
->priv
->output
);
64 G_OBJECT_CLASS (svn_cat_command_parent_class
)->finalize (object
);
68 svn_cat_command_run (AnjutaCommand
*command
)
71 SvnCommand
*svn_command
;
72 svn_opt_revision_t revision
;
73 svn_opt_revision_t peg_revision
;
74 svn_stream_t
*cat_stream
;
75 apr_file_t
*cat_input
;
76 apr_file_t
*cat_output
;
80 apr_status_t apr_error
;
82 self
= SVN_CAT_COMMAND (command
);
83 svn_command
= SVN_COMMAND (command
);
85 apr_file_pipe_create (&cat_output
, &cat_input
,
86 svn_command_get_pool (svn_command
));
87 apr_file_pipe_timeout_set (cat_output
, 0);
88 apr_file_pipe_timeout_set (cat_input
, 0);
89 cat_stream
= svn_stream_from_aprfile2 (cat_input
, FALSE
,
90 svn_command_get_pool (svn_command
));
92 revision
.kind
= svn_opt_revision_number
;
93 revision
.value
.number
= self
->priv
->revision
;
94 peg_revision
.kind
= svn_opt_revision_unspecified
;
96 error
= svn_client_cat2 (cat_stream
,
100 svn_command_get_client_context (svn_command
),
101 svn_command_get_pool (svn_command
));
105 svn_command_set_error (svn_command
, error
);
109 while (apr_file_eof (cat_output
) != APR_EOF
)
112 line
= g_new0 (gchar
, (read_size
+ 1));
114 apr_error
= apr_file_read (cat_output
, line
, &read_size
);
121 anjuta_async_command_lock (ANJUTA_ASYNC_COMMAND (command
));
122 g_queue_push_tail (self
->priv
->output
, g_strdup (line
));
123 anjuta_async_command_unlock (ANJUTA_ASYNC_COMMAND (command
));
127 anjuta_command_notify_data_arrived (command
);
135 svn_cat_command_class_init (SvnCatCommandClass
*klass
)
137 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
138 AnjutaCommandClass
* command_class
= ANJUTA_COMMAND_CLASS (klass
);
140 object_class
->finalize
= svn_cat_command_finalize
;
141 command_class
->run
= svn_cat_command_run
;
146 svn_cat_command_new (const gchar
*path
, glong revision
)
150 self
= g_object_new (SVN_TYPE_CAT_COMMAND
, NULL
);
151 self
->priv
->path
= svn_command_make_canonical_path (SVN_COMMAND (self
),
153 self
->priv
->revision
= revision
;
154 self
->priv
->output
= g_queue_new ();
160 svn_cat_command_destroy (SvnCatCommand
*self
)
162 g_object_unref (self
);
166 svn_cat_command_get_output (SvnCatCommand
*self
)
168 return self
->priv
->output
;