Patchwork [2,of,2,RFC,C-hglib] level 1 prototypes: model (1) commands (hd_log - like commands)

login
register
mail settings
Submitter Iulian Stana
Date Aug. 29, 2013, 12:03 p.m.
Message ID <c863dec59dd4f8282689.1377777782@doppler>
Download mbox | patch
Permalink /patch/2286/
State Superseded
Headers show

Comments

Iulian Stana - Aug. 29, 2013, 12:03 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1377773509 -10800
#      Thu Aug 29 13:51:49 2013 +0300
# Node ID c863dec59dd4f82826898f041195e83392d2f621
# Parent  d0a9cc1b7a8bc6ec16b1770318de68c45534d9a9
level 1 prototypes: model (1) commands (hd_log - like commands)

This mechanism could be called model (1):

(1) Return immedietely after having sent the command to commandserv,
    just wrapping a call to hg_rawcommand().
    Other API functions are provided to retrieve:
    (a) the data sent in response by the commandserv, in parsed
(structured) form
    (b) the exitcode, i.e. the content of the 'r' channel after all things
        have happened.


Some commands must handle huge mass of data. One of those commands is "hg log"
command.

There are also other commands that must handle huge amount of data, in this case
for all of those commands I will use an iterator-like mechanism. The mercurial
command will return immediately, and user will have to get data from iterator
when he whant's.

Patch

diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -41,10 +41,47 @@ 
 	char *name;
 	char *rev;
 	char *node;
+	char *line;
 }hg_bookmark_struct;
 
 
 /**
+ * hg_cset_iterator structure description
+ */
+typedef struct hg_cset_iterator{
+	hg_handle *handle;
+	char **command;
+	char *cset;
+	int cset_size;
+	int cset_send;
+	int top_cset_size;
+}hg_cset_iterator;
+
+/**
+ * hg_rev_iterator structure description
+ */
+typedef struct hg_rev_iterator{
+	hg_handle *handle;
+	char *rev;
+}hg_rev_iterator;
+
+/**
+ * hg_line_iterator structure description
+ */
+typedef struct hg_line_iterator{
+	hg_handle *handle;
+	char *line;
+}hg_line_iterator;
+
+/**
+ * hg_manifest_iterator structure description
+ */
+typedef struct hg_manifest_iterator{
+	hg_handle *handle;
+	char *line;
+}hg_manifest_iterator;
+
+/**
  * Example of description.
  * \brief hg_add command for hglib API.
  *
@@ -74,6 +111,13 @@ 
 							char *argument[]);
 
 /**
+ * annotate description
+ * returning the rev iterator. The annotate command could return lots of
+ * lines. 
+ * */
+hg_rev_iterator *annotate(hg_handle *handle, char *option[]);
+
+/**
  * archive description
  * */
 int hg_archive(hg_handle *handle, int(*callback)(const char *msg, size_t len),
@@ -87,6 +131,12 @@ 
                char (*prompt)(const char *msg, size_t len), char *argument[]);
 
 /**
+ * bisect description
+ * returning the cset iterator. The bisect command could return more csets. 
+ * */
+hg_cset_iterator *bisect(hg_handle *handle, char *option[]);
+
+/**
  * bookmark description.
  * */
 int hg_bookmark(hg_handle *handle, int(*callback)(const char *msg, size_t len),
@@ -119,6 +169,12 @@ 
 							char *argument[]);    
      
 /**
+ * cat description
+ * returning the line    iterator. The cat command could return lots of lines. 
+ * */
+hg_line_iterator *cat(hg_handle *handle, char *option[]);
+
+/**
  * commit description.
  * The return value will be a tuple(rev, node)
  * */
@@ -132,10 +188,42 @@ 
 							char *argument[]);
 
 /**
+ * diff description
+ * returning the line iterator. The diff command could return lots of lines. 
+ * */
+hg_line_iterator *diff(hg_handle *handle, char *option[]);
+
+/**
+ * export_ description
+ * returning the line iterator. The export_ command could return lots of lines. 
+ * */
+hg_line_iterator *export_(hg_handle *handle, char *option[]);
+
+/**
  * forget description
  * */
 int hg_forget(hg_handle *handle, int(*callback)(const char *msg, size_t len),
 							char *argument[]);
+
+/**
+ * grep description
+ * returning the rev iterator. The grep command could return lots of
+ * lines. 
+ * */
+hg_rev_iterator *grep(hg_handle *handle, char *option[]);
+
+/**
+ * heads description
+ * returning the cset iterator. The heads command could return more csets. 
+ * */
+hg_cset_iterator *heads(hg_handle *handle, char *option[]);
+
+/**
+ * help description
+ * returning the line iterator. The help command could return lots of lines. 
+ * */
+hg_line_iterator *help(hg_handle *handle, char *option[]);
+
 /**
  * identify description
  * I would really like to know how to parse this data...
@@ -151,6 +239,12 @@ 
                char (*prompt)(const char *msg, size_t len), char *argument[]);
 
 /**
+ * incoming description
+ * returning the cset iterator. The incoming command could return more csets. 
+ * */
+hg_cset_iterator *incoming(hg_handle *handle, char *option[]);
+
+/**
  * locate description
  * Return a list of strings (files).
  * */
@@ -158,6 +252,41 @@ 
 							char *argument[]);
 
 /**
+ * Example of description.
+ * \brief hg_log command for hglib API.
+ *
+ * It's an advance function to get revision history. It's more like the start 
+ * point of the action, this function will prepare the query question and will 
+ * send it to the cmd-server.
+ *
+ * Return the revision history of the specified files or the entire project.
+ * File history is shown without following rename or copy history of files.
+ * Use follow with a filename to follow history across renames and copies.
+ * follow without a filename will only show ancestors or descendants of the
+ * starting revision. followfirst only follows the first parent of merge
+ * revisions.
+ *
+ * If revrange isn't specified, the default is "tip:0" unless follow is set,
+ * in which case the working directory parent is used as the starting
+ * revision.
+ *
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param option The option list for mercurial log command.
+ * \retval hg_log_iterator A pointer to hg_log_iterator structure if successful
+ * \retval NULL to indicate an error, with errno set appropriately.
+ *
+ * errno can be:
+ *      - hg_rawcommand errors
+ * */
+hg_cset_iterator *hg_log(hg_handle *handle, char *option[]);
+
+/**
+ * manifest description
+ * returning the manifest iterator. The manifest command could return lots of lines. 
+ * */
+hg_manifest_iterator *outgoing(hg_handle *handle, char *option[]);s
+
+/**
  * merge function
  * The merge function can have prompts.
  * */
@@ -165,6 +294,19 @@ 
                char (*prompt)(const char *msg, size_t len), char *argument[]);
 
 /**
+ * outgoing description
+ * returning the cset iterator. The outgoing command could return more csets. 
+ * */
+hg_cset_iterator *outgoing(hg_handle *handle, char *option[]);
+
+/**
+ * parents description
+ * returning the cset iterator. The parents command could return more csets. 
+ * */
+hg_cset_iterator *parents(hg_handle *handle, char *option[]);
+
+
+/**
  * paths description
  * retrun some parse data.
  * I don't really know how this command is working and what data will deliver.
@@ -236,6 +378,12 @@ 
 char *hg_root(hg_handle *handle, int(*callback)(const char *msg, size_t len));
 
 /**
+ * showconfig description
+ * returning the line iterator. The showconfig command could return lots of lines. 
+ * */
+hg_line_iterator *showconfig(hg_handle *handle, char *option[]);
+
+/**
  * status description
  * return a list of (code, file path)
  **/
@@ -296,4 +444,54 @@ 
 char *hg_version(hg_handle *handle, int(*callback)(const char *msg, size_t len),
 							char *argument[]);
 
+/**
+ * Example of description.
+ * \brief The iterator step. Getting the next changeset.
+ *
+ * The revision history could have a huge mass of data. You can pass the entire 
+ * history in one call, so we use an iterator-like mechanism. Calling the 
+ * hg_fetch_log_entry, the next changeset will be read from cmd-server, parse
+ * and pass to hg_log_entry_t structure.
+ * The log_entry structure will handle a  changeset with the following string 
+ * fields:
+ *         - rev
+ *         - node
+ *         - tags (space delimited)
+ *         - branch
+ *         - author
+ *         - desc
+ *
+ * \param log_iterator The iterator for log command.
+ * \param log_entry The hg_log_entry_t structure where the changeset will be 
+ *                   pass
+ * \retval number The lenght for the pass changeset.
+ * \retval exitcode To indicate the end of log_command.
+ * \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_cset_entry(hg_cset_iterator *iterator, hg_cset_entry_t *entry_t);
+
+/**
+ * hg_fetch_rev_entry description
+ * the rev_entry_t structure will contain the parse revision (rev, line);
+ * */
+int hg_fetch_rev_entry(hg_rev_iterator *iterator, hg_rev_entry_t *entry_t);
+
+/**
+ * hg_fetch_line_entry description
+ * This function will read one line at a time from iterator and pass to user.
+ * */
+int hg_fetch_line_entry(hg_line_iterator *iterator, char *line, size_t line_size);
+
+/**
+ * hg_fetch_manifest_entry description
+ * the manifest_entry_t structure will contain the parse line 
+ * (node, perm, executable, symbolic, line);
+ * */
+int hg_fetch_manifest_entry(hg_manifest_iterator *iterator, hg_manifest_entry_t *entry_t);
+
 #endif