git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/5] Move reset_index_file() to a new reset.c

From
Miklos Vajna <vmiklos@frugalware.org>
Date
May 24, 2008, 00:01 UTC
Message-ID
<40d6845554a032ef66a20289aea6c7b2f157fed3.1211586801.git.vmiklos@frugalware.org>
In-Reply-To
<cover.1211586801.git.vmiklos@frugalware.org>
This is needed as we want to use it later in builtin-merge.
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
 Makefile        |    2 ++
 builtin-reset.c |   17 +----------------
 reset.c         |   28 ++++++++++++++++++++++++++++
 reset.h         |    6 ++++++
 4 files changed, 37 insertions(+), 16 deletions(-)
 create mode 100644 reset.c
 create mode 100644 reset.h
diff --git a/Makefile b/Makefile
index a2de075..91d938a 100644
--- a/Makefile
+++ b/Makefile
@@ -364,6 +364,7 @@ LIB_H += quote.h
 LIB_H += reflog-walk.h
 LIB_H += refs.h
 LIB_H += remote.h
+LIB_H += reset.h
 LIB_H += revision.h
 LIB_H += run-command.h
 LIB_H += sha1-lookup.h
@@ -443,6 +444,7 @@ LIB_OBJS += read-cache.o
 LIB_OBJS += reflog-walk.o
 LIB_OBJS += refs.o
 LIB_OBJS += remote.o
+LIB_OBJS += reset.o
 LIB_OBJS += revision.o
 LIB_OBJS += run-command.o
 LIB_OBJS += server-info.o
diff --git a/builtin-reset.c b/builtin-reset.c
index 79424bb..6e6e168 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -18,6 +18,7 @@
 #include "tree.h"
 #include "branch.h"
 #include "parse-options.h"
+#include "reset.h"
 
 static const char * const git_reset_usage[] = {
 	"git-reset [--mixed | --soft | --hard] [-q] [<commit>]",
@@ -49,22 +50,6 @@ static inline int is_merge(void)
 	return !access(git_path("MERGE_HEAD"), F_OK);
 }
 
-static int reset_index_file(const unsigned char *sha1, int is_hard_reset)
-{
-	int i = 0;
-	const char *args[6];
-
-	args[i++] = "read-tree";
-	args[i++] = "-v";
-	args[i++] = "--reset";
-	if (is_hard_reset)
-		args[i++] = "-u";
-	args[i++] = sha1_to_hex(sha1);
-	args[i] = NULL;
-
-	return run_command_v_opt(args, RUN_GIT_CMD);
-}
-
 static void print_new_head_line(struct commit *commit)
 {
 	const char *hex, *body;
diff --git a/reset.c b/reset.c
new file mode 100644
index 0000000..a75fec6
--- /dev/null
+++ b/reset.c
@@ -0,0 +1,28 @@
+/*
+ * generic fucntion(s) from the "git reset" builtin command
+ *
+ * Copyright (c) 2007 Carlos Rica
+ *
+ * Based on git-reset.sh, which is
+ *
+ * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
+ */
+
+#include "cache.h"
+#include "run-command.h"
+
+int reset_index_file(const unsigned char *sha1, int is_hard_reset)
+{
+	int i = 0;
+	const char *args[6];
+
+	args[i++] = "read-tree";
+	args[i++] = "-v";
+	args[i++] = "--reset";
+	if (is_hard_reset)
+		args[i++] = "-u";
+	args[i++] = sha1_to_hex(sha1);
+	args[i] = NULL;
+
+	return run_command_v_opt(args, RUN_GIT_CMD);
+}
diff --git a/reset.h b/reset.h
new file mode 100644
index 0000000..4ae235b
--- /dev/null
+++ b/reset.h
@@ -0,0 +1,6 @@
+#ifndef RESET_H
+#define RESET_H
+
+int reset_index_file(const unsigned char *sha1, int is_hard_reset);
+
+#endif
-- 
1.5.5.1.357.g1af8b.dirty
Previous: Miklos VajnaNext: Miklos Vajna
Message 2 of 10 in “Build in merge”
  1. 0/5 Build in mergeMiklos Vajna, May 24, 2008
  2. 1/5 Move reset_index_file() to a new reset.cMiklos Vajna, May 24, 2008
  3. 2/5 Move split_cmdline() to libgitMiklos Vajna, May 24, 2008
  4. 3/5 Make verbosity configurable in reset_index_file()Miklos Vajna, May 24, 2008
  5. 4/5 Move commit_list_count() to commit.cMiklos Vajna, May 24, 2008
  6. 5/5 Build in mergeMiklos Vajna, May 24, 2008
  7. Kristian HøgsbergMay 27, 2008
  8. Miklos VajnaMay 27, 2008
  9. Daniel BarkalowMay 24, 2008
  10. Miklos VajnaMay 24, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.