[PATCH 2 of 3 RFC -V2] model (1): c-hglib: hg_log() level 1 function

Iulian Stana julian.stana at gmail.com
Tue Aug 20 09:50:55 CDT 2013


> 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, that is build in this commit.
>
> The revision history could have a huge mass of data. To deal with this
> issue, I
> had created a iterator-like mechanism. In this way I will get the
> changesets in
> chunks or more-like one at the time.
>
> The hg_log function will prepare the command and then will call cmd-server
> for
> changesets. This function will return to the user a iterator structure, to
> be
> used on hg_fetch_log_entry funciton. (The log command will not passing any
> changeset to the user)
>
> The hg_fetch_log_entry function will read changesets from command server
> and
> will pass into the hg_log_entry_t structure in a parse way the changeset.
> The hg_log_entry_t structure will be one of the function parameter.
>
> In the main.c file it can be found an example on how this function can be
> used.
>
>

> +#define HGPATH "hg"
> +#define CHANGESET "{rev}\\0{node}\\0{tags}\\0{branch}\\0{author}\\0{desc}\
> +                                               \\0{date|isodate}\\0"
> +
> +/* The high level log command for hglib API. */
> +hg_log_iterator *hg_log(hg_handle *handle, char *option[])
> +{
> +       hg_log_iterator *log_iterator = malloc(sizeof(hg_log_iterator));
> +       log_iterator->handle = handle;
> +
> +       log_iterator->command = cmdbuilder("log", option, CHANGESET);
> +
> +       if(hg_rawcommand(handle, log_iterator->command) < 0){
> +               return NULL;
> +       }
> +
> +       log_iterator->changeset = malloc(0);
> +       return log_iterator;
> +}
> +
> +/* The iterator next step. Getting the next changeset. */
> +int hg_fetch_log_entry(hg_log_iterator *log_iterator, hg_log_entry_t *le)
> +{
> +       hg_header head = hg_head(log_iterator->handle);
> +
> +       if(head.channel == 'r'){
> +               free(log_iterator->command);
> +               free(log_iterator->changeset);
> +               int exitcode = hg_exitcode(log_iterator->handle);
> +               free(log_iterator);
> +               return exitcode;
> +       }
> +
> +       log_iterator->changeset = realloc(log_iterator->changeset,
> head.length + 1);
> +
> +        /* Command server could split a changeset in more shots.
> +           Using a template I will know how to parse the changeset, in
> the end.
> +           First I need to get the entire changeset in one place.
> +        */
> +       if(hg_rawread(log_iterator->handle, log_iterator->changeset,
> +                                       head.length) < 0){
> +               return -1;
> +       }
> +
> +       parse_changeset(log_iterator->changeset, le);
> +
> +       return head.length;
> +}


Let's move the discussion from the other thread over here.


> I believe that the command server is allowed to send data back to you as
>
> 'o', 32, 'changeset:   19527:f37b5a17e6a0\n'
> 'o', 32, 'branch:      stable\ntag:        '
> 'o', 32, ' 2.7\nuser:        Kevin Bullock '
> 'o', 32, '<kbullock at ringworld.org>\ndate:  '
> 'o', 32, '      Thu Aug 01 21:43:14 2013 -'
> 'o', 32, '0500\nsummary:     bookmarks: pul'
> 'o', 32, 'l --update updates to active boo'
> 'o', 29, 'kmark if it moved (issue4007)'
>
>
>if we somehow found out that it was more efficient to buffer data in a
>32 byte buffer before writing it to stdout.

I would really like to know how could I use a template and still receive
data in this way ^_^.

I haven't change this model to much from my last patchbomb, because
I've got some problems in finding a changest.

This is my template :
"{rev}\\0{node}\\0{tags}\\0{branch}\\0{author}\\0{desc}\\0{date|isodate}\\0"
And my parsing process is more like pointing to the right position.

What kind of template could I use to know if where my changeset will
be finish?

The desciption could contain all kind of characters....


-- 
Iulian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130820/bf8a8e3e/attachment.html>


More information about the Mercurial-devel mailing list