1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2008 <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 "git-list-tree-command.h"
27 #define BLOB_REGEX "blob ([[:xdigit:]]{40})(?:\\t)(.*)"
29 struct _GitListTreeCommandPriv
36 G_DEFINE_TYPE (GitListTreeCommand
, git_list_tree_command
, GIT_TYPE_COMMAND
);
39 git_list_tree_command_init (GitListTreeCommand
*self
)
41 self
->priv
= g_new0 (GitListTreeCommandPriv
, 1);
43 self
->priv
->blob_regex
= g_regex_new (BLOB_REGEX
, 0, 0, NULL
);
44 self
->priv
->blobs
= g_hash_table_new_full (g_str_hash
, g_str_equal
, g_free
,
49 git_list_tree_command_finalize (GObject
*object
)
51 GitListTreeCommand
*self
;
53 self
= GIT_LIST_TREE_COMMAND (object
);
55 g_free (self
->priv
->commit_sha
);
56 g_regex_unref (self
->priv
->blob_regex
);
57 g_hash_table_unref (self
->priv
->blobs
);
61 G_OBJECT_CLASS (git_list_tree_command_parent_class
)->finalize (object
);
65 git_list_tree_command_run (AnjutaCommand
*command
)
67 GitListTreeCommand
*self
;
69 self
= GIT_LIST_TREE_COMMAND (command
);
71 git_command_add_arg (GIT_COMMAND (command
), "ls-tree");
72 git_command_add_arg (GIT_COMMAND (command
), self
->priv
->commit_sha
);
78 git_list_tree_command_handle_output (GitCommand
*git_command
,
81 GitListTreeCommand
*self
;
82 GMatchInfo
*match_info
;
86 self
= GIT_LIST_TREE_COMMAND (git_command
);
89 if (g_regex_match (self
->priv
->blob_regex
, output
, 0, &match_info
))
91 blob_sha
= g_match_info_fetch (match_info
, 1);
92 filename
= g_match_info_fetch (match_info
, 2);
94 g_hash_table_insert (self
->priv
->blobs
, g_strdup (filename
),
102 g_match_info_free (match_info
);
106 git_list_tree_command_class_init (GitListTreeCommandClass
*klass
)
108 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
109 GitCommandClass
* parent_class
= GIT_COMMAND_CLASS (klass
);
110 AnjutaCommandClass
*command_class
= ANJUTA_COMMAND_CLASS (klass
);
112 object_class
->finalize
= git_list_tree_command_finalize
;
113 parent_class
->output_handler
= git_list_tree_command_handle_output
;
114 command_class
->run
= git_list_tree_command_run
;
119 git_list_tree_command_new (const gchar
*working_directory
,
120 const gchar
*commit_sha
)
122 GitListTreeCommand
*self
;
124 self
= g_object_new (GIT_TYPE_LIST_TREE_COMMAND
,
125 "working-directory", working_directory
,
126 "single-line-output", TRUE
,
129 self
->priv
->commit_sha
= g_strdup (commit_sha
);
135 git_list_tree_command_get_blobs (GitListTreeCommand
*self
)
137 return g_hash_table_ref (self
->priv
->blobs
);