git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Clément Poulain" <clement.poulain@ensimag.imag.fr>
To: git@vger.kernel.org
Cc: "Clément Poulain" <clement.poulain@ensimag.imag.fr>,
	"Diane Gasselin" <diane.gasselin@ensimag.imag.fr>,
	"Axel Bonnet" <axel.bonnet@ensimag.imag.fr>
Subject: [PATCH v3 1/4] sha1_name: add get_sha1_with_context()
Date: Wed,  9 Jun 2010 19:02:06 +0200	[thread overview]
Message-ID: <1276102929-31712-2-git-send-email-clement.poulain@ensimag.imag.fr> (raw)
In-Reply-To: <1276102929-31712-1-git-send-email-clement.poulain@ensimag.imag.fr>

Textconv is defined by the diff driver, which is associated with a pathname,
not a blob. This fonction permits to know the context for the sha1 you're
looking for, especially his pathname

Signed-off-by: Clément Poulain <clement.poulain@ensimag.imag.fr>
Signed-off-by: Diane Gasselin <diane.gasselin@ensimag.imag.fr>
Signed-off-by: Axel Bonnet <axel.bonnet@ensimag.imag.fr>
---
 cache.h     |   11 +++++++++++
 sha1_name.c |   31 ++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/cache.h b/cache.h
index c966023..67030db 100644
--- a/cache.h
+++ b/cache.h
@@ -730,12 +730,23 @@ static inline unsigned int hexval(unsigned char c)
 #define MINIMUM_ABBREV 4
 #define DEFAULT_ABBREV 7
 
+struct object_context {
+	unsigned char tree[20];
+	char path[PATH_MAX];
+	unsigned mode;
+};
+
 extern int get_sha1(const char *str, unsigned char *sha1);
 extern int get_sha1_with_mode_1(const char *str, unsigned char *sha1, unsigned *mode, int gently, const char *prefix);
 static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
 {
 	return get_sha1_with_mode_1(str, sha1, mode, 1, NULL);
 }
+extern int get_sha1_with_context_1(const char *name, unsigned char *sha1, struct object_context *orc, int gently, const char *prefix);
+static inline int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc)
+{
+	return get_sha1_with_context_1(str, sha1, orc, 1, NULL);
+}
 extern int get_sha1_hex(const char *hex, unsigned char *sha1);
 extern char *sha1_to_hex(const unsigned char *sha1);	/* static buffer result! */
 extern int read_ref(const char *filename, unsigned char *sha1);
diff --git a/sha1_name.c b/sha1_name.c
index bf92417..7fdb202 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -933,8 +933,8 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
  */
 int get_sha1(const char *name, unsigned char *sha1)
 {
-	unsigned unused;
-	return get_sha1_with_mode(name, sha1, &unused);
+	struct object_context unused;
+	return get_sha1_with_context(name, sha1, &unused);
 }
 
 /* Must be called only when object_name:filename doesn't exist. */
@@ -1032,11 +1032,23 @@ static void diagnose_invalid_index_path(int stage,
 
 int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode, int gently, const char *prefix)
 {
+	struct object_context oc;
+	int ret;
+	ret = get_sha1_with_context_1(name, sha1, &oc, gently, prefix);
+	*mode = oc.mode;
+	return ret;
+}
+
+int get_sha1_with_context_1(const char *name, unsigned char *sha1,
+			    struct object_context *oc,
+			    int gently, const char *prefix)
+{
 	int ret, bracket_depth;
 	int namelen = strlen(name);
 	const char *cp;
 
-	*mode = S_IFINVALID;
+	memset(oc, 0, sizeof(*oc));
+	oc->mode = S_IFINVALID;
 	ret = get_sha1_1(name, namelen, sha1);
 	if (!ret)
 		return ret;
@@ -1059,6 +1071,11 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
 			cp = name + 3;
 		}
 		namelen = namelen - (cp - name);
+
+		strncpy(oc->path, cp,
+			sizeof(oc->path));
+		oc->path[sizeof(oc->path)-1] = '\0';
+
 		if (!active_cache)
 			read_cache();
 		pos = cache_name_pos(cp, namelen);
@@ -1071,7 +1088,6 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
 				break;
 			if (ce_stage(ce) == stage) {
 				hashcpy(sha1, ce->sha1);
-				*mode = ce->ce_mode;
 				return 0;
 			}
 			pos++;
@@ -1098,12 +1114,17 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
 		}
 		if (!get_sha1_1(name, cp-name, tree_sha1)) {
 			const char *filename = cp+1;
-			ret = get_tree_entry(tree_sha1, filename, sha1, mode);
+			ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
 			if (!gently) {
 				diagnose_invalid_sha1_path(prefix, filename,
 							   tree_sha1, object_name);
 				free(object_name);
 			}
+			hashcpy(oc->tree, tree_sha1);
+			strncpy(oc->path, filename,
+				sizeof(oc->path));
+			oc->path[sizeof(oc->path)-1] = '\0';
+
 			return ret;
 		} else {
 			if (!gently)
-- 
1.6.6.7.ga5fe3

  reply	other threads:[~2010-06-09 17:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-09 17:02 [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
2010-06-09 17:02 ` Clément Poulain [this message]
2010-06-09 17:02   ` [PATCH v3 2/4] textconv: support for cat_file Clément Poulain
2010-06-09 17:02     ` [PATCH v3 3/4] git gui: use textconv filter for diff and blame Clément Poulain
2010-06-09 17:02       ` [PATCH v3 4/4] t/t8007: test textconv support for cat-file Clément Poulain
2010-06-14 17:18 ` [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
2010-06-14 17:29   ` Junio C Hamano
2010-06-16  7:50     ` Matthieu Moy
2010-06-15 15:50 ` [PATCH v3 2/4] textconv: support for cat_file Clément Poulain

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1276102929-31712-2-git-send-email-clement.poulain@ensimag.imag.fr \
    --to=clement.poulain@ensimag.imag.fr \
    --cc=axel.bonnet@ensimag.imag.fr \
    --cc=diane.gasselin@ensimag.imag.fr \
    --cc=git@vger.kernel.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).