Example #1
0
static svn_error_t *
log_callback (void *baton,
			  apr_hash_t *changed_paths,
			  svn_revnum_t revision,
			  const char *author,
			  const char *date,
			  const char *message,
			  apr_pool_t *pool)
{
	SvnLogCommand *self;
	SvnLogEntry *log_entry;
	gchar *entry_author;
	const gchar *human_date;
	gchar *entry_date;
	apr_time_t entry_time;
	gchar *entry_message;
	
	self = SVN_LOG_COMMAND (baton);
	
	/* Libsvn docs say author, date, and message might be NULL. */
	if (author)
		entry_author = g_strdup (author);
	else 
		entry_author = g_strdup ("(none)");
	
	if (date && date[0])
	{
		svn_time_from_cstring (&entry_time, date,
							   svn_command_get_pool (SVN_COMMAND (self)));
		human_date = svn_time_to_human_cstring (entry_time,
												svn_command_get_pool (SVN_COMMAND (self)));
		entry_date = g_strdup (human_date);
	}
	else
		entry_date = g_strdup ("(none)");
	
	if (message)
		entry_message = g_strdup (message);
	else
		entry_message = g_strdup ("empty log message"); /* Emulate ViewCVS */
	
	log_entry = svn_log_entry_new (entry_author, entry_date, revision, 
								   entry_message);

	g_free (entry_author);
	g_free (entry_date);
	g_free (entry_message);
	
	anjuta_async_command_lock (ANJUTA_ASYNC_COMMAND (self));
	g_queue_push_head (self->priv->log_entry_queue, log_entry);
	anjuta_async_command_unlock (ANJUTA_ASYNC_COMMAND (self));
	
	anjuta_command_notify_data_arrived (ANJUTA_COMMAND (self));
	
	return SVN_NO_ERROR;
}
static void
git_branch_list_command_handle_output (GitCommand *git_command, 
									   const gchar *output)
{
	GitBranchListCommand *self;
	GMatchInfo *active_match_info;
	GMatchInfo *regular_match_info;
	gchar *branch_name;
	GitBranch *branch;
	gboolean active;

	self = GIT_BRANCH_LIST_COMMAND (git_command);
	
	active_match_info = NULL;
	regular_match_info = NULL;
	branch_name = NULL;
	branch = NULL;
	active = FALSE;
	
	if (g_regex_match (self->priv->active_branch_regex, output, 0, 
					   &active_match_info))
	{
		branch_name = g_match_info_fetch (active_match_info, 1);
		active = TRUE;
	}
	else if (g_regex_match (self->priv->regular_branch_regex, output, 0,
							&regular_match_info))
	{
		branch_name = g_match_info_fetch (regular_match_info, 1);
	}
	
	if (branch_name)
		branch = git_branch_new (branch_name, active);
	
	g_free (branch_name);


	if (active_match_info)
		g_match_info_free (active_match_info);

	if (regular_match_info)
		g_match_info_free (regular_match_info);
	
	g_queue_push_head (self->priv->output, branch);
	anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command));
	
}
Example #3
0
static void
git_stash_list_command_handle_output (GitCommand *git_command, 
									  const gchar *output)
{
	GitStashListCommand *self;
	GMatchInfo *match_info;
	gchar *stash_id;
	gchar *stash_number;
	gchar *stash_message;
	GitStash *stash;

	self = GIT_STASH_LIST_COMMAND (git_command);
	
	match_info = NULL;
	stash_id = NULL;
	stash_message = NULL;
	stash = NULL;
	
	if (g_regex_match (self->priv->stash_regex, output, 0, &match_info))
	{
		stash_id = g_match_info_fetch (match_info, 1);
		stash_number = g_match_info_fetch (match_info, 2);
		stash_message = g_match_info_fetch (match_info, 3);

		stash = git_stash_new (stash_id, stash_message, atoi (stash_number));

		g_free (stash_id);
		g_free (stash_number);
		g_free (stash_message);

		g_queue_push_head (self->priv->output, stash);
		anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command));
	}

	if (match_info)
		g_match_info_free (match_info);
}
Example #4
0
static guint
svn_cat_command_run (AnjutaCommand *command)
{
	SvnCatCommand *self;
	SvnCommand *svn_command;
	svn_opt_revision_t revision;
	svn_opt_revision_t peg_revision;
	svn_stream_t *cat_stream;
	apr_file_t *cat_input;
	apr_file_t *cat_output;
	apr_size_t read_size;
	gchar *line;
	svn_error_t *error;
	apr_status_t apr_error;
	
	self = SVN_CAT_COMMAND (command);
	svn_command = SVN_COMMAND (command);
	
	apr_file_pipe_create (&cat_output, &cat_input, 
						  svn_command_get_pool (svn_command));
	apr_file_pipe_timeout_set (cat_output, 0);
	apr_file_pipe_timeout_set (cat_input, 0);
	cat_stream = svn_stream_from_aprfile2 (cat_input, FALSE, 
										   svn_command_get_pool (svn_command));
	
	revision.kind = svn_opt_revision_number;
	revision.value.number = self->priv->revision;
	peg_revision.kind = svn_opt_revision_unspecified;
	
	error = svn_client_cat2 (cat_stream,
							 self->priv->path,
							 &peg_revision,
							 &revision,
							 svn_command_get_client_context (svn_command),
							 svn_command_get_pool (svn_command));
	
	if (error)
	{
		svn_command_set_error (svn_command, error);
		return 1;
	}
	
	while (apr_file_eof (cat_output) != APR_EOF)
	{
		read_size = 80;
		line = g_new0 (gchar, (read_size + 1));
		
		apr_error = apr_file_read (cat_output, line, &read_size);
		
		if (apr_error)
			break;
		
		if (strlen (line))
		{
			anjuta_async_command_lock (ANJUTA_ASYNC_COMMAND (command));
			g_queue_push_tail (self->priv->output, g_strdup (line));
			anjuta_async_command_unlock (ANJUTA_ASYNC_COMMAND (command));
			
			g_free (line);
			
			anjuta_command_notify_data_arrived (command);
		}
	}
								 
	return 0;
}
Example #5
0
static void
git_log_command_handle_output (GitCommand *git_command, const gchar *output)
{
	GitLogCommand *self;
	GMatchInfo *commit_match_info;
	GMatchInfo *parent_match_info;
	GMatchInfo *author_match_info;
	GMatchInfo *time_match_info;
	GMatchInfo *short_log_match_info;
	gchar *commit_sha;
	gchar *parents;
	gchar **parent_shas;
	gint i;
	GitRevision *parent_revision;
	gchar *author;
	gchar *time;
	gchar *short_log;
	
	self = GIT_LOG_COMMAND (git_command);

	commit_match_info = NULL;
	parent_match_info = NULL;
	author_match_info = NULL;
	time_match_info = NULL;
	short_log_match_info = NULL;
	
	/* Entries are delimited by the hex value 0x0c */
	if (*output == 0x0c && self->priv->current_revision)
	{	
		g_queue_push_tail (self->priv->output_queue, 
						   self->priv->current_revision);
		anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command));
	}
	
	if (g_regex_match (self->priv->commit_regex, output, 0, &commit_match_info))
	{
		commit_sha = g_match_info_fetch (commit_match_info, 1);
		
		self->priv->current_revision = g_hash_table_lookup (self->priv->revisions, 
															commit_sha);
		
		if (!self->priv->current_revision)
		{
			self->priv->current_revision = git_revision_new ();
			git_revision_set_sha (self->priv->current_revision, commit_sha);
			g_hash_table_insert (self->priv->revisions, g_strdup (commit_sha),
								 g_object_ref (self->priv->current_revision));
		}
		
		g_free (commit_sha);
	}
	else if (g_regex_match (self->priv->parent_regex, output, 0, 
							&parent_match_info))
	{	
		parents = g_match_info_fetch (parent_match_info, 1);
		parent_shas = g_strsplit (parents, " ", -1);
		
		for (i = 0; parent_shas[i]; i++)
		{
			parent_revision = g_hash_table_lookup (self->priv->revisions,
												   parent_shas[i]);
			
			if (!parent_revision)
			{
				parent_revision = git_revision_new ();
				git_revision_set_sha (parent_revision, parent_shas[i]);
				g_hash_table_insert (self->priv->revisions,
									 g_strdup (parent_shas[i]),
									 g_object_ref (parent_revision));
			}
			
			git_revision_add_child (parent_revision,
									self->priv->current_revision);
		}
		
		g_free (parents);
		g_strfreev (parent_shas);
	}
	else if (g_regex_match (self->priv->author_regex, output, 0, 
			 &author_match_info))
	{
		author = g_match_info_fetch (author_match_info, 1);
		git_revision_set_author (self->priv->current_revision, author);
		
		g_free (author);
	}
	else if (g_regex_match (self->priv->time_regex, output, 0, 
			 &time_match_info))
	{
		time = g_match_info_fetch (time_match_info, 1);
		git_revision_set_date (self->priv->current_revision, atol (time));
		
		g_free (time);
	}
	else if (g_regex_match (self->priv->short_log_regex, output, 0, 
							&short_log_match_info))
	{
		short_log = g_match_info_fetch (short_log_match_info, 1);
		git_revision_set_short_log (self->priv->current_revision, short_log);
		
		g_free (short_log);
	}
	
	if (commit_match_info)
		g_match_info_free (commit_match_info);

	if (parent_match_info)
		g_match_info_free (parent_match_info);

	if (author_match_info)
		g_match_info_free (author_match_info);

	if (time_match_info)
		g_match_info_free (time_match_info);

	if (short_log_match_info)
		g_match_info_free (short_log_match_info);
}
Example #6
0
static void
git_status_command_handle_output (GitCommand *git_command, const gchar *output)
{
	GitStatusCommand *self;
	GMatchInfo *match_info;
	GitStatus *status_object;
	gchar *status;
	gchar *path;
	
	self = GIT_STATUS_COMMAND (git_command);
	status_object = NULL;

	if (g_regex_match (self->priv->status_regex, output, 0, &match_info))
	{
		/* Determine which section this entry goes in */
		status = g_match_info_fetch (match_info, 1);
		path = g_match_info_fetch (match_info, 3);

		if (status[0] == ' ')
		{
			/* Changed but not updated */
			if (self->priv->sections & GIT_STATUS_SECTION_NOT_UPDATED)
			{
				status_object = git_status_new(path, 
				                               GPOINTER_TO_INT (g_hash_table_lookup (self->priv->status_codes, 
				                                                					 GINT_TO_POINTER (status[1]))));
			}
		}
		else if (status[1] == ' ')
		{
			/* Added to commit */
			if (self->priv->sections & GIT_STATUS_SECTION_COMMIT)
			{
				status_object = git_status_new(path, 
				                               GPOINTER_TO_INT (g_hash_table_lookup (self->priv->status_codes, 
				                                                    				 GINT_TO_POINTER (status[0]))));
			}
		}
		else
		{
			/* File may have been added to the index and then changed again in
			 * the working tree, or it could be a conflict */

			/* Unversioned files */
			if (status[0] == '?')
			{
				if (self->priv->sections & GIT_STATUS_SECTION_UNTRACKED)
				{
					status_object = git_status_new(path, 
				                           		   ANJUTA_VCS_STATUS_UNVERSIONED);
				}
			}
			else if (g_hash_table_lookup_extended (self->priv->conflict_codes, status,
			                                       NULL, NULL))
			{
				/* Conflicts are put in the changed but not updated section */
				if (self->priv->sections & GIT_STATUS_SECTION_NOT_UPDATED)
				{
					status_object = git_status_new (path, 
					                                ANJUTA_VCS_STATUS_CONFLICTED);
				}
			}
			else
			{
				status_object = git_status_new(path, 
				                               GPOINTER_TO_INT(g_hash_table_lookup (self->priv->status_codes, 
				                                                                    GINT_TO_POINTER (status[0]))));
			}
			    
		}

		

		g_free (status);
		g_free (path);

		if (status_object)
		{
			g_queue_push_tail (self->priv->status_queue, status_object);
			anjuta_command_notify_data_arrived (ANJUTA_COMMAND (self));
		}
		
	}

	g_match_info_free (match_info);
	
}
Example #7
0
static void
git_status_command_handle_output (GitCommand *git_command, const gchar *output)
{
	GitStatusCommand *self;
	GMatchInfo *match_info;
	GitStatus *status_object;
	gchar *status;
	gchar *path;
	
	self = GIT_STATUS_COMMAND (git_command);
	
	/* See if the section has changed */
	if (g_regex_match (self->priv->section_commit_regex, output, 0, NULL))
	{
		self->priv->current_section = GIT_STATUS_SECTION_COMMIT;
		self->priv->current_section_regex = self->priv->status_regex;
		return;
	}
	else if (g_regex_match (self->priv->section_not_updated_regex, output, 0, 
							NULL))
	{
		self->priv->current_section = GIT_STATUS_SECTION_NOT_UPDATED;
		self->priv->current_section_regex = self->priv->status_regex;
		return;
	}
	else if (g_regex_match (self->priv->section_untracked_regex, output, 0, 
							NULL))
	{
		self->priv->current_section = GIT_STATUS_SECTION_UNTRACKED;
		self->priv->current_section_regex = self->priv->untracked_files_regex;
		return;
	}
	
	if (self->priv->sections & self->priv->current_section)
	{
		if (g_regex_match (self->priv->current_section_regex, output, 0, 
						   &match_info))
		{
			if (self->priv->current_section_regex == self->priv->status_regex)
			{
				status = g_match_info_fetch (match_info, 1);
				path = g_match_info_fetch (match_info, 2);
			}
			else
			{
				status = g_strdup ("untracked");
				path = g_match_info_fetch (match_info, 1);
			}
			
			/* Git sometimes mentions paths twice in status output. This can
			 * happen, for example, where there is a conflict, in which case a
			 * path would show up as both "unmerged" and "modified." */
			g_strchug (path);
			
			if (!g_hash_table_lookup_extended (self->priv->path_lookup_table, 
											   path, NULL, NULL))
			{
				status_object = git_status_new (path, status);
				g_queue_push_tail (self->priv->status_queue, status_object);
				g_hash_table_insert (self->priv->path_lookup_table,  
									 g_strdup (path), NULL);
				anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command));
			}
			
			g_free (status);
			g_free (path);
		}

		g_match_info_free (match_info);
	}
}
Example #8
0
static void
on_data_command_data_arrived (AnjutaCommand *command, GitLogCommand *self)
{
	anjuta_command_notify_data_arrived (command);
}