Patchwork [06,of,11,c-hglib:level0,V2] hg_rawcommand: send a command to the mercurial command server

login
register
mail settings
Submitter Iulian Stana
Date Sept. 13, 2013, 8:31 p.m.
Message ID <f590a6dd6fe4e6402ba6.1379104316@doppler>
Download mbox | patch
Permalink /patch/2437/
State Deferred, archived
Headers show

Comments

Iulian Stana - Sept. 13, 2013, 8:31 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1379103438 -10800
#      Fri Sep 13 23:17:18 2013 +0300
# Node ID f590a6dd6fe4e6402ba645b7a59ce009780d6fef
# Parent  0296ca1fc1214ad6dd813613ae8280d0ffc96b00
hg_rawcommand: send a command to the mercurial command server

Patch

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -192,3 +192,42 @@ 
 
 	return 0;
 }
+
+/*
+ * Sending a command to the mercurial command server, through the given handle.
+ * */
+int hg_rawcommand(hg_handle *handle, char *const command[])
+{
+	if(!handle) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	if(handle->protect){
+		errno = EPERM;
+		return -1;
+	}
+
+	char runcommand[] = "runcommand\n";
+	int cmd_size = 0;
+	char *cmd_send = cmd_prepare(command, &cmd_size);
+	uint32_t big_endian_size = swap_uint32(cmd_size);
+
+	if(write(handle->p_write, runcommand, strlen(runcommand)) < 0){
+		free(cmd_send);
+		return -1;
+	}
+	if(write(handle->p_write, &big_endian_size, sizeof(uint32_t)) < 0){
+		free(cmd_send);
+		return -1;
+	}
+	if(write(handle->p_write, cmd_send, cmd_size) < 0){
+		free(cmd_send);
+		return -1;
+	}
+
+	free_data(handle);
+	handle->protect = 1;
+	free(cmd_send);
+	return 0;
+}
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -138,4 +138,20 @@ 
  * */
 int hg_close(hg_handle **handle);
 
+/**
+ * \brief Sending a command to the mercurial command server, through the given 
+ *        handle.
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param command An array of pointers to null-terminated strings that represent
+ *                the argument list available to the new command. The list of
+ *                arguments must be terminated by a NULL pointer.
+ * \retval   0 if successful
+ * \retval  -1 to indicate an error, with errno set appropriately.
+ *
+ * errno can be:
+ *      - EINVAL   - Invalid argument ( handle it's set to a null pointer)
+ *      - write(2) command errors
+ * */
+int hg_rawcommand(hg_handle *handle, char *const command[]);
+
 #endif