@@ -1032,6 +1032,66 @@
return cbuf;
}
+/* The high level paths command for hglib API. */
+hg_path_entry *hg_paths(hg_handle *handle, int(*callback)(const char *msg,
+ size_t len), char *path_name, int *path_size)
+{
+ int exitcode, i;
+
+ char **command = cmdbuilder("paths", NULL, path_name, NULL);
+
+ if(hg_rawcommand(handle, command) < 0){
+ return NULL;
+ }
+ free(command);
+
+ exitcode = hg_runcommand(handle, callback, NULL);
+
+ if(exitcode){
+ *path_size = -1;
+ return NULL;
+ }
+
+ char *out = get_output_data(handle);
+
+ /* it out is NULL, it means not path is set. */
+ if(out == NULL){
+ *path_size = 0;
+ return NULL;
+ }
+
+ *path_size = number_of_lines(out);
+ char *origin = out;
+ /* if path_name is set, return the url for the path_name*/
+ if(path_name){
+ hg_path_entry *path = malloc(sizeof(hg_path_entry));
+ path[0].pathname = path_name;
+ path[0].url = out;
+
+ out = strstr(out, "\n") + 1;
+ origin[out - origin - 1] = '\0';
+ return path;
+ }
+
+ /* else return a list with all set pats. */
+ hg_path_entry *path = malloc(sizeof(hg_path_entry) * *path_size);
+
+ for(i = 0; i < *path_size; ++i){
+ /* set pathname */
+ path[i].pathname = out;
+ /* skip to '=' char. */
+ out = strstr(out, "=") + 2;
+ /* mark the position */
+ origin[out - origin - 3] = '\0';
+ path[i].url = out;
+
+ out = strstr(out, "\n") + 1;
+ origin[out - origin - 1] = '\0';
+ }
+
+ return path;
+}
+
/* The yield next step. Getting the next entry. */
int hg_fetch_entry(hg_stream_buffer *stream, int (*detect_byte)(char *buff,
int buf_size, int data_on_pipe), int func_type)
@@ -242,6 +242,29 @@
}hg_manifest_entry;
/**
+ * \struct hg_path_entry
+ * \brief This structure will contain information about a path.(pathname, url)
+ *
+ * \var hg_path_entry::pathname
+ * The pathname field will stock the pathname.
+ * \var hg_parth_entry::url
+ * The url field will stock the a url for the repository.
+ *
+ * \typedef hg_path_entry
+ * \brief This structure will contain information about a path.(pathname, url)
+ *
+ * \param pathname
+ * The pathname field will stock the pathname.
+ * \param url
+ * The url field will stock the a url for the repository.
+ *
+ * */
+typedef struct hg_path_entry{
+ char *pathname;
+ char *url;
+}hg_path_entry;
+
+/**
* \struct hg_rev_entry
* \brief This structure will contain revision information about a file.
* (rev:node name)
@@ -1574,6 +1597,35 @@
(const char *msg, size_t len), char *argument[]);
/**
+ * \brief hg_paths command for hglib API.
+ *
+ * Show definition of symbolic path name NAME. If no name is given, show
+ * definition of all available names.
+ *
+ * Option -q/--quiet suppresses all output when searching for NAME and shows
+ * only the path names when listing all definitions.
+ *
+ * Path names are defined in the [paths] section of your configuration file and
+ * in /etc/mercurial/hgrc. If run inside a repository, .hg/hgrc is used, too.
+ *
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param callback A function that will handle error data.
+ * A NULL pointer will ignore error data.
+ * \param path_name Name of symbolic path I want to see.
+ * \param phase_size Address where the array size will be set.
+ * \retval hg_path_entry A list this with all repository paths or the path for
+ * the specific path_name value.
+ * \retval NULL-path_size=0 Succesful, but no path is set.
+ * \retval NULL-path_size=-1 Error, with error set appropriate.
+ *
+ * errno can be:
+ * - hg_rawcommand errors
+ *
+ * */
+hg_path_entry *hg_paths(hg_handle *handle, int(*callback)(const char *msg,
+ size_t len), char *path_name, int *path_size);
+
+/**
* \brief The yield mechanism that will get the next entry.
*
* This function is used inside of hg_fetch_cset_entry() and hg_fetch_line_entry()
@@ -149,3 +149,14 @@
return 0;
}
+
+/*
+ * Count the number of line in the out pointer.
+ * */
+int number_of_lines(char *out)
+{
+ int number = 0;
+ while(out = strstr(out + 1, "\n"), out != NULL)
+ number ++;
+ return number;
+}
@@ -121,5 +121,12 @@
* */
int detect_endline_byte(char *buffer, int buf_size, int data_on_pipe);
+/**
+ * \brief Count the number of line in the out pointer.
+ *
+ * \param out The data pointer.
+ * \retval number The number of lines.
+ * */
+int number_of_lines(char *out);
#endif