[PATCH 28 of 55 RFC c-hglib:level1] hg_import: creating a high level function for mercurial import command

Iulian Stana julian.stana at gmail.com
Fri Sep 13 19:35:40 CDT 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1379112408 -10800
#      Sat Sep 14 01:46:48 2013 +0300
# Node ID a2485c47f38be5505e9fd1ef6cf3fb60eef86a66
# Parent  a952f15026d3945b7a03cf59724e48de7735899c
hg_import: creating a high level function for mercurial import command

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -874,6 +874,23 @@
 	return get_output_data(handle);
 }
 
+/* The high level import command for hglib API. */
+int hg_import(hg_handle *handle, int (*callback)(const char *msg, size_t len),
+		char *(*prompt)(const char *msg, size_t len), char *argument[])
+{
+	int exitcode;
+	char **command = cmdbuilder("import", argument, NULL);
+
+	if(hg_rawcommand(handle, command) < 0){
+		return -1;
+	}
+	free(command);
+
+	exitcode = hg_runcommand(handle, callback, (prompt)? prompt:NULL);
+
+	return exitcode;
+}
+
 /* 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)
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -1189,6 +1189,56 @@
 						size_t len), char *argument[]);
 
 /**
+ * \brief hg_import command for hglib API.
+ *
+ * Import a list of patches and commit them individually (unless --no-commit is
+ * specified).
+ *
+ * Because import first applies changes to the working directory, import will
+ * abort if there are outstanding changes.
+ *
+ * You can import a patch straight from a mail message. Even patches as
+ * attachments work (to use the body part, it must have type text/plain or
+ * text/x-patch). From and Subject headers of email message are used as default
+ * committer and commit message. All text/plain body parts before first diff are
+ * added to commit message.
+ *
+ * Options/Argument list option:
+ *
+ *	-p, --strip	directory strip option for patch. This has the same 
+ *				meaning as the corresponding patch option 
+ *				(default: 1)
+ *	-b, --base		base path (DEPRECATED)
+ *	-e, --edit		invoke editor on commit messages
+ *	-f, --force	skip check for outstanding uncommitted changes 
+ *				(DEPRECATED)
+ *	--no-commit	don't commit, just update the working directory
+ *	--bypass		apply patch without touching the working 
+ *				directory
+ *	--exact		apply patch to the nodes from which it was generated
+ *	--import-branch	use any branch information in patch (implied by --exact)
+ *	-m, --message	use text as commit message
+ *	-l, --logfile	read commit message from file
+ *	-d, --date		record the specified date as commit date
+ *	-u, --user		record the specified user as committer
+ *	-s, --similarity	guess renamed files by similarity (0<=s<=100)
+ *	aliases: patch
+ *
+ * \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 prompt   A function that will handle prompts messages.
+ *                 A NULL pointer will use an abort function.
+ * \param argument The option list. Will contain all option that you wish.
+ * \retval exitcode  To indicate the end of merge_command.
+ *
+ * errno can be:
+ *      - hg_rawcommand errors
+ * */
+int hg_import(hg_handle *handle, int (*callback)(const char *msg, size_t len),
+		char *(*prompt)(const char *msg, size_t len), char *argument[]);
+
+/**
  * \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()


More information about the Mercurial-devel mailing list