* [PATCH 1/4] sequencer: add "builtin-sequencer--helper.c"
2009-06-26 21:08 [PATCH 0/4] start using sequencer code to port "rebase -i" Christian Couder
@ 2009-06-26 21:08 ` Christian Couder
2009-06-26 21:08 ` [PATCH 2/4] sequencer: add "make_patch" function to save a patch Christian Couder
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Christian Couder @ 2009-06-26 21:08 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Johannes Schindelin, Stephan Beyer, Daniel Barkalow,
Jakub Narebski
This a helper builtin that will be used to port some parts of
"git-rebase--interactive.sh" to C.
It currently does nothing except checking arguments it is passed.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
.gitignore | 1 +
Makefile | 1 +
builtin-sequencer--helper.c | 27 +++++++++++++++++++++++++++
builtin.h | 1 +
git.c | 1 +
5 files changed, 31 insertions(+), 0 deletions(-)
create mode 100644 builtin-sequencer--helper.c
diff --git a/.gitignore b/.gitignore
index 04926fc..98711c3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -117,6 +117,7 @@ git-revert
git-rm
git-send-email
git-send-pack
+git-sequencer--helper
git-sh-setup
git-shell
git-shortlog
diff --git a/Makefile b/Makefile
index 4e8f45d..10bb7f5 100644
--- a/Makefile
+++ b/Makefile
@@ -632,6 +632,7 @@ BUILTIN_OBJS += builtin-rev-parse.o
BUILTIN_OBJS += builtin-revert.o
BUILTIN_OBJS += builtin-rm.o
BUILTIN_OBJS += builtin-send-pack.o
+BUILTIN_OBJS += builtin-sequencer--helper.o
BUILTIN_OBJS += builtin-shortlog.o
BUILTIN_OBJS += builtin-show-branch.o
BUILTIN_OBJS += builtin-show-ref.o
diff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c
new file mode 100644
index 0000000..721c0d8
--- /dev/null
+++ b/builtin-sequencer--helper.c
@@ -0,0 +1,27 @@
+#include "builtin.h"
+#include "cache.h"
+#include "parse-options.h"
+
+static const char * const git_sequencer_helper_usage[] = {
+ "git sequencer--helper --make-patch <commit>",
+ NULL
+};
+
+int cmd_sequencer__helper(int argc, const char **argv, const char *prefix)
+{
+ char *commit = NULL;
+ struct option options[] = {
+ OPT_STRING(0, "make-patch", &commit, "commit",
+ "create a patch from commit"),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, prefix, options,
+ git_sequencer_helper_usage, 0);
+
+ if (!commit)
+ usage_with_options(git_sequencer_helper_usage, options);
+
+ /* Nothing to do yet */
+ return 0;
+}
diff --git a/builtin.h b/builtin.h
index 38ceddc..d181669 100644
--- a/builtin.h
+++ b/builtin.h
@@ -92,6 +92,7 @@ extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
extern int cmd_revert(int argc, const char **argv, const char *prefix);
extern int cmd_rm(int argc, const char **argv, const char *prefix);
extern int cmd_send_pack(int argc, const char **argv, const char *prefix);
+extern int cmd_sequencer__helper(int argc, const char **argv, const char *prefix);
extern int cmd_shortlog(int argc, const char **argv, const char *prefix);
extern int cmd_show(int argc, const char **argv, const char *prefix);
extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
diff --git a/git.c b/git.c
index 479279b..3e4b4ad 100644
--- a/git.c
+++ b/git.c
@@ -349,6 +349,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
{ "rm", cmd_rm, RUN_SETUP },
{ "send-pack", cmd_send_pack, RUN_SETUP },
+ { "sequencer--helper", cmd_sequencer__helper, RUN_SETUP | NEED_WORK_TREE },
{ "shortlog", cmd_shortlog, USE_PAGER },
{ "show-branch", cmd_show_branch, RUN_SETUP },
{ "show", cmd_show, RUN_SETUP | USE_PAGER },
--
1.6.3.GIT
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/4] sequencer: add "make_patch" function to save a patch
2009-06-26 21:08 [PATCH 0/4] start using sequencer code to port "rebase -i" Christian Couder
2009-06-26 21:08 ` [PATCH 1/4] sequencer: add "builtin-sequencer--helper.c" Christian Couder
@ 2009-06-26 21:08 ` Christian Couder
2009-06-28 12:13 ` Christian Couder
2009-06-26 21:08 ` [PATCH 3/4] sequencer: free memory used in "make_patch" function Christian Couder
2009-06-26 21:08 ` [PATCH 4/4] rebase -i: use "git sequencer--helper --make-patch" Christian Couder
3 siblings, 1 reply; 6+ messages in thread
From: Christian Couder @ 2009-06-26 21:08 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Johannes Schindelin, Stephan Beyer, Daniel Barkalow,
Jakub Narebski
This function generates an informational patch file.
The "make_patch" and the "get_commit" functions are copied from the
GSoC sequencer project:
git://repo.or.cz/git/sbeyer.git
(commit e7b8dab0c2a73ade92017a52bb1405ea1534ef20)
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-sequencer--helper.c | 75 ++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 74 insertions(+), 1 deletions(-)
diff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c
index 721c0d8..8d32480 100644
--- a/builtin-sequencer--helper.c
+++ b/builtin-sequencer--helper.c
@@ -1,15 +1,83 @@
#include "builtin.h"
#include "cache.h"
#include "parse-options.h"
+#include "run-command.h"
+
+#define SEQ_DIR "rebase-merge"
+
+#define PATCH_FILE git_path(SEQ_DIR "/patch")
static const char * const git_sequencer_helper_usage[] = {
"git sequencer--helper --make-patch <commit>",
NULL
};
+/* Generate purely informational patch file */
+static void make_patch(struct commit *commit)
+{
+ struct commit_list *parents = commit->parents;
+ const char **args;
+ struct child_process chld;
+ int fd = open(PATCH_FILE, O_WRONLY | O_CREAT, 0666);
+ if (fd < 0)
+ return;
+
+ memset(&chld, 0, sizeof(chld));
+ if (!parents) {
+ write(fd, "Root commit\n", 12);
+ close(fd);
+ return;
+ } else if (!parents->next) {
+ args = xcalloc(5, sizeof(char *));
+ args[0] = "diff-tree";
+ args[1] = "-p";
+ args[2] = xstrdup(sha1_to_hex(parents->item->object.sha1));
+ args[3] = xstrdup(sha1_to_hex(((struct object *)commit)->sha1));
+ } else {
+ int i = 0;
+ int count = 1;
+
+ for (; parents; parents = parents->next)
+ ++count;
+ args = xcalloc(count + 3, sizeof(char *));
+ args[i++] = "diff";
+ args[i++] = "--cc";
+ args[i++] = xstrdup(sha1_to_hex(commit->object.sha1));
+
+ for (parents = commit->parents; parents;
+ parents = parents->next)
+ args[i++] = xstrdup(sha1_to_hex(
+ parents->item->object.sha1));
+ }
+
+ chld.argv = args;
+ chld.git_cmd = 1;
+ chld.out = fd;
+
+ /* Run, ignore errors. */
+ if (start_command(&chld))
+ return;
+ finish_command(&chld);
+
+ /* TODO: free dup'ed SHAs in argument list */
+}
+
+/* Return a commit object of "arg" */
+static struct commit *get_commit(const char *arg)
+{
+ unsigned char sha1[20];
+
+ if (get_sha1(arg, sha1)) {
+ error("Could not find '%s'", arg);
+ return NULL;
+ }
+ return lookup_commit_reference(sha1);
+}
+
int cmd_sequencer__helper(int argc, const char **argv, const char *prefix)
{
char *commit = NULL;
+ struct commit *c;
struct option options[] = {
OPT_STRING(0, "make-patch", &commit, "commit",
"create a patch from commit"),
@@ -22,6 +90,11 @@ int cmd_sequencer__helper(int argc, const char **argv, const char *prefix)
if (!commit)
usage_with_options(git_sequencer_helper_usage, options);
- /* Nothing to do yet */
+ c = get_commit(commit);
+ if (!c)
+ return 1;
+
+ make_patch(c);
+
return 0;
}
--
1.6.3.GIT
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/4] sequencer: free memory used in "make_patch" function
2009-06-26 21:08 [PATCH 0/4] start using sequencer code to port "rebase -i" Christian Couder
2009-06-26 21:08 ` [PATCH 1/4] sequencer: add "builtin-sequencer--helper.c" Christian Couder
2009-06-26 21:08 ` [PATCH 2/4] sequencer: add "make_patch" function to save a patch Christian Couder
@ 2009-06-26 21:08 ` Christian Couder
2009-06-26 21:08 ` [PATCH 4/4] rebase -i: use "git sequencer--helper --make-patch" Christian Couder
3 siblings, 0 replies; 6+ messages in thread
From: Christian Couder @ 2009-06-26 21:08 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Johannes Schindelin, Stephan Beyer, Daniel Barkalow,
Jakub Narebski
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-sequencer--helper.c | 20 ++++++++++++--------
1 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/builtin-sequencer--helper.c b/builtin-sequencer--helper.c
index 8d32480..1dda525 100644
--- a/builtin-sequencer--helper.c
+++ b/builtin-sequencer--helper.c
@@ -18,6 +18,7 @@ static void make_patch(struct commit *commit)
struct commit_list *parents = commit->parents;
const char **args;
struct child_process chld;
+ int i;
int fd = open(PATCH_FILE, O_WRONLY | O_CREAT, 0666);
if (fd < 0)
return;
@@ -34,20 +35,22 @@ static void make_patch(struct commit *commit)
args[2] = xstrdup(sha1_to_hex(parents->item->object.sha1));
args[3] = xstrdup(sha1_to_hex(((struct object *)commit)->sha1));
} else {
- int i = 0;
int count = 1;
for (; parents; parents = parents->next)
++count;
+
+ i = 0;
args = xcalloc(count + 3, sizeof(char *));
args[i++] = "diff";
args[i++] = "--cc";
args[i++] = xstrdup(sha1_to_hex(commit->object.sha1));
for (parents = commit->parents; parents;
- parents = parents->next)
- args[i++] = xstrdup(sha1_to_hex(
- parents->item->object.sha1));
+ parents = parents->next) {
+ char *hex = sha1_to_hex(parents->item->object.sha1);
+ args[i++] = xstrdup(hex);
+ }
}
chld.argv = args;
@@ -55,11 +58,12 @@ static void make_patch(struct commit *commit)
chld.out = fd;
/* Run, ignore errors. */
- if (start_command(&chld))
- return;
- finish_command(&chld);
+ if (!start_command(&chld))
+ finish_command(&chld);
- /* TODO: free dup'ed SHAs in argument list */
+ for (i = 2; args[i]; i++)
+ free((char *)args[i]);
+ free(args);
}
/* Return a commit object of "arg" */
--
1.6.3.GIT
^ permalink raw reply related [flat|nested] 6+ messages in thread