Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2013-07-24 08:47:33
Size: 392
Editor: ncewpo01-ext
Comment:
Revision 4 as of 2013-07-24 09:09:07
Size: 1489
Editor: ncewpo01-ext
Comment:
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
char buf[4096]; hg_handle *handle; char buf[4096];
hg_handle *handle;
Line 17: Line 18:

Experimenting with the problem domain lead to something different, more like

{{{
while(hg_rawread(handle, buff, 4096)){
        printf("%s", buff);
}

if(hg_channel(handle) == 'r'){
        exitcode = hg_exitcode(handle);
        printf("exitcode = %d\n", exitcode);
}
}}}

Note how the channel type has to be checked before using `hg_rawread`. Moreover, in other usage case, the usage pattern is like

{{{
while(hg_channel(handle) != 'r'){
    if(hg_channel(handle) == 'o'){
        hg_rawread(handle, buff, 4096);
        printf("%s", buff);
    } else if(hg_channel(handle) == 'e'){
        hg_rawread(handle, buff, 4096);
        printf("%s", buff);
    } else if(hg_channel(handle) == 'L'){
        /* ... */
    }
}
}}}

== remarks ==

 * the two usage cases should be made consistent (i.e., wrap `hg_rawread` into a while loop in the second case too)
 * the above usages do not take into account the case where `hg_rawread` return -1 (error).

== attachments ==

IRC conversation about this topic here: http://bpaste.net/show/z2YXazAQti2NFrCp8qFl/

Design document for hg_rawread

Matt outlined the desired beahaviour as

char buf[4096];
hg_handle *handle;

handle = hg_open("some/repo");
hg_rawcommand(handle, "hg log -v");
while(hg_rawread(handle, buf, 4096))
        printf("got: %s", buf); 
printf("exit code is: %d", hg_exitcode(handle)); 
hg_close(handle); 

at http://markmail.org/message/tc6hsvl7fofdjqcl

Experimenting with the problem domain lead to something different, more like

while(hg_rawread(handle, buff, 4096)){
        printf("%s", buff);
}

if(hg_channel(handle) == 'r'){
        exitcode = hg_exitcode(handle);
        printf("exitcode = %d\n", exitcode);
}

Note how the channel type has to be checked before using hg_rawread. Moreover, in other usage case, the usage pattern is like

while(hg_channel(handle) != 'r'){
    if(hg_channel(handle) == 'o'){
        hg_rawread(handle, buff, 4096);
        printf("%s", buff);
    } else if(hg_channel(handle) == 'e'){
        hg_rawread(handle, buff, 4096);
        printf("%s", buff);
    } else if(hg_channel(handle) == 'L'){
        /* ... */
    }
}

remarks

  • the two usage cases should be made consistent (i.e., wrap hg_rawread into a while loop in the second case too)

  • the above usages do not take into account the case where hg_rawread return -1 (error).

attachments

IRC conversation about this topic here: http://bpaste.net/show/z2YXazAQti2NFrCp8qFl/

C-Hglib/hg_rawreadUsageParadigm (last edited 2013-07-24 09:09:07 by ncewpo01-ext)