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

login
register
mail settings
Submitter Iulian Stana
Date Aug. 29, 2013, 12:03 p.m.
Message ID <d0a9cc1b7a8bc6ec16b1.1377777781@doppler>
Download mbox | patch
Permalink /patch/2285/
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 1377770933 -10800
#      Thu Aug 29 13:08:53 2013 +0300
# Node ID d0a9cc1b7a8bc6ec16b1770318de68c45534d9a9
# Parent  0000000000000000000000000000000000000000
level 1 prototypes: model (2) commands (hd_add - like commands)

This mechanism could be called model (2):

(2) Wait for the commandserv to complete *all* his actions in response to
    the issued command, which is cache the commandserv response somewhere,
    and return the actual exitcode (channel 'r' from commandserv)
    as the result of the chglib API call"


The add command and more other mercurial commands, are not performing any kind
of parse data. The most important thing on those commands is the exitcode, if
everything works well or not.

Also in this model, can be included those commands with a low amount of data,
where I need to parse a cset or I need to return some revision data (rev, node,
and the name of some fields).
Iulian Stana - Aug. 29, 2013, 12:05 p.m.
I would like to receive some remarks for some of those commands. The rest
of
commands will have the same stories.

 +/**

> + * Example of description.
> + * \brief hg_add command for hglib API.
> + *
> + * Add the specified files on the next commit.
> + * If no files are given, add all files to the repository.
> + *
> + *      dryrun - do no perform actions
> + *      subrepos - recurse into subrepositories
> + *      include - include names matching the given patterns
> + *      exclude - exclude names matching the given patterns
> + *
> + * \param handle The handle of the connection, wherewith I want to
> communicate
> + * \param callback The handle function for error data.
> + * \param option The option list for mercurial add command.
> + * \retval exitcode  To indicate the end of add_command.
> + *
> + * errno can be:
> + *      - hg_rawcommand errors
> + * */
> +int hg_add(hg_handle *handle, int (*callback)(const char *msg, size_t
> len),
> +                                                       char *argument[]);
> +
>

Almost all of those commands have the same signature. I would like to
know if this signature will fit with mercurial or if I must change it.
The callback function will handle the error data.



> +/**
> + * bookmarks description.
> + * The return value will be a list of tuples(name, rev, node)
> + * */
> +hg_rev_entry_t *hg_bookmarks(hg_handle *handle, int(*callback)
> +                        (const char *msg, size_t len), char *argument[]);
> +
>

I would like to know if this command is a model (1) command... (probably
the list will have a lots of bookmarks).

Also I would like to know if the hg_rev_entry_t is the proper name for this
tuple.


> +/**
> + * branches description.
> + * The return value will be a list of tuples(name, rev, node)
> + * */
> +hg_rev_entry_t *hg_branches(hg_handle *handle, int(*callback)
> +                        (const char *msg, size_t len), char *argument[]);
> +
>

Same story like above.


> +/**
> + * commit description.
> + * The return value will be a tuple(rev, node)
> + * */
> +hg_rev_entry_t hg_commit(hg_handle *handle, int(*callback)
> +                        (const char *msg, size_t len), char *argument[]);
> +
>

The return value must be the exitcode or a tuple?



> +/**
> + * identify description
> + * I would really like to know how to parse this data...
> + * */
> +char *hg_identify(hg_handle *handle, int(*callback)(const char *msg,
> size_t len),
> +                                                       char *argument[]);
> +
>

What kind of data is this function returning ?

+/**
> + * merge function
> + * The merge function can have prompts.
> + * */
> +int hg_merge(hg_handle *handle, int (*callback)(const char *msg, size_t
> len),
> +               char (*prompt)(const char *msg, size_t len), char
> *argument[]);
> +
>

A command that can have prompts...



> +/**
> + * paths description
> + * retrun some parse data.
> + * I don't really know how this command is working and what data will
> deliver.
> + * */
> +hg_struct hg_paths(hg_handle *handle, int(*callback)(const char *msg,
> size_t len),
> +                                                       char *argument[]);
> +
>

What kind of data is this function returning ?

+/**
> + * tags description
> + * return a list of tags.
> + **/
> +hg_tags_struct *hg_tags(hg_handle *handle, int(*callback)
> +                        (const char *msg, size_t len), char *argument[]);
> +
>

Same story like bookmarks command.


> +/**
> + * tip description
> + * The return value will be a cset_entry structure (the tip cset will be
> parse
> + * and pass to directly to user). If any error occur, the return value
> will be a
> + * NULL pointer and errno will be set appropiate.
> + * */
> +hg_cset_entry_t *hg_tip(hg_handle *handle, int(*callback)(const char *msg,
> +                                               size_t len), char
> *argument[]);
> +
>

The return value is the parse changeset. It would be better to return the
exitcode and the cset structure to be put in command signature?



> +/**
> + * verify description
> + **/
> +hg_verify_entry_t *hg_verify(hg_handle *handle, int(*callback)
> +                               (const char *msg, size_t len), char
> *argument[]);
> +
>

What kind of data is this function returning ? How will verify structure
look like? What I will parse in this structure?

Patch

diff --git a/client.h b/client.h
new file mode 100644
--- /dev/null
+++ b/client.h
@@ -0,0 +1,299 @@ 
+#ifndef _CLIENT_H_
+#define _CLIENT_H_
+
+#include <errno.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+
+/**
+ * hg_handle structure description
+ */
+typedef struct hg_handle{
+	pid_t childpid;
+	hg_header next_header;
+	hg_header current_header;
+	int p_read;
+	int p_write;
+	int protect;
+
+	int out_data_size;
+	char *out_data;
+} hg_handle;
+
+/**
+ * hg_cset_entry_t structure description
+ */
+typedef struct hg_cset_entry_t{
+	char *author; 
+	char *branch; 
+	char *date;
+	char *desc;
+	char *node;
+	char *rev;
+	char *tags;
+}hg_cset_entry_t;
+
+/**
+ * hg_rev_entry_t structure description
+ */
+typedef struct hg_rev_entry_t{
+	char *name;
+	char *rev;
+	char *node;
+}hg_bookmark_struct;
+
+
+/**
+ * Example of description.
+ * \brief hg_add command for hglib API.
+ *
+ * Add the specified files on the next commit.
+ * If no files are given, add all files to the repository.
+ *
+ *      dryrun - do no perform actions
+ *      subrepos - recurse into subrepositories
+ *      include - include names matching the given patterns
+ *      exclude - exclude names matching the given patterns
+ *
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param callback The handle function for error data.
+ * \param option The option list for mercurial add command.
+ * \retval exitcode  To indicate the end of add_command.
+ *
+ * errno can be:
+ *      - hg_rawcommand errors
+ * */
+int hg_add(hg_handle *handle, int (*callback)(const char *msg, size_t len), 
+							char *argument[]);
+
+/**
+ * addremove description
+ * */
+int hg_addremove(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * archive description
+ * */
+int hg_archive(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * backout function
+ * The backout function can have prompts and also a merge tool can appear.
+ * */
+int hg_backout(hg_handle *handle, int (*callback)(const char *msg, size_t len),
+               char (*prompt)(const char *msg, size_t len), char *argument[]);
+
+/**
+ * bookmark description.
+ * */
+int hg_bookmark(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * bookmarks description.
+ * The return value will be a list of tuples(name, rev, node)
+ * */
+hg_rev_entry_t *hg_bookmarks(hg_handle *handle, int(*callback)
+                        (const char *msg, size_t len), char *argument[]);
+
+/**
+ * branch description.
+ * */
+int hg_branch(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * branches description.
+ * The return value will be a list of tuples(name, rev, node)
+ * */
+hg_rev_entry_t *hg_branches(hg_handle *handle, int(*callback)
+                        (const char *msg, size_t len), char *argument[]);
+
+/**
+ * bundle description.
+ * */
+int hg_bundle(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);    
+     
+/**
+ * commit description.
+ * The return value will be a tuple(rev, node)
+ * */
+hg_rev_entry_t hg_commit(hg_handle *handle, int(*callback)
+                        (const char *msg, size_t len), char *argument[]);
+          
+/**
+ * copy description.
+ * */
+int hg_copy(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * forget description
+ * */
+int hg_forget(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+/**
+ * identify description
+ * I would really like to know how to parse this data...
+ * */
+char *hg_identify(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * import function
+ * The import function can have prompts.
+ * */
+int hg_import(hg_handle *handle, int (*callback)(const char *msg, size_t len),
+               char (*prompt)(const char *msg, size_t len), char *argument[]);
+
+/**
+ * locate description
+ * Return a list of strings (files).
+ * */
+char **hg_locate(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * merge function
+ * The merge function can have prompts.
+ * */
+int hg_merge(hg_handle *handle, int (*callback)(const char *msg, size_t len),
+               char (*prompt)(const char *msg, size_t len), char *argument[]);
+
+/**
+ * paths description
+ * retrun some parse data.
+ * I don't really know how this command is working and what data will deliver.
+ * */
+hg_struct hg_paths(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * phase description
+ * */
+int hg_phase(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * pull description
+ * */
+int hg_pull(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * push description
+ * */
+int hg_push(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * recover description
+ * No argument list.
+ * On manual page (http://www.selenic.com/mercurial/hg.1.html#recover), there is
+ * no option for this command.
+ * */
+int hg_recover(hg_handle *handle, int(*callback)(const char *msg, size_t len));
+
+/**
+ * remove description
+ * */
+int hg_remove(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * rename description
+ * */
+int hg_rename(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * resolve function
+ * The resolve function can have prompts.
+ * */
+int hg_resolve(hg_handle *handle, int (*callback)(const char *msg, size_t len),
+               char (*prompt)(const char *msg, size_t len), char *argument[]);
+
+/**
+ * revert description
+ **/
+int hg_revert(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * rollback description
+ **/
+int hg_rollback(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * root description
+ * No argument list.
+ * */
+char *hg_root(hg_handle *handle, int(*callback)(const char *msg, size_t len));
+
+/**
+ * status description
+ * return a list of (code, file path)
+ **/
+hg_tuple *hg_status(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * tag description
+ * return some parse data
+ **/
+hg_tuple *hg_summary(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * tag description
+ **/
+int hg_tag(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+/**
+ * tags description
+ * return a list of tags.
+ **/
+hg_tags_struct *hg_tags(hg_handle *handle, int(*callback)
+                        (const char *msg, size_t len), char *argument[]);
+
+/**
+ * tip description
+ * The return value will be a cset_entry structure (the tip cset will be parse 
+ * and pass to directly to user). If any error occur, the return value will be a
+ * NULL pointer and errno will be set appropiate. 
+ * */
+hg_cset_entry_t *hg_tip(hg_handle *handle, int(*callback)(const char *msg, 
+						size_t len), char *argument[]);
+
+/**
+ * unbandle description
+ **/
+int hg_unbandle(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);				
+							
+/**
+ * update description
+ * Return the number of files (updated, merged, removed, unresolved)
+ **/
+hg_update_entry_t *hg_update(hg_handle *handle, int(*callback)
+                               (const char *msg, size_t len), char *argument[]);
+		
+/**
+ * verify description
+ **/
+hg_verify_entry_t *hg_verify(hg_handle *handle, int(*callback)
+                               (const char *msg, size_t len), char *argument[]);
+					
+/**
+ * version description
+ **/
+char *hg_version(hg_handle *handle, int(*callback)(const char *msg, size_t len),
+							char *argument[]);
+
+#endif