Submitter | Iulian Stana |
---|---|
Date | Dec. 2, 2013, 7:10 p.m. |
Message ID | <dd12b094d3bb1fd5fd9b.1386011413@doppler> |
Download | mbox | patch |
Permalink | /patch/3200/ |
State | Superseded |
Headers | show |
Comments
:::: diff --git a/README b/README :::: --- a/README :::: +++ b/README :::: @@ -160,6 +160,37 @@ :::: > hg up 0 :::: > echo voodoo > foo ; hg commit -m 'voodoo text' :::: :::: +* Verify example: :::: + :::: +The verify example will use the level 0 implementation and will verify the :::: +given repository. :::: +To compile the binary file you can use the make tool with "examples" target. :::: + > make example :::: + :::: +This action will create an executable file named verify_level0. :::: + :::: +To run this executable, the first argument must be a path to the repository :::: +where you want to import the patch, second argument. :::: + e.g: ./verify_level0 repository_path to be replaced by To run this executable, give the path of a repository as argument. If c-hglib has not been installed system-wide via `make install`, the environment variable LD_LIBRARY_PATH has to be augmented with the path of libhg.so, wich is likely to be the path to c-hglib sources (it's the case if only `make install` has been run). e.g: LD_LIBRARY_PATH=/path/to/c-hglib:$LD_LIBRARY_PATH \ ./verify_level0 repository_path :::: + :::: +To run this example, you can use an existing mercurial repository, :::: +or create a throw-away one just for the example. Here is how :::: +you can create an ad-hoc repository :::: + e.g: :::: + `Repository that it's not corrupt` replace with `Repository that isn't not corrupted` :::: + > hg init tmp :::: + > cd tmp :::: + > touch foo ; hg add foo ; hg commit -m foo :::: + > echo baloo > foo ; hg commit -m 'baloo text' replace above line with the simpler touch bar ; hg add bar ; hg commit -m bar :::: + :::: + `Repository that it's corrupt` replace with `Corrupted repository` :::: + > hg init tmp :::: + > cd tmp :::: + > touch foo ; hg add foo ; hg commit -m foo :::: + > echo baloo > foo ; hg commit -m 'baloo text' remove the above line, it is't necessary. :::: + > rm .hg/store/data/foo.i :::: + :::: + :::: Contact :::: """""""" :::: :::: diff --git a/examples/verify.c b/examples/verify.c :::: new file mode 100644 :::: --- /dev/null :::: +++ b/examples/verify.c :::: @@ -0,0 +1,65 @@ :::: +/* For more details please check the README file from the root directory.*/ :::: +#include <stdio.h> :::: +#include <stdlib.h> :::: +#include <string.h> :::: + :::: +#include "client.h" :::: +#include "utils.h" :::: + :::: +#define BUFF_SIZE 4096 :::: + :::: +/** :::: + * \brief The verify command example. :::: + * :::: + * Will receive data, either from output channel, either from error channel. :::: + * The data is printed on stdout. :::: + * \param handle The handle of the connection, wherewith I want to communicate :::: + * \retval exitcode :::: + * */ :::: +int hg_verify_by_hand(hg_handle *handle) :::: +{ :::: + char *comm[] = {"verify", NULL}; :::: + char buff[BUFF_SIZE]; :::: + int exitcode = 0; :::: + int ns; :::: + :::: + hg_rawcommand(handle, comm); :::: + :::: + hg_header *head; :::: + while (head = hg_read_header(handle), head != NULL && :::: + head->channel != r) { :::: + if (head->channel == o) { :::: + if (ns = hg_rawread(handle, buff, BUFF_SIZE), ns > 0) { :::: + printf("out = %s", buff); :::: + } :::: + } else if (head->channel == e) { :::: + if (ns = hg_rawread(handle, buff, BUFF_SIZE), ns > 0) { :::: + printf("err = %s", buff); :::: + } :::: + } :::: + } :::: + :::: + exitcode = hg_exitcode(handle); :::: + printf("exitcode = %d\n", exitcode); :::: + :::: + return exitcode; :::: +} :::: + :::: +/** :::: + * \brief The main function :::: + * */ :::: +int main(int argc, char **argv) :::: +{ :::: + hg_handle *handle; :::: + :::: + if (argc != 2) { :::: + printf("Usage: %s repository_path\n", argv[0]); :::: + return 1; :::: + } :::: + :::: + handle = hg_open(argv[1], NULL); :::: + hg_verify_by_hand(handle); :::: + hg_close(&handle); :::: + :::: + return 0; :::: +}
Patch
diff --git a/README b/README --- a/README +++ b/README @@ -160,6 +160,37 @@ > hg up 0 > echo voodoo > foo ; hg commit -m 'voodoo text' +* Verify example: + +The verify example will use the level 0 implementation and will verify the +given repository. +To compile the binary file you can use the make tool with "examples" target. + > make example + +This action will create an executable file named verify_level0. + +To run this executable, the first argument must be a path to the repository +where you want to import the patch, second argument. + e.g: ./verify_level0 repository_path + +To run this example, you can use an existing mercurial repository, +or create a throw-away one just for the example. Here is how +you can create an ad-hoc repository + e.g: + `Repository that it's not corrupt` + > hg init tmp + > cd tmp + > touch foo ; hg add foo ; hg commit -m foo + > echo baloo > foo ; hg commit -m 'baloo text' + + `Repository that it's corrupt` + > hg init tmp + > cd tmp + > touch foo ; hg add foo ; hg commit -m foo + > echo baloo > foo ; hg commit -m 'baloo text' + > rm .hg/store/data/foo.i + + Contact """""""" diff --git a/examples/verify.c b/examples/verify.c new file mode 100644 --- /dev/null +++ b/examples/verify.c @@ -0,0 +1,65 @@ +/* For more details please check the README file from the root directory.*/ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "client.h" +#include "utils.h" + +#define BUFF_SIZE 4096 + +/** + * \brief The verify command example. + * + * Will receive data, either from output channel, either from error channel. + * The data is printed on stdout. + * \param handle The handle of the connection, wherewith I want to communicate + * \retval exitcode + * */ +int hg_verify_by_hand(hg_handle *handle) +{ + char *comm[] = {"verify", NULL}; + char buff[BUFF_SIZE]; + int exitcode = 0; + int ns; + + hg_rawcommand(handle, comm); + + hg_header *head; + while (head = hg_read_header(handle), head != NULL && + head->channel != r) { + if (head->channel == o) { + if (ns = hg_rawread(handle, buff, BUFF_SIZE), ns > 0) { + printf("out = %s", buff); + } + } else if (head->channel == e) { + if (ns = hg_rawread(handle, buff, BUFF_SIZE), ns > 0) { + printf("err = %s", buff); + } + } + } + + exitcode = hg_exitcode(handle); + printf("exitcode = %d\n", exitcode); + + return exitcode; +} + +/** + * \brief The main function + * */ +int main(int argc, char **argv) +{ + hg_handle *handle; + + if (argc != 2) { + printf("Usage: %s repository_path\n", argv[0]); + return 1; + } + + handle = hg_open(argv[1], NULL); + hg_verify_by_hand(handle); + hg_close(&handle); + + return 0; +}