* [RFC/PATCH] Add a new commit-raw command.
@ 2009-02-24 21:28 Felipe Contreras
2009-02-24 22:14 ` Jeff King
0 siblings, 1 reply; 4+ messages in thread
From: Felipe Contreras @ 2009-02-24 21:28 UTC (permalink / raw)
To: git; +Cc: Rene Stadler, Felipe Contreras
This command receives as input a raw commit object, and outputs the
generated sha1. This is very useful when doing some serious repo
reconstructions.
For example: git cat-file -p 343ee25 | git write-raw
343ee2589d1b94772f513cc699765622351acb19
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
Makefile | 1 +
builtin-commit-raw.c | 23 +++++++++++++++++++++++
builtin.h | 1 +
git.c | 1 +
4 files changed, 26 insertions(+), 0 deletions(-)
create mode 100644 builtin-commit-raw.c
diff --git a/Makefile b/Makefile
index b040a96..94212b3 100644
--- a/Makefile
+++ b/Makefile
@@ -524,6 +524,7 @@ BUILTIN_OBJS += builtin-checkout-index.o
BUILTIN_OBJS += builtin-checkout.o
BUILTIN_OBJS += builtin-clean.o
BUILTIN_OBJS += builtin-clone.o
+BUILTIN_OBJS += builtin-commit-raw.o
BUILTIN_OBJS += builtin-commit-tree.o
BUILTIN_OBJS += builtin-commit.o
BUILTIN_OBJS += builtin-config.o
diff --git a/builtin-commit-raw.c b/builtin-commit-raw.c
new file mode 100644
index 0000000..66c41f4
--- /dev/null
+++ b/builtin-commit-raw.c
@@ -0,0 +1,23 @@
+/*
+ * Writes a raw commit object
+ */
+
+#include "cache.h"
+#include "commit.h"
+
+int cmd_commit_raw(int argc, const char **argv, const char *unused_prefix)
+{
+ unsigned char commit_sha1[20];
+ struct strbuf buffer;
+
+ strbuf_init(&buffer, 8192);
+
+ strbuf_read(&buffer, 0, 0);
+
+ if (!write_sha1_file(buffer.buf, buffer.len, "commit", commit_sha1)) {
+ printf("%s\n", sha1_to_hex(commit_sha1));
+ return 0;
+ }
+ else
+ return 1;
+}
diff --git a/builtin.h b/builtin.h
index 1495cf6..5c33e69 100644
--- a/builtin.h
+++ b/builtin.h
@@ -38,6 +38,7 @@ extern int cmd_cherry_pick(int argc, const char **argv, const char *prefix);
extern int cmd_clone(int argc, const char **argv, const char *prefix);
extern int cmd_clean(int argc, const char **argv, const char *prefix);
extern int cmd_commit(int argc, const char **argv, const char *prefix);
+extern int cmd_commit_raw(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);
diff --git a/git.c b/git.c
index c2b181e..b033365 100644
--- a/git.c
+++ b/git.c
@@ -285,6 +285,7 @@ static void handle_internal_command(int argc, const char **argv)
{ "clone", cmd_clone },
{ "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE },
{ "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE },
+ { "commit-raw", cmd_commit_raw, RUN_SETUP },
{ "commit-tree", cmd_commit_tree, RUN_SETUP },
{ "config", cmd_config },
{ "count-objects", cmd_count_objects, RUN_SETUP },
--
1.6.1.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [RFC/PATCH] Add a new commit-raw command.
2009-02-24 21:28 [RFC/PATCH] Add a new commit-raw command Felipe Contreras
@ 2009-02-24 22:14 ` Jeff King
2009-02-24 22:17 ` Felipe Contreras
2009-02-24 23:07 ` Shawn O. Pearce
0 siblings, 2 replies; 4+ messages in thread
From: Jeff King @ 2009-02-24 22:14 UTC (permalink / raw)
To: Felipe Contreras; +Cc: git, Rene Stadler
On Tue, Feb 24, 2009 at 11:28:34PM +0200, Felipe Contreras wrote:
> This command receives as input a raw commit object, and outputs the
> generated sha1. This is very useful when doing some serious repo
> reconstructions.
>
> For example: git cat-file -p 343ee25 | git write-raw
> 343ee2589d1b94772f513cc699765622351acb19
How about:
git cat-file -p 343ee25 | git hash-object -t commit --stdin
?
-Peff
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC/PATCH] Add a new commit-raw command.
2009-02-24 22:14 ` Jeff King
@ 2009-02-24 22:17 ` Felipe Contreras
2009-02-24 23:07 ` Shawn O. Pearce
1 sibling, 0 replies; 4+ messages in thread
From: Felipe Contreras @ 2009-02-24 22:17 UTC (permalink / raw)
To: Jeff King; +Cc: git, Rene Stadler
On Wed, Feb 25, 2009 at 12:14 AM, Jeff King <peff@peff.net> wrote:
> On Tue, Feb 24, 2009 at 11:28:34PM +0200, Felipe Contreras wrote:
>
>> This command receives as input a raw commit object, and outputs the
>> generated sha1. This is very useful when doing some serious repo
>> reconstructions.
>>
>> For example: git cat-file -p 343ee25 | git write-raw
>> 343ee2589d1b94772f513cc699765622351acb19
>
> How about:
>
> git cat-file -p 343ee25 | git hash-object -t commit --stdin
Duh! Thanks :)
I knew there must have been something for that use-case.
--
Felipe Contreras
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC/PATCH] Add a new commit-raw command.
2009-02-24 22:14 ` Jeff King
2009-02-24 22:17 ` Felipe Contreras
@ 2009-02-24 23:07 ` Shawn O. Pearce
1 sibling, 0 replies; 4+ messages in thread
From: Shawn O. Pearce @ 2009-02-24 23:07 UTC (permalink / raw)
To: Felipe Contreras; +Cc: Jeff King, git, Rene Stadler
Jeff King <peff@peff.net> wrote:
> On Tue, Feb 24, 2009 at 11:28:34PM +0200, Felipe Contreras wrote:
>
> > This command receives as input a raw commit object, and outputs the
> > generated sha1. This is very useful when doing some serious repo
> > reconstructions.
> >
> > For example: git cat-file -p 343ee25 | git write-raw
> > 343ee2589d1b94772f513cc699765622351acb19
>
> How about:
>
> git cat-file -p 343ee25 | git hash-object -t commit --stdin
And if you are really writing a lot of new objects, use fast-import.
--
Shawn.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-02-24 23:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-24 21:28 [RFC/PATCH] Add a new commit-raw command Felipe Contreras
2009-02-24 22:14 ` Jeff King
2009-02-24 22:17 ` Felipe Contreras
2009-02-24 23:07 ` Shawn O. Pearce
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).