Skip to contentSkip to conversation

Make git-update-ref a builtin

PATCH In review Shawn Pearce 2 participants 9 messages Jun 15, 2016 1 message not in the archive Kbuild

lore
Share & tools
lore
#1 lore raw

PATCH 1/8 Make git-write-tree a builtin

In reply to a message not in the archive
---
 Makefile                             |    6 ++-
 write-tree.c => builtin-write-tree.c |   68 +++++++++++++++++++++-------------
 builtin.h                            |    3 ++
 git.c                                |    3 +-
 4 files changed, 50 insertions(+), 30 deletions(-)
Makefile +3 -3
index 2a1e639..37b5e40 100644
@@ -159,7 +159,7 @@ PROGRAMS = \
 	git-show-index$X git-ssh-fetch$X \
 	git-ssh-upload$X git-unpack-file$X \
 	git-unpack-objects$X git-update-index$X git-update-server-info$X \
-	git-upload-pack$X git-verify-pack$X git-write-tree$X \
+	git-upload-pack$X git-verify-pack$X \
 	git-update-ref$X git-symbolic-ref$X \
 	git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
 	git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
@@ -170,7 +170,7 @@ BUILT_INS = git-log$X git-whatchanged$X 
 	git-check-ref-format$X git-rev-parse$X \
 	git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
 	git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
-	git-read-tree$X git-commit-tree$X \
+	git-read-tree$X git-commit-tree$X git-write-tree$X \
 	git-apply$X git-show-branch$X git-diff-files$X \
 	git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
 
@@ -223,7 +223,7 @@ BUILTIN_OBJS = \
 	builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
 	builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
 	builtin-tar-tree.o builtin-upload-tar.o \
-	builtin-ls-files.o builtin-ls-tree.o \
+	builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
 	builtin-read-tree.o builtin-commit-tree.o \
 	builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
 	builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
builtin-write-tree.c renamed from write-tree.c +42 -26

108 lines not on this page · raw message

builtin.h +3 -0
index b9f36be..885422e 100644
@@ -46,4 +46,7 @@ extern int cmd_diff_tree(int argc, const
 extern int cmd_cat_file(int argc, const char **argv, char **envp);
 extern int cmd_rev_parse(int argc, const char **argv, char **envp);
 
+extern int cmd_write_tree(int argc, const char **argv, char **envp);
+extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
+
 #endif
git.c +2 -1
index 9469d44..5868fb9 100644
@@ -178,7 +178,8 @@ static void handle_internal_command(int 
 		{ "diff-stages", cmd_diff_stages },
 		{ "diff-tree", cmd_diff_tree },
 		{ "cat-file", cmd_cat_file },
-		{ "rev-parse", cmd_rev_parse }
+		{ "rev-parse", cmd_rev_parse },
+		{ "write-tree", cmd_write_tree }
 	};
 	int i;
 
Signature · 1 line
1.4.0
#2 lore raw

PATCH 2/8 Make git-mailsplit a builtin

In reply to a message not in the archive
---
 Makefile                           |    5 +--
 mailsplit.c => builtin-mailsplit.c |   71 +++++++++++++++++++++---------------
 builtin.h                          |    2 +
 git.c                              |    3 +-
 4 files changed, 48 insertions(+), 33 deletions(-)
Makefile +2 -3
index 37b5e40..7bee30d 100644
@@ -144,7 +144,6 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)
 
 # The ones that do not have to link with lcrypto, lz nor xdiff.
 SIMPLE_PROGRAMS = \
-	git-mailsplit$X \
 	git-stripspace$X git-daemon$X
 
 # ... and all the rest that could be moved out of bindir to gitexecdir
@@ -165,7 +164,7 @@ PROGRAMS = \
 	git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
 
 BUILT_INS = git-log$X git-whatchanged$X git-show$X \
-	git-count-objects$X git-diff$X git-push$X \
+	git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
 	git-grep$X git-add$X git-rm$X git-rev-list$X \
 	git-check-ref-format$X git-rev-parse$X \
 	git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
@@ -227,7 +226,7 @@ BUILTIN_OBJS = \
 	builtin-read-tree.o builtin-commit-tree.o \
 	builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
 	builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
-	builtin-cat-file.o
+	builtin-cat-file.o builtin-mailsplit.o
 
 GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
 LIBS = $(GITLIBS) -lz
builtin-mailsplit.c renamed from mailsplit.c +42 -29

93 lines not on this page · raw message

builtin.h +2 -0
index 885422e..92e1e1b 100644
@@ -49,4 +49,6 @@ extern int cmd_rev_parse(int argc, const
 extern int cmd_write_tree(int argc, const char **argv, char **envp);
 extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
 
+extern int cmd_mailsplit(int argc, const char **argv, char **envp);
+extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
 #endif
git.c +2 -1
index 5868fb9..3264c65 100644
@@ -179,7 +179,8 @@ static void handle_internal_command(int 
 		{ "diff-tree", cmd_diff_tree },
 		{ "cat-file", cmd_cat_file },
 		{ "rev-parse", cmd_rev_parse },
-		{ "write-tree", cmd_write_tree }
+		{ "write-tree", cmd_write_tree },
+		{ "mailsplit", cmd_mailsplit }
 	};
 	int i;
 
Signature · 1 line
1.4.0
#3 lore raw

PATCH 3/8 Make git-mailinfo a builtin

In reply to a message not in the archive
---
 Makefile                         |   12 ++---
 mailinfo.c => builtin-mailinfo.c |   85 ++++++++++++++++++++++----------------
 builtin.h                        |    6 +++
 git.c                            |    3 +
 4 files changed, 62 insertions(+), 44 deletions(-)
Makefile +4 -8
index 7bee30d..e64d943 100644
@@ -151,7 +151,7 @@ PROGRAMS = \
 	git-checkout-index$X git-clone-pack$X \
 	git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
 	git-hash-object$X git-index-pack$X git-local-fetch$X \
-	git-mailinfo$X git-merge-base$X \
+	git-merge-base$X \
 	git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \
 	git-peek-remote$X git-prune-packed$X git-receive-pack$X \
 	git-send-pack$X git-shell$X \
@@ -166,7 +166,7 @@ PROGRAMS = \
 BUILT_INS = git-log$X git-whatchanged$X git-show$X \
 	git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
 	git-grep$X git-add$X git-rm$X git-rev-list$X \
-	git-check-ref-format$X git-rev-parse$X \
+	git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
 	git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
 	git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
 	git-read-tree$X git-commit-tree$X git-write-tree$X \
@@ -223,7 +223,7 @@ BUILTIN_OBJS = \
 	builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
 	builtin-tar-tree.o builtin-upload-tar.o \
 	builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
-	builtin-read-tree.o builtin-commit-tree.o \
+	builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
 	builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
 	builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
 	builtin-cat-file.o builtin-mailsplit.o
@@ -486,7 +486,7 @@ strip: $(PROGRAMS) git$X
 git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS)
 	$(CC) -DGIT_VERSION='"$(GIT_VERSION)"' \
 		$(ALL_CFLAGS) -o $@ $(filter %.c,$^) \
-		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
+		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) $(LIB_4_ICONV)
 
 builtin-help.o: common-cmds.h
 
@@ -563,10 +563,6 @@ git-%$X: %.o $(GITLIBS)
 	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(LIB_FILE) $(SIMPLE_LIB)
 
-git-mailinfo$X: mailinfo.o $(LIB_FILE)
-	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
-		$(LIB_FILE) $(SIMPLE_LIB) $(LIB_4_ICONV)
-
 git-local-fetch$X: fetch.o
 git-ssh-fetch$X: rsh.o fetch.o
 git-ssh-upload$X: rsh.o
builtin-mailinfo.c renamed from mailinfo.c +50 -35

163 lines not on this page · raw message

builtin.h +6 -0
index 92e1e1b..979e0cd 100644
@@ -1,6 +1,8 @@
 #ifndef BUILTIN_H
 #define BUILTIN_H
 
+#include <stdio.h>
+
 #ifndef PATH_MAX
 # define PATH_MAX 4096
 #endif
@@ -51,4 +53,8 @@ extern int write_tree(unsigned char *sha
 
 extern int cmd_mailsplit(int argc, const char **argv, char **envp);
 extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
+
+extern int cmd_mailinfo(int argc, const char **argv, char **envp);
+extern int mailinfo(FILE *in, FILE *out, int ks, char *encoding,
+		    const char *msg, const char *patch);
 #endif
git.c +2 -1
index 3264c65..1e216de 100644
@@ -180,7 +180,8 @@ static void handle_internal_command(int 
 		{ "cat-file", cmd_cat_file },
 		{ "rev-parse", cmd_rev_parse },
 		{ "write-tree", cmd_write_tree },
-		{ "mailsplit", cmd_mailsplit }
+		{ "mailsplit", cmd_mailsplit },
+		{ "mailinfo", cmd_mailinfo }
 	};
 	int i;
 
Signature · 1 line
1.4.0
#4 lore raw

PATCH 4/8 Make git-stripspace a builtin

In reply to a message not in the archive
---
 Makefile                             |    6 +++---
 stripspace.c => builtin-stripspace.c |   16 +++++++++++-----
 builtin.h                            |    6 ++++--
 git.c                                |    3 ++-
 4 files changed, 20 insertions(+), 11 deletions(-)
Makefile +3 -3
index e64d943..181255f 100644
@@ -144,7 +144,7 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)
 
 # The ones that do not have to link with lcrypto, lz nor xdiff.
 SIMPLE_PROGRAMS = \
-	git-stripspace$X git-daemon$X
+	git-daemon$X
 
 # ... and all the rest that could be moved out of bindir to gitexecdir
 PROGRAMS = \
@@ -165,7 +165,7 @@ PROGRAMS = \
 
 BUILT_INS = git-log$X git-whatchanged$X git-show$X \
 	git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
-	git-grep$X git-add$X git-rm$X git-rev-list$X \
+	git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
 	git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
 	git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
 	git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
@@ -226,7 +226,7 @@ BUILTIN_OBJS = \
 	builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
 	builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
 	builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
-	builtin-cat-file.o builtin-mailsplit.o
+	builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o
 
 GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
 LIBS = $(GITLIBS) -lz
builtin-stripspace.c renamed from stripspace.c +11 -5
similarity index 76%
rename from stripspace.c
rename to builtin-stripspace.c
index 65a6346..2ce1264 100644
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
+#include "builtin.h"
 
 /*
  * Remove empty lines from the beginning and end.
@@ -28,21 +29,21 @@ static int cleanup(char *line)
 	return 1;
 }
 
-int main(int argc, char **argv)
+void stripspace(FILE *in, FILE *out)
 {
 	int empties = -1;
 	int incomplete = 0;
 	char line[1024];
 
-	while (fgets(line, sizeof(line), stdin)) {
+	while (fgets(line, sizeof(line), in)) {
 		incomplete = cleanup(line);
 
 		/* Not just an empty line? */
 		if (line[0] != '\n') {
 			if (empties > 0)
-				putchar('\n');
+				fputc('\n', out);
 			empties = 0;
-			fputs(line, stdout);
+			fputs(line, out);
 			continue;
 		}
 		if (empties < 0)
@@ -50,6 +51,11 @@ int main(int argc, char **argv)
 		empties++;
 	}
 	if (incomplete)
-		putchar('\n');
+		fputc('\n', out);
+}
+
+int cmd_stripspace(int argc, const char **argv, char **envp)
+{
+	stripspace(stdin, stdout);
 	return 0;
 }
builtin.h +4 -2
index 979e0cd..c934d7a 100644
@@ -55,6 +55,8 @@ extern int cmd_mailsplit(int argc, const
 extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
 
 extern int cmd_mailinfo(int argc, const char **argv, char **envp);
-extern int mailinfo(FILE *in, FILE *out, int ks, char *encoding,
-		    const char *msg, const char *patch);
+extern int mailinfo(FILE *in, FILE *out, int ks, char *encoding, const char *msg, const char *patch);
+
+extern int cmd_stripspace(int argc, const char **argv, char **envp);
+extern void stripspace(FILE *in, FILE *out);
 #endif
git.c +2 -1
index 1e216de..31196f5 100644
@@ -181,7 +181,8 @@ static void handle_internal_command(int 
 		{ "rev-parse", cmd_rev_parse },
 		{ "write-tree", cmd_write_tree },
 		{ "mailsplit", cmd_mailsplit },
-		{ "mailinfo", cmd_mailinfo }
+		{ "mailinfo", cmd_mailinfo },
+		{ "stripspace", cmd_stripspace }
 	};
 	int i;
 
Signature · 1 line
1.4.0
#5 lore raw

PATCH 5/8 Make git-update-index a builtin

In reply to a message not in the archive
---
 Makefile                                 |    6 +++---
 update-index.c => builtin-update-index.c |   19 ++++++++++++-------
 builtin.h                                |    1 +
 git.c                                    |    3 ++-
 4 files changed, 18 insertions(+), 11 deletions(-)
Makefile +3 -3
index 181255f..906fc0f 100644
@@ -157,7 +157,7 @@ PROGRAMS = \
 	git-send-pack$X git-shell$X \
 	git-show-index$X git-ssh-fetch$X \
 	git-ssh-upload$X git-unpack-file$X \
-	git-unpack-objects$X git-update-index$X git-update-server-info$X \
+	git-unpack-objects$X git-update-server-info$X \
 	git-upload-pack$X git-verify-pack$X \
 	git-update-ref$X git-symbolic-ref$X \
 	git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
@@ -170,7 +170,7 @@ BUILT_INS = git-log$X git-whatchanged$X 
 	git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
 	git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
 	git-read-tree$X git-commit-tree$X git-write-tree$X \
-	git-apply$X git-show-branch$X git-diff-files$X \
+	git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \
 	git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
 
 # what 'all' will build and 'install' will install, in gitexecdir
@@ -221,7 +221,7 @@ BUILTIN_OBJS = \
 	builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
 	builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
 	builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
-	builtin-tar-tree.o builtin-upload-tar.o \
+	builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \
 	builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
 	builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
 	builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
builtin-update-index.c renamed from update-index.c +12 -7
similarity index 97%
rename from update-index.c
rename to builtin-update-index.c
index fbccc4a..325cd09 100644
@@ -8,6 +8,7 @@ #include "strbuf.h"
 #include "quote.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
+#include "builtin.h"
 
 /*
  * Default to not allowing changes to the list of files. The
@@ -186,8 +187,6 @@ static void chmod_path(int flip, const c
 	die("git-update-index: cannot chmod %cx '%s'", flip, path);
 }
 
-static struct lock_file lock_file;
-
 static void update_one(const char *path, const char *prefix, int prefix_length)
 {
 	const char *p = prefix_path(prefix, prefix_length, path);
@@ -238,7 +237,7 @@ static void read_index_info(int line_ter
 		 * (2) mode SP type SP sha1          TAB path
 		 * The second format is to stuff git-ls-tree output
 		 * into the index file.
-		 * 
+		 *
 		 * (3) mode         SP sha1 SP stage TAB path
 		 * This format is to put higher order stages into the
 		 * index file and matches git-ls-files --stage output.
@@ -477,7 +476,7 @@ static int do_reupdate(int ac, const cha
 	return 0;
 }
 
-int main(int argc, const char **argv)
+int cmd_update_index(int argc, const char **argv, char **envp)
 {
 	int i, newfd, entries, has_errors = 0, line_termination = '\n';
 	int allow_options = 1;
@@ -486,12 +485,16 @@ int main(int argc, const char **argv)
 	int prefix_length = prefix ? strlen(prefix) : 0;
 	char set_executable_bit = 0;
 	unsigned int refresh_flags = 0;
+	struct lock_file *lock_file;
 
 	git_config(git_default_config);
 
-	newfd = hold_lock_file_for_update(&lock_file, get_index_file());
+	/* We can't free this memory, it becomes part of a linked list parsed atexit() */
+	lock_file = xmalloc(sizeof(struct lock_file));
+
+	newfd = hold_lock_file_for_update(lock_file, get_index_file());
 	if (newfd < 0)
-		die("unable to create new index file");
+		die("unable to create new cachefile");
 
 	entries = read_cache();
 	if (entries < 0)
@@ -645,9 +648,11 @@ int main(int argc, const char **argv)
  finish:
 	if (active_cache_changed) {
 		if (write_cache(newfd, active_cache, active_nr) ||
-		    commit_lock_file(&lock_file))
+		    commit_lock_file(lock_file))
 			die("Unable to write new index file");
 	}
 
+	rollback_lock_file(lock_file);
+
 	return has_errors ? 1 : 0;
 }
builtin.h +1 -0
index c934d7a..9ee5ea6 100644
@@ -47,6 +47,7 @@ extern int cmd_diff_stages(int argc, con
 extern int cmd_diff_tree(int argc, const char **argv, char **envp);
 extern int cmd_cat_file(int argc, const char **argv, char **envp);
 extern int cmd_rev_parse(int argc, const char **argv, char **envp);
+extern int cmd_update_index(int argc, const char **argv, char **envp);
 
 extern int cmd_write_tree(int argc, const char **argv, char **envp);
 extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
git.c +2 -1
index 31196f5..4a931fb 100644
@@ -182,7 +182,8 @@ static void handle_internal_command(int 
 		{ "write-tree", cmd_write_tree },
 		{ "mailsplit", cmd_mailsplit },
 		{ "mailinfo", cmd_mailinfo },
-		{ "stripspace", cmd_stripspace }
+		{ "stripspace", cmd_stripspace },
+		{ "update-index", cmd_update_index }
 	};
 	int i;
 
Signature · 1 line
1.4.0
#6 lore raw

PATCH 6/8 Make git-update-ref a builtin

In reply to a message not in the archive
---
 Makefile                             |    7 ++++---
 update-ref.c => builtin-update-ref.c |    5 ++++-
 builtin.h                            |    1 +
 git.c                                |    3 ++-
 4 files changed, 11 insertions(+), 5 deletions(-)
Makefile +4 -3
index 906fc0f..4b30ca0 100644
@@ -159,11 +159,11 @@ PROGRAMS = \
 	git-ssh-upload$X git-unpack-file$X \
 	git-unpack-objects$X git-update-server-info$X \
 	git-upload-pack$X git-verify-pack$X \
-	git-update-ref$X git-symbolic-ref$X \
+	git-symbolic-ref$X \
 	git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
 	git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
 
-BUILT_INS = git-log$X git-whatchanged$X git-show$X \
+BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
 	git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
 	git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
 	git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
@@ -226,7 +226,8 @@ BUILTIN_OBJS = \
 	builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
 	builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
 	builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
-	builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o
+	builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \
+	builtin-update-ref.o
 
 GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
 LIBS = $(GITLIBS) -lz
builtin-update-ref.c renamed from update-ref.c +4 -1
similarity index 89%
rename from update-ref.c
rename to builtin-update-ref.c
index a1e6bb9..00333c7 100644
@@ -1,10 +1,11 @@
 #include "cache.h"
 #include "refs.h"
+#include "builtin.h"
 
 static const char git_update_ref_usage[] =
 "git-update-ref <refname> <value> [<oldval>] [-m <reason>]";
 
-int main(int argc, char **argv)
+int cmd_update_ref(int argc, const char **argv, char **envp)
 {
 	const char *refname=NULL, *value=NULL, *oldval=NULL, *msg=NULL;
 	struct ref_lock *lock;
@@ -52,5 +53,7 @@ int main(int argc, char **argv)
 		return 1;
 	if (write_ref_sha1(lock, sha1, msg) < 0)
 		return 1;
+
+	/* write_ref_sha1 always unlocks the ref, no need to do it explicitly */
 	return 0;
 }
builtin.h +1 -0
index 9ee5ea6..c1f3395 100644
@@ -48,6 +48,7 @@ extern int cmd_diff_tree(int argc, const
 extern int cmd_cat_file(int argc, const char **argv, char **envp);
 extern int cmd_rev_parse(int argc, const char **argv, char **envp);
 extern int cmd_update_index(int argc, const char **argv, char **envp);
+extern int cmd_update_ref(int argc, const char **argv, char **envp);
 
 extern int cmd_write_tree(int argc, const char **argv, char **envp);
 extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
git.c +2 -1
index 4a931fb..652e3c4 100644
@@ -183,7 +183,8 @@ static void handle_internal_command(int 
 		{ "mailsplit", cmd_mailsplit },
 		{ "mailinfo", cmd_mailinfo },
 		{ "stripspace", cmd_stripspace },
-		{ "update-index", cmd_update_index }
+		{ "update-index", cmd_update_index },
+		{ "update-ref", cmd_update_ref }
 	};
 	int i;
 
Signature · 1 line
1.4.0
#7 lore raw
Quoted 7 lines · Lukas Sandstr?m
---
 Makefile                             |    7 ++++---
 update-ref.c => builtin-update-ref.c |    5 ++++-
 builtin.h                            |    1 +
 git.c                                |    3 ++-
 4 files changed, 11 insertions(+), 5 deletions(-)

Thanks for doing this. I know I had written this change and I was pretty sure I had sent it to Junio a while ago but I guess it got lost in the shuffle and I just failed to follow through with it when it didn't show up in next.

Signature · 1 line
Shawn.
#8 lore raw

PATCH 7/8 Make it possible to call cmd_apply multiple times

In reply to a message not in the archive

* xmalloc a new struct lock_file each invocation.
* Don't die() if the patch doesn't apply.
* Initialize the global variables each invocation.
* Roll back the lock_file.

---
 builtin-apply.c |   94 +++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 60 insertions(+), 34 deletions(-)
builtin-apply.c +60 -34
index e113c74..a76c553 100644
@@ -22,24 +22,13 @@ #include "builtin.h"
 //  --index updates the cache as well.
 //  --cached updates only the cache without ever touching the working tree.
 //
-static const char *prefix;
-static int prefix_length = -1;
-static int newfd = -1;
-
-static int p_value = 1;
-static int allow_binary_replacement = 0;
-static int check_index = 0;
-static int write_index = 0;
-static int cached = 0;
-static int diffstat = 0;
-static int numstat = 0;
-static int summary = 0;
-static int check = 0;
-static int apply = 1;
-static int no_add = 0;
-static int show_index_info = 0;
-static int line_termination = '\n';
+static const char *prefix, *patch_input_file;
+static int prefix_length, newfd, p_value, allow_binary_replacement, check_index,
+	write_index, cached, diffstat, numstat, summary, check, apply, no_add,
+	show_index_info, line_termination, whitespace_error, squelch_whitespace_errors,
+	applied_after_stripping;
 static unsigned long p_context = -1;
+
 static const char apply_usage[] =
 "git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|error|error-all|strip>] <patch>...";
 
@@ -49,10 +38,31 @@ static enum whitespace_eol {
 	error_on_whitespace,
 	strip_whitespace,
 } new_whitespace = warn_on_whitespace;
-static int whitespace_error = 0;
-static int squelch_whitespace_errors = 5;
-static int applied_after_stripping = 0;
-static const char *patch_input_file = NULL;
+
+static void setup_state()
+{
+	prefix = NULL;
+	prefix_length = -1;
+	newfd = -1;
+	p_value = 1;
+	allow_binary_replacement = 0;
+	check_index = 0;
+	write_index = 0;
+	cached = 0;
+	diffstat = 0;
+	numstat = 0;
+	summary = 0;
+	check = 0;
+	apply = 1;
+	no_add = 0;
+	show_index_info = 0;
+	line_termination = '\n';
+	p_context = -1;
+	whitespace_error = 0;
+	squelch_whitespace_errors = 5;
+	applied_after_stripping = 0;
+	patch_input_file = NULL;
+}
 
 static void parse_whitespace_option(const char *option)
 {
@@ -2072,7 +2082,7 @@ static void write_out_results(struct pat
 	}
 }
 
-static struct lock_file lock_file;
+static struct lock_file *lock_file;
 
 static struct excludes {
 	struct excludes *next;
@@ -2106,7 +2116,7 @@ static int apply_patch(int fd, const cha
 
 	patch_input_file = filename;
 	if (!buffer)
-		return -1;
+		return -2;
 	offset = 0;
 	while (size > 0) {
 		struct patch *patch;
@@ -2134,7 +2144,7 @@ static int apply_patch(int fd, const cha
 
 	write_index = check_index && apply;
 	if (write_index && newfd < 0) {
-		newfd = hold_lock_file_for_update(&lock_file,
+		newfd = hold_lock_file_for_update(lock_file,
 						  get_index_file());
 		if (newfd < 0)
 			die("unable to create new index file");
@@ -2145,7 +2155,7 @@ static int apply_patch(int fd, const cha
 	}
 
 	if ((check || apply) && check_patch_list(list) < 0)
-		exit(1);
+		return -1;
 
 	if (apply)
 		write_out_results(list, skipped_patch);
@@ -2175,20 +2185,27 @@ static int git_apply_config(const char *
 	return git_default_config(var, value);
 }
 
-
 int cmd_apply(int argc, const char **argv, char **envp)
 {
-	int i;
+	int i, ret = 0;
 	int read_stdin = 1;
 	const char *whitespace_option = NULL;
 
+	setup_state();
+
+	/* This memory can't be free()'d since it's needed atexit() */
+	lock_file = xmalloc(sizeof(struct lock_file));
+
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 		char *end;
-		int fd;
+		int fd, apply_status;
 
 		if (!strcmp(arg, "-")) {
-			apply_patch(0, "<stdin>");
+			if (apply_patch(0, "<stdin>")) {
+				ret = 1;
+				goto err;
+			}
 			read_stdin = 0;
 			continue;
 		}
@@ -2281,12 +2298,18 @@ int cmd_apply(int argc, const char **arg
 			usage(apply_usage);
 		read_stdin = 0;
 		set_default_whitespace_mode(whitespace_option);
-		apply_patch(fd, arg);
+		apply_status = apply_patch(fd, arg);
 		close(fd);
+		if (apply_status) {
+			ret = 1;
+			goto err;
+		}
 	}
 	set_default_whitespace_mode(whitespace_option);
-	if (read_stdin)
-		apply_patch(0, "<stdin>");
+	if (read_stdin && apply_patch(0, "<stdin>")) {
+		ret = 1;
+		goto err;
+	}
 	if (whitespace_error) {
 		if (squelch_whitespace_errors &&
 		    squelch_whitespace_errors < whitespace_error) {
@@ -2316,9 +2339,12 @@ int cmd_apply(int argc, const char **arg
 
 	if (write_index) {
 		if (write_cache(newfd, active_cache, active_nr) ||
-		    commit_lock_file(&lock_file))
+		    commit_lock_file(lock_file))
 			die("Unable to write new index file");
 	}
 
-	return 0;
+err:
+	rollback_lock_file(lock_file);
+
+	return ret;
 }
Signature · 1 line
1.4.0
#9 lore raw

PATCH 8/8 Make git-am a builtin

In reply to a message not in the archive

---

Being able to switch index-file on the fly would reduce the number of system() calls.
A way to check if the index/working dir is dirty would also help.

 Makefile     |    6 -
 builtin-am.c |  664 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 builtin.h    |    1 
 git-am.sh    |  427 -------------------------------------
 git.c        |    3 
 5 files changed, 670 insertions(+), 431 deletions(-)
Makefile +3 -3
index 4b30ca0..e9b372e 100644
@@ -122,7 +122,7 @@ SCRIPT_SH = \
 	git-repack.sh git-request-pull.sh git-reset.sh \
 	git-resolve.sh git-revert.sh git-sh-setup.sh \
 	git-tag.sh git-verify-tag.sh \
-	git-applymbox.sh git-applypatch.sh git-am.sh \
+	git-applymbox.sh git-applypatch.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 	git-merge-resolve.sh git-merge-ours.sh \
 	git-lost-found.sh git-quiltimport.sh
@@ -166,7 +166,7 @@ PROGRAMS = \
 BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
 	git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
 	git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
-	git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
+	git-check-ref-format$X git-rev-parse$X git-mailinfo$X git-am$X \
 	git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
 	git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
 	git-read-tree$X git-commit-tree$X git-write-tree$X \
@@ -220,7 +220,7 @@ LIB_OBJS = \
 BUILTIN_OBJS = \
 	builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
 	builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
-	builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
+	builtin-rm.o builtin-init-db.o builtin-rev-parse.o builtin-am.o \
 	builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \
 	builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
 	builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
builtin-am.c new file +664 -0

664 lines not on this page · raw message

builtin.h +1 -0
index c1f3395..8771e36 100644
@@ -49,6 +49,7 @@ extern int cmd_cat_file(int argc, const 
 extern int cmd_rev_parse(int argc, const char **argv, char **envp);
 extern int cmd_update_index(int argc, const char **argv, char **envp);
 extern int cmd_update_ref(int argc, const char **argv, char **envp);
+extern int cmd_am(int argc, const char **argv, char **envp);
 
 extern int cmd_write_tree(int argc, const char **argv, char **envp);
 extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
git-am.sh deleted +0 -427

427 lines not on this page · raw message

git.c +2 -1
index 652e3c4..b9261e4 100644
@@ -184,7 +184,8 @@ static void handle_internal_command(int 
 		{ "mailinfo", cmd_mailinfo },
 		{ "stripspace", cmd_stripspace },
 		{ "update-index", cmd_update_index },
-		{ "update-ref", cmd_update_ref }
+		{ "update-ref", cmd_update_ref },
+		{ "am", cmd_am }
 	};
 	int i;
 
Signature · 1 line
1.4.0