Commit 1648fbd34457c287ffb961457349689c67f3ad97

Vicent Marti 2011-05-02T01:12:53

Re-apply missing patches

diff --git a/include/git2/index.h b/include/git2/index.h
index 98a17a1..7991de9 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -51,39 +51,29 @@ GIT_BEGIN_DECL
  *
  * In-memory only flags:
  */
-#define GIT_IDXENTRY_UPDATE            (1 << 16)
-#define GIT_IDXENTRY_REMOVE            (1 << 17)
-#define GIT_IDXENTRY_UPTODATE          (1 << 18)
-#define GIT_IDXENTRY_ADDED             (1 << 19)
+#define GIT_IDXENTRY_UPDATE            (1 << 0)
+#define GIT_IDXENTRY_REMOVE            (1 << 1)
+#define GIT_IDXENTRY_UPTODATE          (1 << 2)
+#define GIT_IDXENTRY_ADDED             (1 << 3)
 
-#define GIT_IDXENTRY_HASHED            (1 << 20)
-#define GIT_IDXENTRY_UNHASHED          (1 << 21)
-#define GIT_IDXENTRY_WT_REMOVE         (1 << 22) /* remove in work directory */
-#define GIT_IDXENTRY_CONFLICTED        (1 << 23)
+#define GIT_IDXENTRY_HASHED            (1 << 4)
+#define GIT_IDXENTRY_UNHASHED          (1 << 5)
+#define GIT_IDXENTRY_WT_REMOVE         (1 << 6) /* remove in work directory */
+#define GIT_IDXENTRY_CONFLICTED        (1 << 7)
 
-#define GIT_IDXENTRY_UNPACKED          (1 << 24)
-#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 25)
+#define GIT_IDXENTRY_UNPACKED          (1 << 8)
+#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9)
 
 /*
  * Extended on-disk flags:
  */
-#define GIT_IDXENTRY_INTENT_TO_ADD     (1 << 29)
-#define GIT_IDXENTRY_SKIP_WORKTREE     (1 << 30)
+#define GIT_IDXENTRY_INTENT_TO_ADD     (1 << 13)
+#define GIT_IDXENTRY_SKIP_WORKTREE     (1 << 14)
 /* GIT_IDXENTRY_EXTENDED2 is for future extension */
-#define GIT_IDXENTRY_EXTENDED2         (1 << 31)
+#define GIT_IDXENTRY_EXTENDED2         (1 << 15)
 
 #define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE)
 
-/*
- * Safeguard to avoid saving wrong flags:
- *  - GIT_IDXENTRY_EXTENDED2 won't get saved until its semantic is known
- *  - Bits in 0x0000FFFF have been saved in flags already
- *  - Bits in 0x003F0000 are currently in-memory flags
- */
-#if GIT_IDXENTRY_EXTENDED_FLAGS & 0x803FFFFF
-#error "GIT_IDXENTRY_EXTENDED_FLAGS out of range"
-#endif
-
 /** Time used in a git index entry */
 typedef struct {
 	git_time_t seconds;
diff --git a/src/index.c b/src/index.c
index 850f5de..130d1fd 100644
--- a/src/index.c
+++ b/src/index.c
@@ -101,6 +101,7 @@ static int read_tree(git_index *index, const char *buffer, size_t buffer_size);
 static git_index_tree *read_tree_internal(const char **, const char *, git_index_tree *);
 
 static int parse_index(git_index *index, const char *buffer, size_t buffer_size);
+static int is_index_extended(git_index *index);
 static void sort_index(git_index *index);
 static int write_index(git_index *index, git_filebuf *file);
 
@@ -718,6 +719,24 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
 	return GIT_SUCCESS;
 }
 
+static int is_index_extended(git_index *index)
+{
+	unsigned int i, extended;
+
+	extended = 0;
+
+	for (i = 0; i < index->entries.length; ++i) {
+		git_index_entry *entry;
+		entry = git_vector_get(&index->entries, i);
+		entry->flags &= ~GIT_IDXENTRY_EXTENDED;
+		if (entry->flags_extended & GIT_IDXENTRY_EXTENDED_FLAGS) {
+			extended++;
+			entry->flags |= GIT_IDXENTRY_EXTENDED;
+		}
+	}
+	return extended;
+}
+
 static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
 {
 	struct entry_short *ondisk;
@@ -786,12 +805,14 @@ static int write_index(git_index *index, git_filebuf *file)
 
 	struct index_header header;
 
-	int is_extended = 1;
+	int is_extended;
 
 	assert(index && file);
 
+	is_extended = is_index_extended(index);
+
 	header.signature = htonl(INDEX_HEADER_SIG);
-	header.version = htonl(is_extended ? INDEX_VERSION_NUMBER : INDEX_VERSION_NUMBER_EXT);
+	header.version = htonl(is_extended ? INDEX_VERSION_NUMBER_EXT : INDEX_VERSION_NUMBER);
 	header.entry_count = htonl(index->entries.length);
 
 	git_filebuf_write(file, &header, sizeof(struct index_header));
diff --git a/src/refs.c b/src/refs.c
index e5fc79d..8c84540 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -787,6 +787,8 @@ static int packed_find_peel(reference_oid *ref)
 		 */
 	}
 
+	git_object_close(object);
+
 	return GIT_SUCCESS;
 }