Skip to contentSkip to conversation

Update on builtin-commit

RFC In review Kristian Høgsberg 3 participants 6 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Update on builtin-commit

Hi,

Here's an update on the work so far, and I've attached the current state of the work as a patch. I'm pretty close to making my first commit with this, and some of the work here is ready to be factored out into a few stand-alone patches. I'm thinking of the wt-status.[ch] changes and the read_fd and read_path changes. My plan is to finish this first-pass porting of the script and then go back and review and split the patch into a series of commits, but if somebody wants to pick that up now, that'd be great.

The only steps missing here are

1) Call git-write-tree with the new index
2) Run the post-commit hook

and I need to look into the reflog stuff. But other than that, the port is mostly complete.

Kristian

---
 Makefile         |    9 +-
 builtin-commit.c |  567 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 builtin.h        |    3 +-
 cache.h          |    3 +-
 color.c          |   18 +-
 color.h          |    4 +-
 git.c            |    3 +-
 mktag.c          |    8 +-
 sha1_file.c      |   44 +++--
 wt-status.c      |   84 ++++----
 wt-status.h      |    4 +
 11 files changed, 667 insertions(+), 80 deletions(-)
 create mode 100644 builtin-commit.c
Makefile +3 -6
index 0f75955..967d5a5 100644
@@ -198,7 +198,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 \
@@ -257,7 +257,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
@@ -332,6 +332,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 \
@@ -367,7 +368,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 \
@@ -791,9 +791,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 -f $@ $@+ && \
 	sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \
builtin-commit.c new file +567 -0

567 lines not on this page · raw message

builtin.h +2 -1
index da4834c..7f395da 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_tar_tree(int argc, const char **argv, const char *prefix);
cache.h +2 -1
index 5e7381e..0403ada 100644
@@ -245,7 +245,8 @@ extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat
 extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int);
 extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
 extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
-extern int read_pipe(int fd, char** return_buf, unsigned long* return_size);
+extern int read_fd(int fd, char** return_buf, unsigned long* return_size);
+extern int read_path(const char *path, char** return_buf, unsigned long* return_size);
 extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object);
 extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
 extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
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 */
git.c +2 -1
index 29b55a1..4018e3c 100644
@@ -237,6 +237,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 		{ "check-attr", cmd_check_attr, RUN_SETUP | NOT_BARE },
 		{ "cherry", cmd_cherry, RUN_SETUP },
 		{ "cherry-pick", cmd_cherry_pick, RUN_SETUP | NOT_BARE },
+		{ "commit", cmd_commit, RUN_SETUP },
 		{ "commit-tree", cmd_commit_tree, RUN_SETUP },
 		{ "config", cmd_config },
 		{ "count-objects", cmd_count_objects, RUN_SETUP },
@@ -279,10 +280,10 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
 		{ "rev-parse", cmd_rev_parse, RUN_SETUP },
 		{ "revert", cmd_revert, RUN_SETUP | NOT_BARE },
 		{ "rm", cmd_rm, RUN_SETUP | NOT_BARE },
-		{ "runstatus", cmd_runstatus, RUN_SETUP | NOT_BARE },
 		{ "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 | NOT_BARE },
 		{ "stripspace", cmd_stripspace },
 		{ "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
 		{ "tar-tree", cmd_tar_tree },
mktag.c +3 -5
index b82e377..26b9ebf 100644
@@ -111,8 +111,8 @@ static int verify_tag(char *buffer, unsigned long size)
 
 int main(int argc, char **argv)
 {
-	unsigned long size = 4096;
-	char *buffer = xmalloc(size);
+	unsigned long size;
+	char *buffer;
 	unsigned char result_sha1[20];
 
 	if (argc != 1)
@@ -120,10 +120,8 @@ int main(int argc, char **argv)
 
 	setup_git_directory();
 
-	if (read_pipe(0, &buffer, &size)) {
-		free(buffer);
+	if (read_fd(0, &buffer, &size))
 		die("could not read from stdin");
-	}
 
 	/* Verify it for some basic sanity: it needs to start with
 	   "object <sha1>\ntype\ntagger " */
sha1_file.c +30 -14

69 lines not on this page · raw message

wt-status.c +43 -41

193 lines not on this page · raw message

wt-status.h +4 -0
index cfea4ae..7744932 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,8 @@ struct wt_status {
 	int commitable;
 	int workdir_dirty;
 	int workdir_untracked;
+	const char *index_file;
+	FILE *fp;
 };
 
 int git_status_config(const char *var, const char *value);
Signature · 1 line
1.5.2.2
#1 lore raw

Hi,

just a quick comment on the option parser:

On most platforms, sizeof(void*)>=sizeof(int). But I would not rely on that. Rather (also because it is prettier), I'd use "union".

Besides, your option parser loses order information, correct? IOW, something like "--color --no-color --color" would confuse it.

Ciao,
Dscho

#2 lore raw
Quoted 4 lines · Johannes Schindelin

just a quick comment on the option parser:

On most platforms, sizeof(void*)>=sizeof(int). But I would not rely on that. Rather (also because it is prettier), I'd use "union".

In the OPTION_INTEGER case, the 'value' void pointer points to an integer global that's set to the value passed. In the OPTION_NONE, it also points to an integer, which is set to 1 if the option is seen. So I'm relying on sizeof(void*) == sizeof(int*), but I'm not storing ints in pointers.

Quoted 2 lines

Besides, your option parser loses order information, correct? IOW, something like "--color --no-color --color" would confuse it.

Yes, I don't record the order of options, but in the builtin-commit case, I don't think there are any options where that makes a difference? In cases where order is important or we have an option that negates the effect of another option (your --no-color example), we could either 1) extend the option struct with a 'disable' name that flips the value back to 0 or 2) instead of just setting it to 1, record the index of the options passed and compare the indexes of conflicting options to see which one was passed last.

Kristian

#3 lore raw

Hi,

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

just a quick comment on the option parser:

On most platforms, sizeof(void*)>=sizeof(int). But I would not rely on that. Rather (also because it is prettier), I'd use "union".

In the OPTION_INTEGER case, the 'value' void pointer points to an integer global that's set to the value passed. In the OPTION_NONE, it also points to an integer, which is set to 1 if the option is seen. So I'm relying on sizeof(void*) == sizeof(int*), but I'm not storing ints in pointers.

Ah, right.

Quoted 5 lines
Quoted 2 lines

Besides, your option parser loses order information, correct? IOW, something like "--color --no-color --color" would confuse it.

Yes, I don't record the order of options, but in the builtin-commit case, I don't think there are any options where that makes a difference?

That might be correct now. But why not make the option parser general enough to (finally!) support something like "git clone -lns <directory>", i.e. short options a la GNU? This is something that has been wanted for a long time.

Besides, if you make the option parser not general enough to be reused in all git programs, I wonder why bother at all? It's not like it is less complex than a hand-rolled option parser, if it is used only once.

Quoted 6 lines

In cases where order is important or we have an option that negates the effect of another option (your --no-color example), we could either 1) extend the option struct with a 'disable' name that flips the value back to 0 or 2) instead of just setting it to 1, record the index of the options passed and compare the indexes of conflicting options to see which one was passed last.

Hmm. Somehow I think that the getopt solution is not so bad at all. We'd need some code in compat/, but since we're GPL, and there are so many GPLed getopt versions out there, I don't see any obstacle there.

Ciao,
Dscho

#4 lore raw
Quoted 4 lines · Johannes Schindelin

Hmm. Somehow I think that the getopt solution is not so bad at all. We'd need some code in compat/, but since we're GPL, and there are so many GPLed getopt versions out there, I don't see any obstacle there.

If we are going to make this option parser into some complex general-purpose option parsing library let's not re-invent the wheel. Let's pick one of the GPL'd option parsing libraries and make it a dependency of Git.

Jeff

#5 lore raw
Quoted 10 lines · Jeffrey C. Ollie
Quoted 4 lines · Johannes Schindelin

Hmm. Somehow I think that the getopt solution is not so bad at all. We'd need some code in compat/, but since we're GPL, and there are so many GPLed getopt versions out there, I don't see any obstacle there.

If we are going to make this option parser into some complex general-purpose option parsing library let's not re-invent the wheel. Let's pick one of the GPL'd option parsing libraries and make it a dependency of Git.

I don't have much of an opinion here; as I've said before, my goal here is to get commit ported to C, and I specifically don't want to block on the option parser discussion reaching consensus. One thing I do not want to do, though, is to explode the current table driven approach into a gazillion strcmps. Other than that I'm open to porting it to an external getopt dependency, adding the couple of missing features Johannes mentioned (bundling and ordering), or just keeping it local to builtin-commit.c as is.

That said, we're debating less than 100 lines of code. Adding the bundling of short options and some kind of ordering mechanism would add at most 20 more lines. Is it worth taking a getopt dependency for that?

Kristian