Patchwork [20,of,55,RFC,c-hglib:level1] hg_diff: creating a high level function for mercurial diff command

login
register
mail settings
Submitter Iulian Stana
Date Sept. 14, 2013, 12:35 a.m.
Message ID <30726b3c4e0788afaaf3.1379118932@doppler>
Download mbox | patch
Permalink /patch/2464/
State Deferred, archived
Headers show

Comments

Iulian Stana - Sept. 14, 2013, 12:35 a.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1379111806 -10800
#      Sat Sep 14 01:36:46 2013 +0300
# Node ID 30726b3c4e0788afaaf354cdd85cda30906a90b9
# Parent  a3fa5ba234aeda27121ccb80a61fa73125b5f423
hg_diff: creating a high level function for mercurial diff command

Patch

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -720,6 +720,26 @@ 
 	return exitcode;
 }
 
+/* The high level cat command for hglib API. */
+hg_linestream_buffer *hg_diff(hg_handle *handle, int (*callback)
+			(const char *msg, size_t len), char *argument[])
+{
+	hg_linestream_buffer *dbuf = malloc(sizeof(hg_csetstream_buffer));
+	dbuf->handle = handle;
+
+	dbuf->command = cmdbuilder("diff", argument, NULL);
+
+	if(hg_rawcommand(handle, dbuf->command) < 0){
+		return NULL;
+	}
+
+	dbuf->callback = callback;
+	dbuf->buffer = NULL;
+	dbuf->buf_size = 0;
+
+	return dbuf;
+}
+
 /* The yield next step. Getting the next entry. */
 int hg_fetch_entry(hg_stream_buffer *stream, int (*detect_byte)(char *buff, 
 			int buf_size, int data_on_pipe), int func_type)
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -867,6 +867,57 @@ 
 							char *argument[]);
 
 /**
+ * \brief hg_diff command for hglib API.
+ *
+ * Show differences between revisions for the specified files.
+ *
+ * Differences between files are shown using the unified diff format.
+ *
+ * When two revision arguments are given, then changes are shown between those
+ * revisions. If only one revision is specified then that revision is compared
+ * to the working directory, and, when no revisions are specified, the working
+ * directory files are compared to its parent.
+ *
+ * Options/Argument list option:
+ *
+ *	-r, --rev		revision
+ *	-c, --change	change made by revision
+ *	-a, --text		treat all files as text
+ *	-g, --git		use git extended diff format
+ *	--nodates		omit dates from diff headers
+ *	-p, --show-function
+ *				show which function each change is in
+ *	--reverse		produce a diff that undoes the changes
+ *	-w, --ignore-all-space
+ *				ignore white space when comparing lines
+ *	-b, --ignore-space-change
+ *				ignore changes in the amount of white space
+ *	-B, --ignore-blank-lines
+ *				ignore changes whose lines are all blank
+ *	-U, --unified	number of lines of context to show
+ *	--stat		output diffstat-style summary of changes
+ *	-I, --include	include names matching the given patterns
+ *	-X, --exclude	exclude names matching the given patterns
+ *	-S, --subrepos	recurse into subrepositories
+ *
+ * To get diff information use the returned hg_linestream_buffer structure with
+ * hg_fetch_line_entry() function.
+ *
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param callback A function that will handle error data. 
+ *                 A NULL pointer will ignore error data.
+ * \param argument The option list. Will contain all option that you wish.
+ * \retval hg_linestream_buffer A pointer to hg_linestream_buffer structure if 
+ *                              successful
+ * \retval NULL to indicate an error, with errno set appropriately.
+ *
+ * errno can be:
+ *      - hg_rawcommand errors
+ * */
+hg_linestream_buffer *hg_diff(hg_handle *handle, int (*callback)
+			(const char *msg, size_t len), char *argument[]);
+
+/**
  * \brief The yield mechanism that will get the next entry.
  *
  * This function is used inside of hg_fetch_cset_entry() and hg_fetch_line_entry()