git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Junio C Hamano <gitster@pobox.com>, Git List <git@vger.kernel.org>
Subject: Re: [RFC/PATCH 0/7] Rework git core for native submodules
Date: Fri,  5 Apr 2013 22:07:58 +0530	[thread overview]
Message-ID: <1365179878-2259-1-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <CA+55aFxyyqkS4XyE1as2TdeARce9g9BTK=jdY+XcomNtMdrArg@mail.gmail.com>

Linus Torvalds wrote:
> So you absolutely need a dirty worktree. You need it for testing, and
> you need it for merging. Having a model where you don't have a
> in-progress entity that works as a temporary is absolutely and
> entirely wrong.

I agree entirely.  My comment was just a "by the way", and specific to
how people work with .gitmodules: I didn't imply any strong notions of
Right or Wrong with respect to dirty worktrees in general.  So, yes:
links stage and unstage, just like blobs do.

Oh, and I'm currently writing infrastructure to work with links like
blobs.  Here's a WIP: git cat-link <link> is exactly the same as cat
<file>, to the end user.

-- 8< --
From d8a1de6f9075771dde6f1fde9ffa193dce386a17 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon@gmail.com>
Date: Fri, 5 Apr 2013 19:42:56 +0530
Subject: [PATCH] builtin/cat-link: implement new builtin

This is a simple program that calls unpack_trees() with a custom
callback that just prints the contents of whatever objects were
matched using revs.prune_data.  Blobs can be cat'ed directly from the
filesystem, so this program is primarily useful for links; git
cat-link <link> shows it up like a blob.

We will use this program to build edit-link.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 Makefile           |  3 +-
 builtin.h          |  1 +
 builtin/cat-link.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 diff-lib.c         | 10 +++----
 diff.h             |  6 ++++
 git.c              |  1 +
 6 files changed, 98 insertions(+), 6 deletions(-)
 create mode 100644 builtin/cat-link.c

diff --git a/Makefile b/Makefile
index cd4b6f9..28194d7 100644
--- a/Makefile
+++ b/Makefile
@@ -349,7 +349,7 @@ GIT-VERSION-FILE: FORCE
 
 # CFLAGS and LDFLAGS are for the users to override from the command line.
 
-CFLAGS = -g -O2 -Wall
+CFLAGS = -g -O0 -Wall
 LDFLAGS =
 ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
@@ -893,6 +893,7 @@ BUILTIN_OBJS += builtin/blame.o
 BUILTIN_OBJS += builtin/branch.o
 BUILTIN_OBJS += builtin/bundle.o
 BUILTIN_OBJS += builtin/cat-file.o
+BUILTIN_OBJS += builtin/cat-link.o
 BUILTIN_OBJS += builtin/check-attr.o
 BUILTIN_OBJS += builtin/check-ignore.o
 BUILTIN_OBJS += builtin/check-ref-format.o
diff --git a/builtin.h b/builtin.h
index faef559..be0160d 100644
--- a/builtin.h
+++ b/builtin.h
@@ -49,6 +49,7 @@ extern int cmd_blame(int argc, const char **argv, const char *prefix);
 extern int cmd_branch(int argc, const char **argv, const char *prefix);
 extern int cmd_bundle(int argc, const char **argv, const char *prefix);
 extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
+extern int cmd_cat_link(int argc, const char **argv, const char *prefix);
 extern int cmd_checkout(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_attr(int argc, const char **argv, const char *prefix);
diff --git a/builtin/cat-link.c b/builtin/cat-link.c
new file mode 100644
index 0000000..14dd92b
--- /dev/null
+++ b/builtin/cat-link.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2013 Ramkumar Ramachandra
+ */
+#include "cache.h"
+#include "tree.h"
+#include "cache-tree.h"
+#include "unpack-trees.h"
+#include "commit.h"
+#include "diff.h"
+#include "revision.h"
+
+static int cat_file(struct cache_entry **src, struct unpack_trees_options *o) {
+	int cached, match_missing = 1;
+	unsigned dirty_submodule = 0;
+	unsigned int mode;
+	const unsigned char *sha1;
+	struct cache_entry *idx = src[0];
+	struct cache_entry *tree = src[1];
+	struct rev_info *revs = o->unpack_data;
+	enum object_type type;
+	unsigned long size;
+	char *buf;
+
+	cached = o->index_only;
+	if (ce_path_match(idx ? idx : tree, &revs->prune_data)) {
+		if (get_stat_data(idx, &sha1, &mode, cached, match_missing,
+					&dirty_submodule, NULL) < 0)
+			die("Something went wrong!");
+		buf = read_sha1_file(sha1, &type, &size);
+		printf("%s", buf);
+	}
+	return 0;
+}
+
+int cmd_cat_link(int argc, const char **argv, const char *prefix)
+{
+	struct unpack_trees_options opts;
+	int cached = 1;
+	struct rev_info revs;
+	struct tree *tree;
+	struct tree_desc tree_desc;
+	struct object_array_entry *ent;
+
+	if (argc < 2)
+		die("Usage: git cat-link <link>");
+
+	init_revisions(&revs, prefix);
+	setup_revisions(argc, argv, &revs, NULL); /* For revs.prune_data */
+	add_head_to_pending(&revs);
+
+	/* Hack to diff against index; we create a dummy tree for the
+	   index information */
+	if (!revs.pending.nr) {
+		struct tree *tree;
+		tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+		add_pending_object(&revs, &tree->object, "HEAD");
+	}
+
+	if (read_cache() < 0)
+		die("read_cache() failed");
+	ent = revs.pending.objects;
+	tree = parse_tree_indirect(ent->item->sha1);
+	if (!tree)
+		return error("bad tree object %s",
+			     ent->name ? ent->name : sha1_to_hex(ent->item->sha1));
+
+	memset(&opts, 0, sizeof(opts));
+	opts.head_idx = 1;
+	opts.index_only = cached;
+	opts.diff_index_cached = cached;
+	opts.merge = 1;
+	opts.fn = cat_file;
+	opts.unpack_data = &revs;
+	opts.src_index = &the_index;
+	opts.dst_index = NULL;
+	opts.pathspec = &revs.diffopt.pathspec;
+	opts.pathspec->recursive = 1;
+	opts.pathspec->max_depth = -1;
+
+	init_tree_desc(&tree_desc, tree->buffer, tree->size);
+	unpack_trees(1, &tree_desc, &opts);
+	return 0;
+}
diff --git a/diff-lib.c b/diff-lib.c
index f35de0f..b0ba136 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -246,11 +246,11 @@ static void diff_index_show_file(struct rev_info *revs,
 		       sha1, sha1_valid, ce->name, dirty_submodule);
 }
 
-static int get_stat_data(struct cache_entry *ce,
-			 const unsigned char **sha1p,
-			 unsigned int *modep,
-			 int cached, int match_missing,
-			 unsigned *dirty_submodule, struct diff_options *diffopt)
+int get_stat_data(struct cache_entry *ce,
+		const unsigned char **sha1p,
+		unsigned int *modep,
+		int cached, int match_missing,
+		unsigned *dirty_submodule, struct diff_options *diffopt)
 {
 	const unsigned char *sha1 = ce->sha1;
 	unsigned int mode = ce->ce_mode;
diff --git a/diff.h b/diff.h
index 78b4091..02ed497 100644
--- a/diff.h
+++ b/diff.h
@@ -326,6 +326,12 @@ extern int diff_result_code(struct diff_options *, int);
 
 extern void diff_no_index(struct rev_info *, int, const char **, int, const char *);
 
+extern int get_stat_data(struct cache_entry *ce,
+			const unsigned char **sha1p,
+			unsigned int *modep,
+			int cached, int match_missing,
+			unsigned *dirty_submodule, struct diff_options *diffopt);
+
 extern int index_differs_from(const char *def, int diff_flags);
 
 extern size_t fill_textconv(struct userdiff_driver *driver,
diff --git a/git.c b/git.c
index 850d3f5..3f3f074 100644
--- a/git.c
+++ b/git.c
@@ -313,6 +313,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "branch", cmd_branch, RUN_SETUP },
 		{ "bundle", cmd_bundle, RUN_SETUP_GENTLY },
 		{ "cat-file", cmd_cat_file, RUN_SETUP },
+		{ "cat-link", cmd_cat_link, RUN_SETUP },
 		{ "check-attr", cmd_check_attr, RUN_SETUP },
 		{ "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },
 		{ "check-ref-format", cmd_check_ref_format },
-- 
1.8.2.380.g0d4e79b

  reply	other threads:[~2013-04-06 16:50 UTC|newest]

Thread overview: 140+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-04 18:30 [RFC/PATCH 0/7] Rework git core for native submodules Ramkumar Ramachandra
2013-04-04 18:30 ` [PATCH 1/7] link.c, link.h: introduce fifth object type Ramkumar Ramachandra
2013-04-04 18:30 ` [PATCH 2/7] sha1_file, link: write link objects to the database Ramkumar Ramachandra
2013-04-05  7:11   ` Ramkumar Ramachandra
2013-04-05  7:59     ` Ramkumar Ramachandra
2013-04-04 18:30 ` [PATCH 3/7] teach ce_compare_gitlink() about OBJ_LINK Ramkumar Ramachandra
2013-04-04 18:30 ` [PATCH 4/7] builtin/log: teach show " Ramkumar Ramachandra
2013-04-04 18:30 ` [PATCH 5/7] edit-link: add new builtin Ramkumar Ramachandra
2013-04-04 18:30 ` [PATCH 6/7] clone: introduce clone.submodulegitdir Ramkumar Ramachandra
2013-04-05  7:07   ` Ramkumar Ramachandra
2013-04-04 18:30 ` [PATCH 7/7] sha1_file: write ref_name to link object Ramkumar Ramachandra
2013-04-05  7:03   ` Ramkumar Ramachandra
2013-04-04 18:40 ` [RFC/PATCH 0/7] Rework git core for native submodules Linus Torvalds
2013-04-04 18:52   ` Ramkumar Ramachandra
2013-04-04 19:04     ` Linus Torvalds
2013-04-04 19:17       ` Junio C Hamano
2013-04-04 19:59         ` Ramkumar Ramachandra
2013-04-04 20:28         ` Jens Lehmann
2013-04-04 19:36       ` Ramkumar Ramachandra
2013-04-04 19:44         ` Linus Torvalds
2013-04-04 19:52           ` Ramkumar Ramachandra
2013-04-04 20:08             ` Ramkumar Ramachandra
2013-04-04 20:04           ` Ramkumar Ramachandra
2013-04-05 16:02             ` Linus Torvalds
2013-04-05 16:37               ` Ramkumar Ramachandra [this message]
2013-04-04 19:42       ` Ramkumar Ramachandra
2013-04-04 21:20       ` Jens Lehmann
2013-04-04 21:35         ` Ramkumar Ramachandra
2013-04-04 22:13         ` Junio C Hamano
2013-04-04 22:18           ` Ramkumar Ramachandra
2013-04-04 22:26             ` Junio C Hamano
2013-04-04 22:32               ` Ramkumar Ramachandra
2013-04-04 23:08                 ` Junio C Hamano
2013-04-04 23:14                   ` Ramkumar Ramachandra
2013-04-05 17:07                     ` Junio C Hamano
2013-04-05 17:23                       ` Ramkumar Ramachandra
2013-04-05  6:53     ` Ramkumar Ramachandra
2013-04-04 18:47 ` Jonathan Nieder
2013-04-04 18:58   ` Jonathan Nieder
2013-04-04 18:55 ` Jonathan Nieder
2013-04-08 10:10   ` Duy Nguyen
2013-04-08 10:26     ` [PATCH] t3700 (add): add failing test for add with submodules Ramkumar Ramachandra
2013-04-08 11:04       ` Duy Nguyen
2013-04-08 15:07         ` Junio C Hamano
2013-04-08 21:30       ` Jeff King
2013-04-08 22:03         ` Junio C Hamano
2013-04-08 22:07           ` Jeff King
2013-04-09  9:19         ` Ramkumar Ramachandra
2013-04-09  9:21           ` [PATCH 0/2] Fix git " Ramkumar Ramachandra
2013-04-09  9:21             ` [PATCH 1/2] t3700 (add): add two tests for testing " Ramkumar Ramachandra
2013-04-09  9:21             ` [PATCH 2/2] add: refuse to add paths beyond repository boundaries Ramkumar Ramachandra
2013-04-09 16:50               ` Jeff King
2013-04-09 17:09               ` Junio C Hamano
2013-04-09 17:34                 ` Junio C Hamano
2013-04-09 17:41                   ` Ramkumar Ramachandra
2013-04-09 17:54                     ` Junio C Hamano
2013-04-09 18:17                       ` Ramkumar Ramachandra
2013-04-09 18:50                         ` Junio C Hamano
2013-04-09 19:09                           ` Junio C Hamano
2013-04-09 20:31                         ` Junio C Hamano
2013-04-10 13:25                           ` Ramkumar Ramachandra
2013-04-10 16:25                             ` Junio C Hamano
2013-04-09 17:41                   ` Junio C Hamano
2013-04-09 17:56                     ` Ramkumar Ramachandra
2013-04-09 18:48                       ` Junio C Hamano
2013-04-10 13:38                         ` Ramkumar Ramachandra
2013-04-09 18:32                   ` Jakub Narębski
2013-04-09 18:51                     ` Junio C Hamano
2013-04-09 18:58                       ` Jakub Narębski
2013-04-09 19:10                         ` Junio C Hamano
2013-04-09 16:27           ` [PATCH] t3700 (add): add failing test for add with submodules Jeff King
2013-04-09 11:43         ` Jakub Narębski
2013-04-09 11:54           ` Ramkumar Ramachandra
2013-04-09 13:49             ` Jakub Narębski
2013-04-06 20:10 ` [RFC/PATCH 0/7] Rework git core for native submodules Ramkumar Ramachandra
2013-04-07  3:31   ` Junio C Hamano
2013-04-07  7:27     ` Ramkumar Ramachandra
2013-04-07  9:00       ` Junio C Hamano
2013-04-07 10:58         ` Ramkumar Ramachandra
2013-04-07 15:51         ` Ramkumar Ramachandra
2013-04-07 16:12           ` John Keeping
2013-04-07 16:42             ` Ramkumar Ramachandra
2013-04-07 17:02               ` John Keeping
2013-04-07 17:22                 ` Ramkumar Ramachandra
2013-04-07 17:52                   ` John Keeping
2013-04-07 18:07                     ` Ramkumar Ramachandra
2013-04-07 18:21                       ` John Keeping
2013-04-07 18:34                         ` Jens Lehmann
2013-04-07 18:44                           ` Ramkumar Ramachandra
2013-04-07 20:15                             ` Jens Lehmann
2013-04-07 20:49                               ` Ramkumar Ramachandra
2013-04-07 21:02                                 ` John Keeping
2013-04-07 21:11                                   ` Ramkumar Ramachandra
2013-04-07 20:57                               ` Ramkumar Ramachandra
2013-04-07 21:23                                 ` Jonathan Nieder
2013-04-07 21:30                                   ` Ramkumar Ramachandra
2013-04-08  7:48                                     ` Jens Lehmann
2013-04-08  8:07                                       ` Ramkumar Ramachandra
2013-04-08  8:19                                         ` Jonathan Nieder
2013-04-08  9:08                                           ` Ramkumar Ramachandra
2013-04-08 10:29                                             ` Duy Nguyen
2013-04-08 11:06                                               ` Ramkumar Ramachandra
2013-04-08 11:29                                                 ` Duy Nguyen
2013-04-08 11:53                                                   ` Ramkumar Ramachandra
2013-04-08 15:06                                                     ` Junio C Hamano
2013-04-08 16:08                                                       ` Ramkumar Ramachandra
2013-04-08 18:10                                                         ` Junio C Hamano
2013-04-08 19:03                                                           ` Ramkumar Ramachandra
2013-04-08 19:48                                                             ` Junio C Hamano
2013-04-08 19:54                                                               ` Ramkumar Ramachandra
2013-04-08 20:30                                                                 ` Junio C Hamano
2013-04-08 21:03                                                                   ` Ramkumar Ramachandra
2013-04-10  7:23                                                                     ` Philip Oakley
2013-04-08 21:59                                                                   ` Ramkumar Ramachandra
2013-04-09 11:51                                                           ` Jakub Narębski
2013-04-08 11:10                                               ` Ramkumar Ramachandra
2013-04-08  8:37                                         ` Jonathan Nieder
2013-04-08  9:14                                           ` Ramkumar Ramachandra
2013-04-08 14:46                                           ` Junio C Hamano
2013-04-08 17:12                                             ` Junio C Hamano
2013-04-17 10:37                                   ` Duy Nguyen
2013-04-17 11:06                                     ` Ramkumar Ramachandra
2013-04-17 11:27                                       ` Duy Nguyen
2013-04-17 11:56                                         ` Ramkumar Ramachandra
2013-04-17 12:06                                           ` Duy Nguyen
2013-04-17 12:14                                             ` Ramkumar Ramachandra
     [not found]                                         ` <CALkWK0m9QmZaSDruY=+2F-Kkw+fd6E1TYC TBpVQHRJrzq2VjCQ@mail.gmail.com>
2013-04-17 23:17                                           ` Philip Oakley
2013-04-18  7:50                                             ` Ramkumar Ramachandra
2013-04-19 17:08                                             ` Jens Lehmann
2013-04-17 16:01                                     ` Junio C Hamano
2013-04-08 20:41                               ` Jens Lehmann
2013-04-08 21:36                                 ` Jeff King
2013-04-07 18:59                           ` John Keeping
2013-04-07 19:06                             ` Ramkumar Ramachandra
2013-04-07 19:17                               ` Ramkumar Ramachandra
2013-04-07 18:37                         ` Ramkumar Ramachandra
2013-04-07 18:22                       ` Ramkumar Ramachandra
2013-04-07 19:26           ` Ramkumar Ramachandra
     [not found]             ` <CAP8UFD3i2vc3OSAHRERpiPY7cRjqhkqcBN9hVW0QmMksnCPccw@mail.gmail.com>
2013-04-07 21:24               ` Ramkumar Ramachandra
     [not found]                 ` <CAP8UFD16gwWjE7T75D7kUM-VOXhtZaSRGtEg8fW5kmuKDLTQHQ@mail.gmail.com>
2013-04-08 17:04                   ` Ramkumar Ramachandra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365179878-2259-1-git-send-email-artagnon@gmail.com \
    --to=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).