@matheusbsbs / matheus-bagliano / commits / 69e74e7412
Fork 0

Correct packfile edge output in fast-import.

Branches are only contained by a packfile if the branch actually had its most recent commit in that packfile. So new branches are set to MAX_PACK_ID to ensure they don't cause their commit to list as part of the first packfile when it closes out if the commit was actually in existance before fast-import started. Also corrected the type of last_commit to be umaxint_t to prevent overflow and wraparound on very large imports. Though that is highly unlikely to occur as we're talking 4 billion commits, which no real project has right now. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 17, 2007 at 02:42 UTC 69e74e7412603dd536695c3d6a397673e8ae2bd2
1 file changed +15 -8
fast-import.c
+15 -8
@@ -111,12 +111,15 @@ Format of STDIN stream:
111 #include "strbuf.h"
112 #include "quote.h"
113
114 +#define PACK_ID_BITS 16
115 +#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
116 +
117 struct object_entry
118 {
119 struct object_entry *next;
120 unsigned long offset;
121 unsigned type : TYPE_BITS;
119 - unsigned pack_id : 16;
122 + unsigned pack_id : PACK_ID_BITS;
123 unsigned char sha1[20];
124 };
125
@@ -193,7 +196,7 @@ struct branch
196 struct branch *active_next_branch;
197 const char *name;
198 struct tree_entry branch_tree;
196 - unsigned long last_commit;
199 + uintmax_t last_commit;
200 unsigned int pack_id;
201 unsigned char sha1[20];
202 };
@@ -494,6 +497,7 @@ static struct branch* new_branch(const char *name)
497 b->table_next_branch = branch_table[hc];
498 b->branch_tree.versions[0].mode = S_IFDIR;
499 b->branch_tree.versions[1].mode = S_IFDIR;
500 + b->pack_id = MAX_PACK_ID;
501 branch_table[hc] = b;
502 branch_count++;
503 return b;
@@ -1696,11 +1700,11 @@ static void cmd_new_commit(void)
1700 free(committer);
1701 free(msg);
1702
1699 - store_object(OBJ_COMMIT,
1703 + if (!store_object(OBJ_COMMIT,
1704 new_data.buffer, sp - (char*)new_data.buffer,
1701 - NULL, b->sha1, next_mark);
1705 + NULL, b->sha1, next_mark))
1706 + b->pack_id = pack_id;
1707 b->last_commit = object_count_by_type[OBJ_COMMIT];
1703 - b->pack_id = pack_id;
1708
1709 if (branch_log) {
1710 int need_dq = quote_c_style(b->name, NULL, NULL, 0);
@@ -1807,9 +1811,12 @@ static void cmd_new_tag(void)
1811 free(tagger);
1812 free(msg);
1813
1810 - store_object(OBJ_TAG, new_data.buffer, sp - (char*)new_data.buffer,
1811 - NULL, t->sha1, 0);
1812 - t->pack_id = pack_id;
1814 + if (store_object(OBJ_TAG, new_data.buffer,
1815 + sp - (char*)new_data.buffer,
1816 + NULL, t->sha1, 0))
1817 + t->pack_id = MAX_PACK_ID;
1818 + else
1819 + t->pack_id = pack_id;
1820
1821 if (branch_log) {
1822 int need_dq = quote_c_style(t->name, NULL, NULL, 0);