Exemple #1
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);
	
}
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);
	}
}