Patchwork [30,of,55,RFC,c-hglib:level1] hg_locate: creating a high level function for mercurial locate command

login
register
mail settings
Submitter Iulian Stana
Date Sept. 14, 2013, 12:35 a.m.
Message ID <f878cd8368a6d91d2107.1379118942@doppler>
Download mbox | patch
Permalink /patch/2473/
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 1379112589 -10800
#      Sat Sep 14 01:49:49 2013 +0300
# Node ID f878cd8368a6d91d2107af4e93ead5f4b7dc69e5
# Parent  9e2ee0ccc497cc713e0d7e3799fa3e7a85adc333
hg_locate: creating a high level function for mercurial locate command

Patch

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -912,6 +912,26 @@ 
 	return cbuf;
 }
 
+/* The high level locate command for hglib API. */
+hg_linestream_buffer *hg_locate(hg_handle *handle, int (*callback)
+			(const char *msg, size_t len), char *argument[])
+{
+	hg_linestream_buffer *lbuf = malloc(sizeof(hg_csetstream_buffer));
+	lbuf->handle = handle;
+
+	lbuf->command = cmdbuilder("locate", argument, NULL);
+
+	if(hg_rawcommand(handle, lbuf->command) < 0){
+		return NULL;
+	}
+
+	lbuf->callback = callback;
+	lbuf->buffer = NULL;
+	lbuf->buf_size = 0;
+
+	return lbuf;
+}
+
 /* 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
@@ -1239,29 +1239,6 @@ 
 		char *(*prompt)(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()
- * function. This function represent the modularized function of those two.
- *
- * \param hg_stream_buffer The stream structure to store entry data.
- * \param detect_byte The function to detect the size of the next entry.
- * \param func_type The type for function that will use this function:
- *      - 0 for hg_fetch_cset_entry() used with detect_null_byte() function
- *      - 1 for hg_fetch_line_entry() used with detect_endline_byte() function
- * \retval 1  Succesful operation, pass the first find cset to centry structure
- * \retval 0  To indicate the end of log_command, everything works well.
- * \retval -1 to indicate an error, with errno set appropriately.
- *
- * errno can be:
- *      - EINVAL  - Invalid argument (handle it's set to a null pointer)
- *      - read(2) command errors
- *      - read_header error
- * */
-int hg_fetch_entry(hg_stream_buffer *stream, int (*detect_byte)(char *buff, 
-			int buf_size, int data_on_pipe), int func_type);
-
-/**
  * \brief hg_incoming command for hglib API.
  * 
  * Show new changesets found in the specified path/URL or the default pull
@@ -1312,6 +1289,67 @@ 
 			(const char *msg, size_t len), char *argument[]);
 
 /**
+ * \brief hg_locate command for hglib API.
+ * 
+ * Print files under Mercurial control in the working directory whose names
+ * match the given patterns.
+ *
+ * By default, this command searches all directories in the working directory.
+ * To search just the current directory and its subdirectories, use "--include
+ * .".
+ *
+ * If no patterns are given to match, this command prints the names of all 
+ * files under Mercurial control in the working directory.
+ *
+ * Options/Argument list option:
+ *
+ *	-r, --rev		search the repository as it is in REV
+ *	-0, --print0	end filenames with NUL, for use with xargs
+ *	-f, --fullpath	print complete paths from the filesystem root
+ *	-I, --include	include names matching the given patterns
+ *	-X, --exclude	exclude names matching the given patterns
+ *  
+ * To get locate information use the returned hg_linestream_buffer strucutre 
+ * 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_locate(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()
+ * function. This function represent the modularized function of those two.
+ *
+ * \param hg_stream_buffer The stream structure to store entry data.
+ * \param detect_byte The function to detect the size of the next entry.
+ * \param func_type The type for function that will use this function:
+ *      - 0 for hg_fetch_cset_entry() used with detect_null_byte() function
+ *      - 1 for hg_fetch_line_entry() used with detect_endline_byte() function
+ * \retval 1  Succesful operation, pass the first find cset to centry structure
+ * \retval 0  To indicate the end of log_command, everything works well.
+ * \retval -1 to indicate an error, with errno set appropriately.
+ *
+ * errno can be:
+ *      - EINVAL  - Invalid argument (handle it's set to a null pointer)
+ *      - read(2) command errors
+ *      - read_header error
+ * */
+int hg_fetch_entry(hg_stream_buffer *stream, int (*detect_byte)(char *buff, 
+			int buf_size, int data_on_pipe), int func_type);
+
+/**
  * \brief The yield mechanism that will get the next changeset.
  *
  * The revision history could have a huge mass of data. You cannot pass the