git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@uchicago.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: Daniel Barkalow <barkalow@iabervon.org>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 3/3] git-add --intent-to-add (-N)
Date: Fri, 22 Aug 2008 02:52:39 -0500 (CDT)	[thread overview]
Message-ID: <Pine.GSO.4.62.0808220150410.13589@harper.uchicago.edu> (raw)
In-Reply-To: <Pine.GSO.4.62.0808220119250.12851@harper.uchicago.edu>

Jonathan Nieder wrote:
[...]
> I still wonder, do we want to pretend we have that object on disk
> and proceed with the commit, or are the hardcoded objects only
> supposed to be sufficient for in-core use?

Sorry, I responded in haste.  The objects are supposed to be used in
core and then written out as needed, so I had been describing a bug.

How about this (in the spirit of patch 1/3)?  If the approach is
right, I can add tests tomorrow.

-- snipsnip --
Subject: update_one(): write out cached objects as needed

Although we can always pretend to have hardcoded objects such as
the empty tree in core, in the on-disk repository, if they are
referred to, they should be present.  Currently, if we try to
write a tree that uses a hardcoded object, we can notice that the
object is missing and fail with "error: invalid object".

With this patch, the objects are written to disk as needed
instead.

Signed-off-by: Jonathan Nieder <jrnieder@uchicago.edu>
---
 cache-tree.c |   11 +++++++++--
 cache.h      |    1 +
 sha1_file.c  |   16 ++++++++++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/cache-tree.c b/cache-tree.c
index 5f8ee87..b17f34f 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -323,8 +323,15 @@ static int update_one(struct cache_tree *it,
 			mode = ce->ce_mode;
 			entlen = pathlen - baselen;
 		}
-		if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))
-			return error("invalid object %s", sha1_to_hex(sha1));
+		if (mode != S_IFGITLINK && !missing_ok &&
+				!has_sha1_file(sha1)) {
+			/* Hopefully it's a cached object.  Make sure. */
+			if (dryrun)
+				(void) sha1_object_info(sha1, NULL);
+			else if (write_cached_object_sha1_file(sha1))
+				return error("invalid object %s",
+					sha1_to_hex(sha1));
+		}
 
 		if (ce->ce_flags & CE_REMOVE)
 			continue; /* entry being removed */
diff --git a/cache.h b/cache.h
index c443df4..83dbdf7 100644
--- a/cache.h
+++ b/cache.h
@@ -546,6 +546,7 @@ extern int hash_sha1_file(const void *buf, unsigned long len, const char *type,
 extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
 extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
 extern int force_object_loose(const unsigned char *sha1, time_t mtime);
+extern int write_cached_object_sha1_file(const unsigned char *sha1);
 
 /* just like read_sha1_file(), but non fatal in presence of bad objects */
 extern void *read_object(const unsigned char *sha1, enum object_type *type, unsigned long *size);
diff --git a/sha1_file.c b/sha1_file.c
index 7d86d76..8584a33 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2028,6 +2028,22 @@ static struct cached_object *find_cached_object(const unsigned char *sha1)
 	return NULL;
 }
 
+int write_cached_object_sha1_file(const unsigned char *sha1)
+{
+	struct cached_object *co = find_cached_object(sha1);
+	unsigned char sha1_compare[20];
+	int result;
+
+	if (co == NULL)
+		return -1;
+	result = write_sha1_file(co->buf, co->size, typename(co->type),
+			sha1_compare);
+	if (memcmp(sha1, sha1_compare, 20))
+		return error("corrupt cached object %s",
+				sha1_to_hex(sha1));
+	return result;
+}
+
 int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
 		      unsigned char *sha1)
 {
-- 
1.6.0.481.gabe4

  reply	other threads:[~2008-08-22  7:54 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-18  0:02 Call Me Gitless Trans
2008-08-18  0:28 ` Benjamin Sergeant
2008-08-18  0:40 ` Martin Langhoff
2008-08-18  8:50 ` Pascal Obry
2008-08-18 16:43 ` Jon Loeliger
2008-08-18 19:22 ` Daniel Barkalow
2008-08-18 20:17   ` Marcus Griep
2008-08-18 20:20   ` Junio C Hamano
2008-08-18 21:31     ` Daniel Barkalow
2008-08-18 22:30       ` Junio C Hamano
2008-08-18 23:12         ` Daniel Barkalow
2008-08-19  3:22           ` Junio C Hamano
2008-08-19  3:55             ` Marcus Griep
2008-08-19  6:47               ` Junio C Hamano
2008-08-19  7:02                 ` Junio C Hamano
2008-08-20  8:00                   ` [PATCH v2] diff: vary default prefix depending on what are compared Junio C Hamano
2008-08-20  9:06                     ` Jakub Narebski
2008-08-19  6:28             ` Call Me Gitless Stephen R. van den Berg
2008-08-19 11:42             ` Jakub Narebski
2008-08-19 18:18               ` Junio C Hamano
2008-08-19 17:52             ` Jeff King
2008-08-19 18:39               ` Daniel Barkalow
2008-08-19 18:45                 ` Jeff King
2008-08-19 18:57                   ` Daniel Barkalow
2008-08-19 19:01                     ` Jeff King
2008-08-19 19:42                       ` Daniel Barkalow
2008-08-19 20:33                         ` Petr Baudis
2008-08-19 21:49                           ` Daniel Barkalow
2008-08-19 19:43               ` Junio C Hamano
2008-08-19  7:25       ` Junio C Hamano
2008-08-19 19:22         ` Daniel Barkalow
2008-08-21  3:40       ` Sverre Hvammen Johansen
2008-08-21  8:41       ` Junio C Hamano
2008-08-21  8:43         ` [PATCH 1/3] sha1_object_info(): pay attention to cached objects Junio C Hamano
2008-08-21  8:43         ` [PATCH 2/3] cached_object: learn empty blob Junio C Hamano
2008-08-21  8:44         ` [PATCH 3/3] git-add --intent-to-add (-N) Junio C Hamano
2008-08-21 14:23           ` Paolo Bonzini
2008-08-21 21:14           ` Jonathan Nieder
2008-08-22  4:10             ` Jonathan Nieder
2008-08-22  4:34               ` Daniel Barkalow
2008-08-22  4:59                 ` Junio C Hamano
2008-08-22  5:32                 ` Jonathan Nieder
2008-08-22  5:59                   ` Junio C Hamano
2008-08-22  6:38                     ` Jonathan Nieder
2008-08-22  7:52                       ` Jonathan Nieder [this message]
2008-08-21 13:58         ` Call Me Gitless Daniel Barkalow
2008-08-18 23:24     ` Tarmigan
2008-08-19  0:32       ` Daniel Barkalow
2008-08-19  0:45         ` Tarmigan
2008-08-19  7:53       ` "Peter Valdemar Mørch (Lists)"
2008-08-19  8:01         ` Junio C Hamano
2008-08-19  8:10           ` Imran M Yousuf
2008-08-19  8:26             ` "Peter Valdemar Mørch (Lists)"
2008-08-19  8:53               ` Imran M Yousuf
2008-08-19  8:57           ` Alexander E Genaud
2008-08-19  9:11             ` Matthieu Moy
2008-08-19  9:36               ` Mike Hommey
2008-08-19 10:09               ` Alexander E Genaud
2008-08-19 11:27                 ` Pascal Obry
2008-08-21 14:15                   ` Paolo Bonzini
2008-08-22 19:10                     ` Elijah Newren
2008-08-19 10:16               ` "Peter Valdemar Mørch (Lists)"
2008-08-19 11:31             ` Mark Struberg
2008-08-19 12:04               ` Alexander E Genaud
2008-08-19 18:15                 ` Junio C Hamano
2008-08-19  8:56         ` Teemu Likonen
2008-08-19 13:15 ` Jakub Narebski

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=Pine.GSO.4.62.0808220150410.13589@harper.uchicago.edu \
    --to=jrnieder@uchicago.edu \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).