Skip to contentSkip to conversation

Enable wt-status output to a given FILE pointer.

PATCH In review Kristian Høgsberg 5 participants 25 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/9 Enable wt-status output to a given FILE pointer.

Still defaults to stdout, but you can now override wt_status.fp after calling wt_status_prepare().

---
 color.c     |   18 ++++++------
 color.h     |    4 +-
 wt-status.c |   85 ++++++++++++++++++++++++++++++----------------------------
 wt-status.h |    3 ++
 4 files changed, 58 insertions(+), 52 deletions(-)
color.c +9 -9
index 09d82ee..124ba33 100644
@@ -135,39 +135,39 @@ int git_config_colorbool(const char *var, const char *value)
 	return git_config_bool(var, value);
 }
 
-static int color_vprintf(const char *color, const char *fmt,
+static int color_vfprintf(FILE *fp, const char *color, const char *fmt,
 		va_list args, const char *trail)
 {
 	int r = 0;
 
 	if (*color)
-		r += printf("%s", color);
-	r += vprintf(fmt, args);
+		r += fprintf(fp, "%s", color);
+	r += vfprintf(fp, fmt, args);
 	if (*color)
-		r += printf("%s", COLOR_RESET);
+		r += fprintf(fp, "%s", COLOR_RESET);
 	if (trail)
-		r += printf("%s", trail);
+		r += fprintf(fp, "%s", trail);
 	return r;
 }
 
 
 
-int color_printf(const char *color, const char *fmt, ...)
+int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)
 {
 	va_list args;
 	int r;
 	va_start(args, fmt);
-	r = color_vprintf(color, fmt, args, NULL);
+	r = color_vfprintf(fp, color, fmt, args, NULL);
 	va_end(args);
 	return r;
 }
 
-int color_printf_ln(const char *color, const char *fmt, ...)
+int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)
 {
 	va_list args;
 	int r;
 	va_start(args, fmt);
-	r = color_vprintf(color, fmt, args, "\n");
+	r = color_vfprintf(fp, color, fmt, args, "\n");
 	va_end(args);
 	return r;
 }
color.h +2 -2
index 88bb8ff..6809800 100644
@@ -6,7 +6,7 @@
 
 int git_config_colorbool(const char *var, const char *value);
 void color_parse(const char *var, const char *value, char *dst);
-int color_printf(const char *color, const char *fmt, ...);
-int color_printf_ln(const char *color, const char *fmt, ...);
+int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
+int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
 
 #endif /* COLOR_H */
wt-status.c +44 -41

193 lines not on this page · raw message

wt-status.h +3 -0
index cfea4ae..4f3a615 100644
@@ -1,6 +1,8 @@
 #ifndef STATUS_H
 #define STATUS_H
 
+#include <stdio.h>
+
 enum color_wt_status {
 	WT_STATUS_HEADER,
 	WT_STATUS_UPDATED,
@@ -19,6 +21,7 @@ struct wt_status {
 	int commitable;
 	int workdir_dirty;
 	int workdir_untracked;
+	FILE *fp;
 };
 
 int git_status_config(const char *var, const char *value);
Signature · 1 line
1.5.2.GIT
#1 lore raw

PATCH 2/9 Enable wt-status to run against non-standard index file.

We still default to get_index_file(), but this can be overridden by setting wt_status.index_file after calling wt_status_prepare().

---
 wt-status.c |    3 ++-
 wt-status.h |    1 +
 2 files changed, 3 insertions(+), 1 deletions(-)
wt-status.c +2 -1
index 65a7259..0cf9b81 100644
@@ -53,6 +53,7 @@ void wt_status_prepare(struct wt_status *s)
 	s->branch = head ? xstrdup(head) : NULL;
 	s->reference = "HEAD";
 	s->fp = stdout;
+	s->index_file = get_index_file();
 }
 
 static void wt_status_print_cached_header(struct wt_status *s)
@@ -198,7 +199,7 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
 static void wt_read_cache(struct wt_status *s)
 {
 	discard_cache();
-	read_cache();
+	read_cache_from(s->index_file);
 }
 
 static void wt_status_print_initial(struct wt_status *s)
wt-status.h +1 -0
index 4f3a615..7744932 100644
@@ -21,6 +21,7 @@ struct wt_status {
 	int commitable;
 	int workdir_dirty;
 	int workdir_untracked;
+	const char *index_file;
 	FILE *fp;
 };
 
Signature · 1 line
1.5.2.GIT
#2 lore raw

PATCH 3/9 Add strbuf_printf() to do formatted printing to a strbuf.

Also, expose strbuf_add() and strbuf_add_char() to add raw data to the buffer.

---
 strbuf.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 strbuf.h |    3 ++
 2 files changed, 65 insertions(+), 7 deletions(-)
strbuf.c +62 -7
index e33d06b..2805c11 100644
@@ -11,16 +11,26 @@ static void strbuf_begin(struct strbuf *sb) {
 	strbuf_init(sb);
 }
 
-static void inline strbuf_add(struct strbuf *sb, int ch) {
-	if (sb->alloc <= sb->len) {
-		sb->alloc = sb->alloc * 3 / 2 + 16;
-		sb->buf = xrealloc(sb->buf, sb->alloc);
-	}
+static void inline strbuf_grow(struct strbuf *sb, size_t extra)
+{
+	ALLOC_GROW(sb->buf, sb->len + extra, sb->alloc);
+}
+
+void strbuf_add(struct strbuf *sb, const char *data, size_t len)
+{
+	strbuf_grow(sb, len);
+	memcpy(sb->buf + sb->len, data, len);
+	sb->len += len;
+}
+
+void strbuf_add_char(struct strbuf *sb, int ch)
+{
+	strbuf_grow(sb, 1);
 	sb->buf[sb->len++] = ch;
 }
 
 static void strbuf_end(struct strbuf *sb) {
-	strbuf_add(sb, 0);
+	strbuf_add_char(sb, 0);
 }
 
 void read_line(struct strbuf *sb, FILE *fp, int term) {
@@ -33,9 +43,54 @@ void read_line(struct strbuf *sb, FILE *fp, int term) {
 	while ((ch = fgetc(fp)) != EOF) {
 		if (ch == term)
 			break;
-		strbuf_add(sb, ch);
+		strbuf_add_char(sb, ch);
 	}
 	if (ch == EOF && sb->len == 0)
 		sb->eof = 1;
 	strbuf_end(sb);
 }
+
+void strbuf_printf(struct strbuf *sb, const char *fmt, ...)
+{
+	char buffer[2048];
+	va_list args;
+	int len, size = 2 * sizeof buffer;
+
+	va_start(args, fmt);
+	len = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	if (len > sizeof(buffer)) {
+		/*
+		 * Didn't fit in the buffer, but this vsnprintf at
+		 * least gives us the required length back.  Grow the
+		 * buffer acccordingly and try again.
+		 */
+		strbuf_grow(sb, len);
+		va_start(args, fmt);
+		len = vsnprintf(sb->buf + sb->len,
+				sb->alloc - sb->len, fmt, args);
+		va_end(args);
+	} else if (len >= 0) {
+		/*
+		 * The initial vsnprintf fit in the temp buffer, just
+		 * copy it to the strbuf.
+		 */
+		strbuf_add(sb, buffer, len);
+	} else {
+		/*
+		 * This vnsprintf sucks and just returns -1 when the
+		 * buffer is too small.  Keep doubling the size until
+		 * it fits.
+		 */
+		while (len < 0) {
+			strbuf_grow(sb, size);
+			va_start(args, fmt);
+			len = vsnprintf(sb->buf + sb->len,
+					sb->alloc - sb->len, fmt, args);
+			va_end(args);
+			size *= 2;
+		}
+	}
+}
+
strbuf.h +3 -0
index 74cc012..1e5d09e 100644
@@ -9,5 +9,8 @@ struct strbuf {
 
 extern void strbuf_init(struct strbuf *);
 extern void read_line(struct strbuf *, FILE *, int);
+extern void strbuf_add(struct strbuf *sb, const char *data, size_t len);
+extern void strbuf_add_char(struct strbuf *sb, int ch);
+extern void strbuf_printf(struct strbuf *sb, const char *fmt, ...);
 
 #endif /* STRBUF_H */
Signature · 1 line
1.5.2.GIT
#3 lore raw

PATCH 4/9 Introduce entry point for launching add--interactive.

This refactors builtin-add.c a little to provide a unique entry point for launching git add --interactive, which will be used by builtin-commit too. If we later want to make add --interactive a builtin or change how it is launched, we just start from this function.

---
 builtin-add.c |   15 ++++++++++-----
 commit.h      |    9 +++++++++
 2 files changed, 19 insertions(+), 5 deletions(-)
builtin-add.c +10 -5
index 3dd4ded..e79e8f7 100644
@@ -12,6 +12,7 @@
 #include "diffcore.h"
 #include "commit.h"
 #include "revision.h"
+#include "run-command.h"
 
 static const char builtin_add_usage[] =
 "git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--] <filepattern>...";
@@ -153,6 +154,13 @@ static int git_add_config(const char *var, const char *value)
 	return git_default_config(var, value);
 }
 
+int interactive_add(void)
+{
+	const char *argv[2] = { "add--interactive", NULL };
+
+	return run_command_v_opt(argv, RUN_GIT_CMD);
+}
+
 static struct lock_file lock_file;
 
 static const char ignore_warning[] =
@@ -172,12 +180,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 			add_interactive++;
 	}
 	if (add_interactive) {
-		const char *args[] = { "add--interactive", NULL };
-
-		if (add_interactive != 1 || argc != 2)
+		if (argc != 2)
 			die("add --interactive does not take any parameters");
-		execv_git_cmd(args);
-		exit(1);
+		exit(interactive_add());
 	}
 
 	git_config(git_add_config);
commit.h +9 -0
index 467872e..64e1d4b 100644
@@ -122,4 +122,13 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
 		int depth, int shallow_flag, int not_shallow_flag);
 
 int in_merge_bases(struct commit *, struct commit **, int);
+
+extern const unsigned char *
+create_commit(const unsigned char *tree_sha1,
+	      unsigned char parent_sha1[][20], int parents,
+	      const char *author_info, const char *committer_info,
+	      const char *message, int length);
+
+extern int interactive_add(void);
+
 #endif /* COMMIT_H */
Signature · 1 line
1.5.2.GIT
#4 lore raw

PATCH 5/9 Introduce strbuf_read_fd().

This function reads from a given fd into a strbuf until end of file.

---
 strbuf.c |   19 +++++++++++++++++++
 strbuf.h |    1 +
 2 files changed, 20 insertions(+), 0 deletions(-)
strbuf.c +19 -0
index 2805c11..fcfc05e 100644
@@ -50,6 +50,25 @@ void read_line(struct strbuf *sb, FILE *fp, int term) {
 	strbuf_end(sb);
 }
 
+int strbuf_read_fd(struct strbuf *sb, int fd)
+{
+	int len, total = 0;
+
+	do {
+		strbuf_grow(sb, 1024);
+		len = xread(fd, sb->buf + sb->len, sb->alloc - sb->len);
+		if (len > 0) {
+			total += len;
+			sb->len += len;
+		}
+	} while (len > 0);
+
+	if (len < 0)
+		return len;
+
+	return total;
+}
+
 void strbuf_printf(struct strbuf *sb, const char *fmt, ...)
 {
 	char buffer[2048];
strbuf.h +1 -0
index 1e5d09e..6e630ea 100644
@@ -12,5 +12,6 @@ extern void read_line(struct strbuf *, FILE *, int);
 extern void strbuf_add(struct strbuf *sb, const char *data, size_t len);
 extern void strbuf_add_char(struct strbuf *sb, int ch);
 extern void strbuf_printf(struct strbuf *sb, const char *fmt, ...);
+extern int strbuf_read_fd(struct strbuf *sb, int fd);
 
 #endif /* STRBUF_H */
Signature · 1 line
1.5.2.GIT
#5 lore raw

PATCH 6/9 Rewrite launch_editor, create_tag and stripspace to use strbufs.

---
 builtin-stripspace.c |   45 +++++++++++++-------------
 builtin-tag.c        |   84 +++++++++++++++++++++-----------------------------
 builtin.h            |    1 -
 strbuf.c             |   43 +++++---------------------
 strbuf.h             |    2 +
 5 files changed, 68 insertions(+), 107 deletions(-)
builtin-stripspace.c +23 -22
index 916355c..f0264a8 100644
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "strbuf.h"
 
 /*
  * Returns the length of a line, without trailing spaces.
@@ -34,34 +35,34 @@ static size_t cleanup(char *line, size_t len)
  * If the input has only empty lines and spaces,
  * no output will be produced.
  *
- * If last line has a newline at the end, it will be removed.
+ * If the last line does not have a newline, one will be added.
  *
  * Enable skip_comments to skip every line starting with "#".
  */
-size_t stripspace(char *buffer, size_t length, int skip_comments)
+size_t stripspace(struct strbuf *sb, int skip_comments)
 {
 	int empties = -1;
 	size_t i, j, len, newlen;
 	char *eol;
 
-	for (i = j = 0; i < length; i += len, j += newlen) {
-		eol = memchr(buffer + i, '\n', length - i);
-		len = eol ? eol - (buffer + i) + 1 : length - i;
+	for (i = j = 0; i < sb->len; i += len, j += newlen) {
+		eol = memchr(sb->buf + i, '\n', sb->len - i);
+		len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
 
-		if (skip_comments && len && buffer[i] == '#') {
+		if (skip_comments && len && sb->buf[i] == '#') {
 			newlen = 0;
 			continue;
 		}
-		newlen = cleanup(buffer + i, len);
+		newlen = cleanup(sb->buf + i, len);
 
 		/* Not just an empty line? */
 		if (newlen) {
 			if (empties != -1)
-				buffer[j++] = '\n';
+				sb->buf[j++] = '\n';
 			if (empties > 0)
-				buffer[j++] = '\n';
+				sb->buf[j++] = '\n';
 			empties = 0;
-			memmove(buffer + j, buffer + i, newlen);
+			memmove(sb->buf + j, sb->buf + i, newlen);
 			continue;
 		}
 		if (empties < 0)
@@ -69,31 +70,31 @@ size_t stripspace(char *buffer, size_t length, int skip_comments)
 		empties++;
 	}
 
-	return j;
+	sb->len = j;
+	if (j > 0)
+		strbuf_add_char(sb, '\n');
+
+	return sb->len;
 }
 
 int cmd_stripspace(int argc, const char **argv, const char *prefix)
 {
-	char *buffer;
-	unsigned long size;
+	struct strbuf sb;
 	int strip_comments = 0;
 
 	if (argc > 1 && (!strcmp(argv[1], "-s") ||
 				!strcmp(argv[1], "--strip-comments")))
 		strip_comments = 1;
 
-	size = 1024;
-	buffer = xmalloc(size);
-	if (read_fd(0, &buffer, &size)) {
-		free(buffer);
+	strbuf_init(&sb);
+	if (strbuf_read_fd(&sb, 0) < 0) {
+		strbuf_release(&sb);
 		die("could not read the input");
 	}
 
-	size = stripspace(buffer, size, strip_comments);
-	write_or_die(1, buffer, size);
-	if (size)
-		putc('\n', stdout);
+	stripspace(&sb, strip_comments);
+	write_or_die(1, sb.buf, sb.len);
+	strbuf_release(&sb);
 
-	free(buffer);
 	return 0;
 }
builtin-tag.c +35 -49

147 lines not on this page · raw message

builtin.h +0 -1
index bb72000..91bc595 100644
@@ -7,7 +7,6 @@ extern const char git_version_string[];
 extern const char git_usage_string[];
 
 extern void help_unknown_cmd(const char *cmd);
-extern size_t stripspace(char *buffer, size_t length, int skip_comments);
 extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
 extern void prune_packed_objects(int);
 
strbuf.c +8 -35

65 lines not on this page · raw message

strbuf.h +2 -0
index 6e630ea..a93b9e1 100644
@@ -8,10 +8,12 @@ struct strbuf {
 };
 
 extern void strbuf_init(struct strbuf *);
+extern void strbuf_release(struct strbuf *);
 extern void read_line(struct strbuf *, FILE *, int);
 extern void strbuf_add(struct strbuf *sb, const char *data, size_t len);
 extern void strbuf_add_char(struct strbuf *sb, int ch);
 extern void strbuf_printf(struct strbuf *sb, const char *fmt, ...);
 extern int strbuf_read_fd(struct strbuf *sb, int fd);
+extern size_t stripspace(struct strbuf *sb, int skip_comments);
 
 #endif /* STRBUF_H */
Signature · 1 line
1.5.2.GIT
#6 lore raw

PATCH 7/9 Add strbuf_read_path().

---
 builtin-tag.c |    7 +------
 strbuf.c      |   15 +++++++++++++++
 strbuf.h      |    1 +
 3 files changed, 17 insertions(+), 6 deletions(-)
builtin-tag.c +1 -6
index 1aff952..8724d49 100644
@@ -53,14 +53,9 @@ static void launch_editor(const char *path, struct strbuf *sb)
 	if (run_command(&child))
 		die("There was a problem with the editor %s.", editor);
 
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		die("could not open '%s': %s", path, strerror(errno));
-	if (strbuf_read_fd(sb, fd) < 0) {
+	if (strbuf_read_path(sb, path) < 0)
 		die("could not read message file '%s': %s",
 		    path, strerror(errno));
-	}
-	close(fd);
 }
 
 struct tag_filter {
strbuf.c +15 -0
index ed2afea..1951a5b 100644
@@ -70,6 +70,21 @@ int strbuf_read_fd(struct strbuf *sb, int fd)
 	return total;
 }
 
+int strbuf_read_path(struct strbuf *sb, const char *path)
+{
+	int fd, len;
+
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+		return -1;
+	len = strbuf_read_fd(sb, fd);
+	if (len < 0)
+		return -1;
+	close(fd);
+
+	return len;
+}
+
 void strbuf_printf(struct strbuf *sb, const char *fmt, ...)
 {
 	char buffer[2048];
strbuf.h +1 -0
index a93b9e1..e852070 100644
@@ -14,6 +14,7 @@ extern void strbuf_add(struct strbuf *sb, const char *data, size_t len);
 extern void strbuf_add_char(struct strbuf *sb, int ch);
 extern void strbuf_printf(struct strbuf *sb, const char *fmt, ...);
 extern int strbuf_read_fd(struct strbuf *sb, int fd);
+extern int strbuf_read_path(struct strbuf *sb, const char *path);
 extern size_t stripspace(struct strbuf *sb, int skip_comments);
 
 #endif /* STRBUF_H */
Signature · 1 line
1.5.2.GIT
#7 lore raw

PATCH 8/9 Export rerere() and launch_editor().

---
 builtin-rerere.c |   16 ++++++++++++++++
 builtin-tag.c    |    3 +--
 commit.h         |    1 +
 strbuf.h         |    1 +
 4 files changed, 19 insertions(+), 2 deletions(-)
builtin-rerere.c +16 -0
index 29d057c..eb22a28 100644
@@ -415,6 +415,22 @@ static int is_rerere_enabled(void)
 	return 1;
 }
 
+/* Export for builtin-commit. */
+int rerere(void)
+{
+	struct path_list merge_rr = { NULL, 0, 0, 1 };
+	int fd;
+
+	git_config(git_rerere_config);
+	if (!is_rerere_enabled())
+		return 0;
+
+	merge_rr_path = xstrdup(git_path("rr-cache/MERGE_RR"));
+	fd = hold_lock_file_for_update(&write_lock, merge_rr_path, 1);
+	read_rr(&merge_rr);
+	return do_plain_rerere(&merge_rr, fd);
+}
+
 int cmd_rerere(int argc, const char **argv, const char *prefix)
 {
 	struct path_list merge_rr = { NULL, 0, 0, 1 };
builtin-tag.c +1 -2
index 8724d49..3b181f5 100644
@@ -18,12 +18,11 @@ static const char builtin_tag_usage[] =
 
 static char signingkey[1000];
 
-static void launch_editor(const char *path, struct strbuf *sb)
+void launch_editor(const char *path, struct strbuf *sb)
 {
 	const char *editor, *terminal;
 	struct child_process child;
 	const char *args[3];
-	int fd;
 
 	editor = getenv("GIT_EDITOR");
 	if (!editor && editor_program)
commit.h +1 -0
index 64e1d4b..39934cc 100644
@@ -130,5 +130,6 @@ create_commit(const unsigned char *tree_sha1,
 	      const char *message, int length);
 
 extern int interactive_add(void);
+extern int rerere(void);
 
 #endif /* COMMIT_H */
strbuf.h +1 -0
index e852070..b009b4b 100644
@@ -16,5 +16,6 @@ extern void strbuf_printf(struct strbuf *sb, const char *fmt, ...);
 extern int strbuf_read_fd(struct strbuf *sb, int fd);
 extern int strbuf_read_path(struct strbuf *sb, const char *path);
 extern size_t stripspace(struct strbuf *sb, int skip_comments);
+extern void launch_editor(const char *path, struct strbuf *sb);
 
 #endif /* STRBUF_H */
Signature · 1 line
1.5.2.GIT
#8 lore raw

PATCH 9/9 Implement git commit as a builtin command.

Move git-commit.sh to contrib/examples.

---
 Makefile                       |    9 +-
 builtin-commit.c               |  742 ++++++++++++++++++++++++++++++++++++++++
 builtin.h                      |    3 +-
 contrib/examples/git-commit.sh |  665 +++++++++++++++++++++++++++++++++++
 git-commit.sh                  |  665 -----------------------------------
 git.c                          |    3 +-
 6 files changed, 1414 insertions(+), 673 deletions(-)
 create mode 100644 builtin-commit.c
 create mode 100755 contrib/examples/git-commit.sh
 delete mode 100755 git-commit.sh
Makefile +3 -6
index 4eb4637..beb3cbb 100644
@@ -201,7 +201,7 @@ BASIC_LDFLAGS =
 
 SCRIPT_SH = \
 	git-bisect.sh git-checkout.sh \
-	git-clean.sh git-clone.sh git-commit.sh \
+	git-clean.sh git-clone.sh \
 	git-fetch.sh \
 	git-ls-remote.sh \
 	git-merge-one-file.sh git-mergetool.sh git-parse-remote.sh \
@@ -250,7 +250,7 @@ EXTRA_PROGRAMS =
 BUILT_INS = \
 	git-format-patch$X git-show$X git-whatchanged$X git-cherry$X \
 	git-get-tar-commit-id$X git-init$X git-repo-config$X \
-	git-fsck-objects$X git-cherry-pick$X \
+	git-fsck-objects$X git-cherry-pick$X git-status$X\
 	$(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS))
 
 # what 'all' will build and 'install' will install, in gitexecdir
@@ -322,6 +322,7 @@ BUILTIN_OBJS = \
 	builtin-check-attr.o \
 	builtin-checkout-index.o \
 	builtin-check-ref-format.o \
+	builtin-commit.o \
 	builtin-commit-tree.o \
 	builtin-count-objects.o \
 	builtin-describe.o \
@@ -357,7 +358,6 @@ BUILTIN_OBJS = \
 	builtin-rev-parse.o \
 	builtin-revert.o \
 	builtin-rm.o \
-	builtin-runstatus.o \
 	builtin-shortlog.o \
 	builtin-show-branch.o \
 	builtin-stripspace.o \
@@ -797,9 +797,6 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
 	chmod +x $@+ && \
 	mv $@+ $@
 
-git-status: git-commit
-	$(QUIET_GEN)cp $< $@+ && mv $@+ $@
-
 gitweb/gitweb.cgi: gitweb/gitweb.perl
 	$(QUIET_GEN)$(RM) $@ $@+ && \
 	sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \
builtin-commit.c new file +742 -0

742 lines not on this page · raw message

builtin.h +2 -1
index 91bc595..c23cd6d 100644
@@ -23,6 +23,7 @@ extern int cmd_check_attr(int argc, const char **argv, const char *prefix);
 extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
 extern int cmd_cherry(int argc, const char **argv, const char *prefix);
 extern int cmd_cherry_pick(int argc, const char **argv, const char *prefix);
+extern int cmd_commit(int argc, const char **argv, const char *prefix);
 extern int cmd_commit_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_count_objects(int argc, const char **argv, const char *prefix);
 extern int cmd_describe(int argc, const char **argv, const char *prefix);
@@ -63,10 +64,10 @@ extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
 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_runstatus(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);
+extern int cmd_status(int argc, const char **argv, const char *prefix);
 extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
 extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
 extern int cmd_tag(int argc, const char **argv, const char *prefix);
contrib/examples/git-commit.sh new file +665 -0

665 lines not on this page · raw message

git-commit.sh deleted +0 -665

665 lines not on this page · raw message

git.c +2 -1
index cab0e72..62859a2 100644
@@ -321,6 +321,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "check-attr", cmd_check_attr, RUN_SETUP | NEED_WORK_TREE },
 		{ "cherry", cmd_cherry, RUN_SETUP },
 		{ "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },
+		{ "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE },
 		{ "commit-tree", cmd_commit_tree, RUN_SETUP },
 		{ "config", cmd_config },
 		{ "count-objects", cmd_count_objects, RUN_SETUP },
@@ -363,10 +364,10 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "rev-parse", cmd_rev_parse, RUN_SETUP },
 		{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
 		{ "rm", cmd_rm, RUN_SETUP | NEED_WORK_TREE },
-		{ "runstatus", cmd_runstatus, RUN_SETUP | NEED_WORK_TREE },
 		{ "shortlog", cmd_shortlog, RUN_SETUP | USE_PAGER },
 		{ "show-branch", cmd_show_branch, RUN_SETUP },
 		{ "show", cmd_show, RUN_SETUP | USE_PAGER },
+		{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
 		{ "stripspace", cmd_stripspace },
 		{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
 		{ "tag", cmd_tag, RUN_SETUP },
Signature · 1 line
1.5.2.GIT
#9 lore raw

Re: [PATCH 9/9] Implement git commit as a builtin command.

Hi,

Quoted 2 lines · Kristian Høgsberg
 contrib/examples/git-commit.sh |  665 +++++++++++++++++++++++++++++++++++
 git-commit.sh                  |  665 -----------------------------------

You might want to use "git format-patch -M" next time ;-)

Makefile BUILTIN_OBJS = \ · line 360

Quoted 5 lines
Makefile +0 -1
@@ -357,7 +358,6 @@ BUILTIN_OBJS = \
 	builtin-rev-parse.o \
 	builtin-revert.o \
 	builtin-rm.o \
-	builtin-runstatus.o \

Better keep it; some people's scripts could depend on it.

builtin-commit.c line 52

Quoted 9 lines
builtin-commit.c new file +9 -0
+struct option {
+    enum option_type type;
+    const char *long_name;
+    char short_name;
+    void *value;
+};
+
+static int scan_options(const char ***argv, struct option *options)
+{

I would not (no longer, anyway) be opposed to replacing the option parsing in git with getopt(); I hear that it is small enough to keep a copy in compat/getopt.c.

But let's go forward with builtin-commit; getopt() can come later.

Quoted 34 lines
builtin-commit.c new file +34 -0
+static char *
+prepare_index(const char **files, const char *prefix)
+{
+	int fd;
+	struct tree *tree;
+	struct lock_file *next_index_lock;
+
+	fd = hold_locked_index(&lock_file, 1);
+	if (read_cache() < 0)
+		die("index file corrupt");
+
+	if (all) {
+		add_files_to_cache(fd, files, NULL);
+		return lock_file.filename;
+	} else if (also) {
+		add_files_to_cache(fd, files, prefix);
+		return lock_file.filename;
+	}
+
+	if (interactive)
+		interactive_add();
+
+	if (*files == NULL) {
+		/* Commit index as-is. */
+		rollback_lock_file(&lock_file);
+		return get_index_file();
+	}
+
+	/*
+	 * FIXME: Warn on unknown files.  Shell script does
+	 *
+	 *   commit_only=`git-ls-files --error-unmatch -- "$@"`
+	 */
+

builtin-commit.c line 241

Quoted 10 lines
builtin-commit.c new file +10 -0
+	/*
+	 * FIXME: shell script does
+	 *
+	 *   git-read-tree --index-output="$TMP_INDEX" -i -m HEAD
+	 *
+	 * which warns about unmerged files in the index.
+	 */
+
+	/* update the user index file */
+	add_files_to_cache(fd, files, prefix);

I suspect this, or ...

Quoted 4 lines
builtin-commit.c new file +4 -0
+
+	if (!initial_commit) {
+		tree = parse_tree_indirect(head_sha1);
+		if (!tree)

builtin-commit.c line 255

Quoted 10 lines
builtin-commit.c new file +10 -0
+			die("failed to unpack HEAD tree object");
+		if (read_tree(tree, 0, NULL))
+			die("failed to read HEAD tree object");
+	}
+
+	/* Uh oh, abusing lock_file to create a garbage collected file */
+	next_index_lock = xmalloc(sizeof(*next_index_lock));
+	fd = hold_lock_file_for_update(next_index_lock,
+				       git_path("next-index-%d", getpid()), 1);
+	add_files_to_cache(fd, files, prefix);

... this, but not both.

builtin-commit.c line 370

Quoted 5 lines
builtin-commit.c new file +5 -0
+/* Find out if the message starting at position 'start' in the strbuf
+ * contains only whitespace and Signed-off-by lines. */
+static int message_is_empty(struct strbuf *sb, int start)
+{
+	static const char signed_off_by[] = "Signed-off-by: ";

I think you already defined that globally earlier.

In the function message_is_empty() you write:

builtin-commit.c line 381

Quoted 7 lines
builtin-commit.c new file +7 -0
+	/* See if the template is just a prefix of the message. */
+	strbuf_init(&tmpl);
+	if (template_file && strbuf_read_path(&tmpl, template_file) > 0) {
+		stripspace(&tmpl, 1);
+		if (start + tmpl.len <= sb->len &&
+		    memcmp(tmpl.buf, sb->buf + start, tmpl.len) == 0)
+			start += tmpl.len;

Could we not bail out here, if there is no match? In that case, the message is clearly not empty...

builtin-commit.c line 391

Quoted 7 lines
builtin-commit.c new file +7 -0
+	/* Check if the rest is just whitespace and Signed-of-by's. */
+	for (i = start; i < sb->len; i++) {
+		nl = memchr(sb->buf + i, '\n', sb->len - i);
+		if (nl)
+			eol = nl - sb->buf;
+		else
+			eol = sb->len;

Why not just "if (isspace(sb->buf[i]) || sb->buf[i] == '\n') continue;"? This would also catch the cases where people indent their S-O-Bs.

builtin-commit.c line 404

Quoted 13 lines
builtin-commit.c new file +13 -0
+
+		if (strlen(signed_off_by) <= eol - i &&
+		    !prefixcmp(sb->buf + i, signed_off_by)) {
+			i = eol;
+			continue;
+		}
+		while (i < eol)
+			if (!isspace(sb->buf[i++]))
+				return 0;
+	}
+
+	return 1;
+}

I did not review the rest of the code closely yet...

All in all: well done!

Ciao,
Dscho

#10 lore raw

Re: [PATCH 9/9] Implement git commit as a builtin command.

Quoted 9 lines · Johannes Schindelin

Hi,

Quoted 2 lines · Kristian Høgsberg
 contrib/examples/git-commit.sh |  665 +++++++++++++++++++++++++++++++++++
 git-commit.sh                  |  665 -----------------------------------

You might want to use "git format-patch -M" next time ;-)

Quoted 7 lines

Makefile BUILTIN_OBJS = \ · line 360

Quoted 5 lines
Makefile +0 -1
@@ -357,7 +358,6 @@ BUILTIN_OBJS = \
 	builtin-rev-parse.o \
 	builtin-revert.o \
 	builtin-rm.o \
-	builtin-runstatus.o \

Better keep it; some people's scripts could depend on it.

Seriously? Why don't we remove it and see if somebody yells? It's more of an implementation detail than most other git commands; if you need status output in your script why wouldn't you just run git status?

Quoted 14 lines

builtin-commit.c line 52

Quoted 9 lines
builtin-commit.c new file +9 -0
+struct option {
+    enum option_type type;
+    const char *long_name;
+    char short_name;
+    void *value;
+};
+
+static int scan_options(const char ***argv, struct option *options)
+{

I would not (no longer, anyway) be opposed to replacing the option parsing in git with getopt(); I hear that it is small enough to keep a copy in compat/getopt.c.

Quoted 1 line

But let's go forward with builtin-commit; getopt() can come later.

I don't know. I think it's a situation much like the string library discussion. It's a small enough dependency (70 lines!) that there's no gain in depending on an external implementation, and we can tailor it to gits needs as we extend the use within git. And we can call it gitopt!

Quoted 47 lines
Quoted 34 lines
builtin-commit.c new file +34 -0
+static char *
+prepare_index(const char **files, const char *prefix)
+{
+	int fd;
+	struct tree *tree;
+	struct lock_file *next_index_lock;
+
+	fd = hold_locked_index(&lock_file, 1);
+	if (read_cache() < 0)
+		die("index file corrupt");
+
+	if (all) {
+		add_files_to_cache(fd, files, NULL);
+		return lock_file.filename;
+	} else if (also) {
+		add_files_to_cache(fd, files, prefix);
+		return lock_file.filename;
+	}
+
+	if (interactive)
+		interactive_add();
+
+	if (*files == NULL) {
+		/* Commit index as-is. */
+		rollback_lock_file(&lock_file);
+		return get_index_file();
+	}
+
+	/*
+	 * FIXME: Warn on unknown files.  Shell script does
+	 *
+	 *   commit_only=`git-ls-files --error-unmatch -- "$@"`
+	 */
+

builtin-commit.c line 241

Quoted 10 lines
builtin-commit.c new file +10 -0
+	/*
+	 * FIXME: shell script does
+	 *
+	 *   git-read-tree --index-output="$TMP_INDEX" -i -m HEAD
+	 *
+	 * which warns about unmerged files in the index.
+	 */
+
+	/* update the user index file */
+	add_files_to_cache(fd, files, prefix);

I suspect this, or ...

Quoted 16 lines
Quoted 4 lines
builtin-commit.c new file +4 -0
+
+	if (!initial_commit) {
+		tree = parse_tree_indirect(head_sha1);
+		if (!tree)

builtin-commit.c line 255

Quoted 10 lines
builtin-commit.c new file +10 -0
+			die("failed to unpack HEAD tree object");
+		if (read_tree(tree, 0, NULL))
+			die("failed to read HEAD tree object");
+	}
+
+	/* Uh oh, abusing lock_file to create a garbage collected file */
+	next_index_lock = xmalloc(sizeof(*next_index_lock));
+	fd = hold_lock_file_for_update(next_index_lock,
+				       git_path("next-index-%d", getpid()), 1);
+	add_files_to_cache(fd, files, prefix);

... this, but not both.

No, this needs both. The first add_files_to_cache() call updates the user index (.git/index) by adding the given files, then we build a temporary index from a tree and add the files to that index.

Quoted 8 lines

builtin-commit.c line 370

Quoted 6 lines
builtin-commit.c new file +5 -0
+/* Find out if the message starting at position 'start' in the strbuf
+ * contains only whitespace and Signed-off-by lines. */
+static int message_is_empty(struct strbuf *sb, int start)
+{
+	static const char signed_off_by[] = "Signed-off-by: ";

I think you already defined that globally earlier.

Ah, yes, fixed.

Quoted 12 lines

In the function message_is_empty() you write:

builtin-commit.c line 381

Quoted 7 lines
builtin-commit.c new file +7 -0
+	/* See if the template is just a prefix of the message. */
+	strbuf_init(&tmpl);
+	if (template_file && strbuf_read_path(&tmpl, template_file) > 0) {
+		stripspace(&tmpl, 1);
+		if (start + tmpl.len <= sb->len &&
+		    memcmp(tmpl.buf, sb->buf + start, tmpl.len) == 0)
+			start += tmpl.len;

Could we not bail out here, if there is no match? In that case, the message is clearly not empty...

The contents could be just sign-off-by's.

Quoted 11 lines

builtin-commit.c line 391

Quoted 7 lines
builtin-commit.c new file +7 -0
+	/* Check if the rest is just whitespace and Signed-of-by's. */
+	for (i = start; i < sb->len; i++) {
+		nl = memchr(sb->buf + i, '\n', sb->len - i);
+		if (nl)
+			eol = nl - sb->buf;
+		else
+			eol = sb->len;

Why not just "if (isspace(sb->buf[i]) || sb->buf[i] == '\n') continue;"? This would also catch the cases where people indent their S-O-Bs.

Quoted 15 lines

builtin-commit.c line 404

Quoted 13 lines
builtin-commit.c new file +13 -0
+
+		if (strlen(signed_off_by) <= eol - i &&
+		    !prefixcmp(sb->buf + i, signed_off_by)) {
+			i = eol;
+			continue;
+		}
+		while (i < eol)
+			if (!isspace(sb->buf[i++]))
+				return 0;
+	}
+
+	return 1;
+}

I did not review the rest of the code closely yet...

I'm sending an updated version against Pierre's strbuf changes now. It's a smaller patch set, so hopefully we can get it in soon.

Kristian

#11 lore raw

Re: [PATCH 9/9] Implement git commit as a builtin command.

Quoted 7 lines · Kristian Høgsberg
Quoted 3 lines

Makefile BUILTIN_OBJS = \ · line 360

Quoted 1 line
Makefile +0 -1
-	builtin-runstatus.o \

Better keep it; some people's scripts could depend on it.

Seriously? Why don't we remove it and see if somebody yells? It's more of an implementation detail than most other git commands; if you need status output in your script why wouldn't you just run git status?

As the author of builtin-runstatus, I had always intended that it was a temporary part of the transition to a C git-commit, and would go away then. But I see in the interim somebody documented it. It should perhaps have been called git-status--helper, and the documentation should have read "DO NOT USE THIS."

So certainly my intent was for it to go away, but whether it has become something else is perhaps up to others to judge.

-Peff

#12 lore raw

Re: [PATCH 9/9] Implement git commit as a builtin command.

Quoted 10 lines · Jeff King
Quoted 7 lines · Kristian Høgsberg
Quoted 3 lines

Makefile BUILTIN_OBJS = \ · line 360

Quoted 1 line
Makefile +0 -1
-	builtin-runstatus.o \

Better keep it; some people's scripts could depend on it.

Seriously? Why don't we remove it and see if somebody yells? It's more of an implementation detail than most other git commands; if you need status output in your script why wouldn't you just run git status?

Quoted 5 lines

As the author of builtin-runstatus, I had always intended that it was a temporary part of the transition to a C git-commit, and would go away then. But I see in the interim somebody documented it. It should perhaps have been called git-status--helper, and the documentation should have read "DO NOT USE THIS."

That's what I suspected, thanks for clearing that up. It definitely feels more like a step towards a built-in commit than a useful command on it's own. It plugs right into this work, so as such, it's been a success.

Kristian

#13 lore raw

Re: [PATCH 9/9] Implement git commit as a builtin command.

In reply to Kristian Høgsberg

Hi,

Quoted 11 lines · Kristian H?gsberg
Quoted 6 lines · Johannes Schindelin

Makefile BUILTIN_OBJS = \ · line 360

Quoted 1 line · Kristian Høgsberg
Makefile +0 -1
-	builtin-runstatus.o \

Better keep it; some people's scripts could depend on it.

Seriously? Why don't we remove it and see if somebody yells? It's more of an implementation detail than most other git commands; if you need status output in your script why wouldn't you just run git status?

git status is deemed porcelain.

Yes, we recently converted a few things to use "git log", which is porcelain, too, and I was not happy...

But then, you're right, we could just go and break peoples' scripts, if they indeed did not use "git diff" directly.

Quoted 14 lines
Quoted 14 lines

builtin-commit.c line 52

Quoted 9 lines
builtin-commit.c new file +9 -0
+struct option {
+    enum option_type type;
+    const char *long_name;
+    char short_name;
+    void *value;
+};
+
+static int scan_options(const char ***argv, struct option *options)
+{

I would not (no longer, anyway) be opposed to replacing the option parsing in git with getopt(); I hear that it is small enough to keep a copy in compat/getopt.c.

Quoted 6 lines
Quoted 1 line

But let's go forward with builtin-commit; getopt() can come later.

I don't know. I think it's a situation much like the string library discussion. It's a small enough dependency (70 lines!) that there's no gain in depending on an external implementation, and we can tailor it to gits needs as we extend the use within git. And we can call it gitopt!

Hm. I liked the semantics of getopt better, but what the heck.

Quoted 2 lines

I'm sending an updated version against Pierre's strbuf changes now. It's a smaller patch set, so hopefully we can get it in soon.

Yes, that would be good.

Thanks,
Dscho

#14 lore raw

Re: [PATCH 7/9] Add strbuf_read_path().

In reply to Kristian Høgsberg

Hi,

Quoted 1 line · Kristian Høgsberg

+extern int strbuf_read_path(struct strbuf *sb, const char *path);

May I suggest renaming this to "strbuf_read_file()"? I kind of expected a function which reads in the absolute path of a file, judging by the name...

Ciao,
Dscho

#15 lore raw

Re: [PATCH 6/9] Rewrite launch_editor, create_tag and stripspace to use strbufs.

In reply to Kristian Høgsberg

Hi,

Quoted 42 lines · Kristian Høgsberg
strbuf.c +1 -28
index fcfc05e..ed2afea 100644
@@ -73,43 +74,15 @@ void strbuf_printf(struct strbuf *sb, const char *fmt, ...)
 {
 	char buffer[2048];
 	va_list args;
-	int len, size = 2 * sizeof buffer;
+	int len;
 
 	va_start(args, fmt);
 	len = vsnprintf(buffer, sizeof(buffer), fmt, args);
 	va_end(args);
 
-	if (len > sizeof(buffer)) {
-		/*
-		 * Didn't fit in the buffer, but this vsnprintf at
-		 * least gives us the required length back.  Grow the
-		 * buffer acccordingly and try again.
-		 */
-		strbuf_grow(sb, len);
-		va_start(args, fmt);
-		len = vsnprintf(sb->buf + sb->len,
-				sb->alloc - sb->len, fmt, args);
-		va_end(args);
-	} else if (len >= 0) {
-		/*
-		 * The initial vsnprintf fit in the temp buffer, just
-		 * copy it to the strbuf.
-		 */
-		strbuf_add(sb, buffer, len);
-	} else {
-		/*
-		 * This vnsprintf sucks and just returns -1 when the
-		 * buffer is too small.  Keep doubling the size until
-		 * it fits.
-		 */
-		while (len < 0) {
-			strbuf_grow(sb, size);
-			va_start(args, fmt);
-			len = vsnprintf(sb->buf + sb->len,

strbuf.c void strbuf_printf(struct strbuf *sb, const char *fmt, ...) · line 87

Quoted 10 lines
strbuf.c +4 -5
-					sb->alloc - sb->len, fmt, args);
-			va_end(args);
-			size *= 2;
-		}
-	}
+	if (len > sizeof(buffer) || len < 0)
+		die("out of buffer space\n");
+
+	strbuf_add(sb, buffer, len);
 }

Really?

(If you find the time, it would be really nice to rebase that patch series on top of Pierre's strbuf work...)

Ciao,
Dscho

#16 lore raw

Re: [PATCH 6/9] Rewrite launch_editor, create_tag and stripspace to use strbufs.

Quoted 59 lines · Johannes Schindelin

Hi,

Quoted 42 lines · Kristian Høgsberg
strbuf.c +1 -28
index fcfc05e..ed2afea 100644
@@ -73,43 +74,15 @@ void strbuf_printf(struct strbuf *sb, const char *fmt, ...)
 {
 	char buffer[2048];
 	va_list args;
-	int len, size = 2 * sizeof buffer;
+	int len;
 
 	va_start(args, fmt);
 	len = vsnprintf(buffer, sizeof(buffer), fmt, args);
 	va_end(args);
 
-	if (len > sizeof(buffer)) {
-		/*
-		 * Didn't fit in the buffer, but this vsnprintf at
-		 * least gives us the required length back.  Grow the
-		 * buffer acccordingly and try again.
-		 */
-		strbuf_grow(sb, len);
-		va_start(args, fmt);
-		len = vsnprintf(sb->buf + sb->len,
-				sb->alloc - sb->len, fmt, args);
-		va_end(args);
-	} else if (len >= 0) {
-		/*
-		 * The initial vsnprintf fit in the temp buffer, just
-		 * copy it to the strbuf.
-		 */
-		strbuf_add(sb, buffer, len);
-	} else {
-		/*
-		 * This vnsprintf sucks and just returns -1 when the
-		 * buffer is too small.  Keep doubling the size until
-		 * it fits.
-		 */
-		while (len < 0) {
-			strbuf_grow(sb, size);
-			va_start(args, fmt);
-			len = vsnprintf(sb->buf + sb->len,

strbuf.c void strbuf_printf(struct strbuf *sb, const char *fmt, ...) · line 87

Quoted 10 lines
strbuf.c +4 -5
-					sb->alloc - sb->len, fmt, args);
-			va_end(args);
-			size *= 2;
-		}
-	}
+	if (len > sizeof(buffer) || len < 0)
+		die("out of buffer space\n");
+
+	strbuf_add(sb, buffer, len);
 }

Really?

Quoted 2 lines

(If you find the time, it would be really nice to rebase that patch series on top of Pierre's strbuf work...)

Argh, this was a screwup when I edited the patch series. The next series is based on Pierres changes.

Kristian

#17 lore raw

Re: [PATCH 4/9] Introduce entry point for launching add--interactive.

In reply to Kristian Høgsberg

Hi,

Quoted 5 lines · Kristian Høgsberg
builtin-add.c +0 -0
index 3dd4ded..e79e8f7 100644

builtin-add.c static int git_add_config(const char *var, const char *value) · line 162

Quoted 9 lines
builtin-add.c +6 -0
@@ -153,6 +154,13 @@ static int git_add_config(const char *var, const char *value)
 	return git_default_config(var, value);
 }
 
+int interactive_add(void)
+{
+	const char *argv[2] = { "add--interactive", NULL };
+
+	return run_command_v_opt(argv, RUN_GIT_CMD);
+}

I'd rather have this in builtin-commit.c, since it is quite funny if builtin-add.c has code to fork() and exec() itself (eventually, that is) ;-)

Quoted 7 lines
commit.h +0 -0
index 467872e..64e1d4b 100644
@@ -122,4 +122,13 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
 		int depth, int shallow_flag, int not_shallow_flag);
 

commit.h extern struct commit_list *get_shallow_commits(struct object_array *heads, · line 133

Quoted 10 lines
commit.h +9 -0
 int in_merge_bases(struct commit *, struct commit **, int);
+
+extern const unsigned char *
+create_commit(const unsigned char *tree_sha1,
+	      unsigned char parent_sha1[][20], int parents,
+	      const char *author_info, const char *committer_info,
+	      const char *message, int length);
+
+extern int interactive_add(void);
+

Just a guess: you did not want create_commit() to creep in here, right?

Ciao,
Dscho

#18 lore raw

Re: [PATCH 4/9] Introduce entry point for launching add--interactive.

Quoted 12 lines · Johannes Schindelin

Hi,

Quoted 8 lines · Kristian Høgsberg
builtin-add.c +0 -0
index 3dd4ded..e79e8f7 100644
@@ -153,6 +154,13 @@ static int git_add_config(const char *var, const char *value)
 	return git_default_config(var, value);
 }
 
Quoted 10 lines

builtin-add.c static int git_add_config(const char *var, const char *value) · line 162

Quoted 6 lines
builtin-add.c +6 -0
+int interactive_add(void)
+{
+	const char *argv[2] = { "add--interactive", NULL };
+
+	return run_command_v_opt(argv, RUN_GIT_CMD);
+}

I'd rather have this in builtin-commit.c, since it is quite funny if builtin-add.c has code to fork() and exec() itself (eventually, that is) ;-)

Huh... it ends up in the same binary, and interactive_add() sounds like it should live in builtin-add.c rather than builtin-commit.c. Either way, I don't care too much, but can we fix it up later?

Quoted 7 lines
Quoted 7 lines
commit.h +0 -0
index 467872e..64e1d4b 100644
@@ -122,4 +122,13 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
 		int depth, int shallow_flag, int not_shallow_flag);
 
Quoted 12 lines

commit.h extern struct commit_list *get_shallow_commits(struct object_array *heads, · line 133

Quoted 10 lines
commit.h +9 -0
 int in_merge_bases(struct commit *, struct commit **, int);
+
+extern const unsigned char *
+create_commit(const unsigned char *tree_sha1,
+	      unsigned char parent_sha1[][20], int parents,
+	      const char *author_info, const char *committer_info,
+	      const char *message, int length);
+
+extern int interactive_add(void);
+

Just a guess: you did not want create_commit() to creep in here, right?

Yeah, that was another oversight, fixed in the next series.

Kristian

#19 lore raw

Re: [PATCH 4/9] Introduce entry point for launching add--interactive.

Hi,

Quoted 23 lines · Kristian H?gsberg
Quoted 11 lines · Johannes Schindelin
Quoted 8 lines · Kristian Høgsberg
builtin-add.c +0 -0
index 3dd4ded..e79e8f7 100644
@@ -153,6 +154,13 @@ static int git_add_config(const char *var, const char *value)
 	return git_default_config(var, value);
 }
 
Quoted 10 lines

builtin-add.c static int git_add_config(const char *var, const char *value) · line 162

Quoted 6 lines
builtin-add.c +6 -0
+int interactive_add(void)
+{
+	const char *argv[2] = { "add--interactive", NULL };
+
+	return run_command_v_opt(argv, RUN_GIT_CMD);
+}

I'd rather have this in builtin-commit.c, since it is quite funny if builtin-add.c has code to fork() and exec() itself (eventually, that is) ;-)

Quoted 3 lines

Huh... it ends up in the same binary, and interactive_add() sounds like it should live in builtin-add.c rather than builtin-commit.c. Either way, I don't care too much, but can we fix it up later?

Well, you are probably right on the former, and therefore we do not have to do the latter.

Thanks,
Dscho

#20 lore raw

Re: [PATCH 3/9] Add strbuf_printf() to do formatted printing to a strbuf.

In reply to Kristian Høgsberg

As you noted in your follow-up message, this one has overlaps with the other strbuf series. I could adjust them if I wanted to, but I do not have time for it right now. I might try over the weekend but no promises.

#21 lore raw

Re: [PATCH 3/9] Add strbuf_printf() to do formatted printing to a strbuf.

Quoted 4 lines · Junio C Hamano

As you noted in your follow-up message, this one has overlaps with the other strbuf series. I could adjust them if I wanted to, but I do not have time for it right now. I might try over the weekend but no promises.

This one is exactly the same as the one that follows, I corrected a
typo in the comment of the commit, and I forgot to cleanse my tree before running format-patch again, so you have the "second" patch twice (name of the patch changed, hence the new one did not replaced the previous, but created a 0002-foo.patch instead of overwriting the 0002-bar.patch).

You just must drop the one I followup-ed to.

Signature · 3 lines
·O·  Pierre Habouzit
··O                                                [email protected]
OOO                                                http://www.madism.org
#22 lore raw

Re: [PATCH 3/9] Add strbuf_printf() to do formatted printing to a strbuf.

Quoted 6 lines · Pierre Habouzit
Quoted 4 lines · Junio C Hamano

As you noted in your follow-up message, this one has overlaps with the other strbuf series. I could adjust them if I wanted to, but I do not have time for it right now. I might try over the weekend but no promises.

Quoted 8 lines

This one is exactly the same as the one that follows, I corrected a
typo in the comment of the commit, and I forgot to cleanse my tree before running format-patch again, so you have the "second" patch twice (name of the patch changed, hence the new one did not replaced the previous, but created a 0002-foo.patch instead of overwriting the 0002-bar.patch).

You just must drop the one I followup-ed to.

err sorry, I mixed up with another thread. Did not had coffee yet :/

Just nvm

Signature · 3 lines
·O·  Pierre Habouzit
··O                                                [email protected]
OOO                                                http://www.madism.org
#24 lore raw
Quoted 8 lines · Johannes Schindelin

Hi,

Quoted 2 lines · Kristian Høgsberg

Still defaults to stdout, but you can now override wt_status.fp after calling wt_status_prepare().

Would it not be easier to freopen(filename, "a", stdout)?

It's probably easier, but I think this is cleaner and the patch isn't that big. I don't want to worry about the side effects of freopening stdout...

Kristian