Skip to contentSkip to conversation

Rewrite branch in C and make it a builtin.

PATCH In review Kristian Høgsberg 2 participants 3 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Rewrite branch in C and make it a builtin.

From: =?utf-8?q?Kristian_H=C3=B8gsberg?= <[email protected]>

A more or less straight port to C of the shell script version.

---
 Makefile         |    3 -
 builtin-branch.c |  227 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 builtin.h        |    1 
 git-branch.sh    |  130 -------------------------------
 git.c            |    1 
 5 files changed, 231 insertions(+), 131 deletions(-)
Makefile +2 -1
index 23cd8a0..adf043e 100644
@@ -149,7 +149,7 @@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powe
 ### --- END CONFIGURATION SECTION ---
 
 SCRIPT_SH = \
-	git-bisect.sh git-branch.sh git-checkout.sh \
+	git-bisect.sh git-checkout.sh \
 	git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \
 	git-fetch.sh \
 	git-ls-remote.sh \
@@ -253,6 +253,7 @@ LIB_OBJS = \
 BUILTIN_OBJS = \
 	builtin-add.o \
 	builtin-apply.o \
+	builtin-branch.o \
 	builtin-cat-file.o \
 	builtin-checkout-index.o \
 	builtin-check-ref-format.o \
builtin-branch.c new file +227 -0

227 lines not on this page · raw message

builtin.h +1 -0
index ade58c4..eb28986 100644
@@ -15,6 +15,7 @@ extern int write_tree(unsigned char *sha
 
 extern int cmd_add(int argc, const char **argv, const char *prefix);
 extern int cmd_apply(int argc, const char **argv, const char *prefix);
+extern int cmd_branch(int argc, const char **argv, const char *prefix);
 extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
 extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
 extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
git-branch.sh deleted +0 -130

130 lines not on this page · raw message

git.c +1 -0
index 930998b..5738cb4 100644
@@ -226,6 +226,7 @@ static void handle_internal_command(int 
 	} commands[] = {
 		{ "add", cmd_add, RUN_SETUP },
 		{ "apply", cmd_apply },
+		{ "branch", cmd_branch, RUN_SETUP },
 		{ "cat-file", cmd_cat_file, RUN_SETUP },
 		{ "checkout-index", cmd_checkout_index, RUN_SETUP },
 		{ "check-ref-format", cmd_check_ref_format },
Signature · 1 line
1.4.2.g8153-dirty
#1 lore raw
Quoted 1 line · Kristian H??gsberg

A more or less straight port to C of the shell script version.

[snip]

Quoted 1 line

+static void create_reflog(struct ref_lock *lock)

I'm attaching a patch to the reflog code which introduces a new force_log option. You can use set this after you lock the ref but before writing it, provided that the user supplied -l on the command line.

This completely replaces the create_reflog function with common code.

I apologize for taking so long to get around to this but I've been busy with other stuff lately. :-)

-- 8> --
Add force_log flag to ref_lock to create logs when necessary.

Callers of lock_ref_sha1 or lock_any_ref_for_update may now set lck->force_log = 1 if they want to create the associated reflog during write_ref_sha1 if the log is missing.

If set this will override a false setting of the configuration parameter core.logAllRefUpdates and create a missing log, at which point future updates to the same ref would be logged as the log is present.

---
 refs.c |    2 +-
 refs.h |    3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
refs.c +1 -1
index aab14fc..b29e2f4 100644
@@ -361,7 +361,7 @@ static int log_ref_write(struct ref_lock
 	char *logrec;
 	const char *committer;
 
-	if (log_all_ref_updates) {
+	if (log_all_ref_updates || lock->force_log) {
 		if (safe_create_leading_directories(lock->log_file) < 0)
 			return error("unable to create directory for %s",
 				lock->log_file);
refs.h +2 -1
index 553155c..d4798c9 100644
@@ -7,7 +7,8 @@ struct ref_lock {
 	struct lock_file *lk;
 	unsigned char old_sha1[20];
 	int lock_fd;
-	int force_write;
+	int force_write; /* force creating ref if not present */
+	int force_log;   /* force creating log if not present */
 };
 
 /*
Signature · 5 lines
1.4.2.ga2654


-- 
VGER BF report: U 0.5
#2 lore raw
Quoted 4 lines · Shawn Pearce
Quoted 1 line · Kristian H??gsberg

A more or less straight port to C of the shell script version.

[snip]

Quoted 8 lines
Quoted 1 line

+static void create_reflog(struct ref_lock *lock)

I'm attaching a patch to the reflog code which introduces a new force_log option. You can use set this after you lock the ref but before writing it, provided that the user supplied -l on the command line.

This completely replaces the create_reflog function with common code.

Yeah, that should work, I'll send out a new version that uses the new flag.

Quoted 2 lines

I apologize for taking so long to get around to this but I've been busy with other stuff lately. :-)

No problem at all, I'm working on this on and off anyway :)

Kristian

Signature · 1 line
VGER BF report: U 0.499995