Skip to content

Commit

Permalink
Just hash pointers and keep objects around, instead of hashing SHA-1s
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Jun 4, 2010
1 parent 71bacea commit f191c66
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
6 changes: 4 additions & 2 deletions arrowstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using namespace std;
using namespace std::tr1;

typedef unordered_multimap<string, string> arrow_map_t;
class GitObject;

typedef unordered_multimap<GitObject *, GitObject *> arrow_map_t;

class ArrowStore
{
Expand All @@ -18,7 +20,7 @@ class ArrowStore
ArrowStore( void ) {}
~ArrowStore() {}

void add( string src, string dest )
void add( GitObject *src, GitObject *dest )
{
arrow_map.insert( arrow_map_t::value_type( dest, src ) );
}
Expand Down
2 changes: 1 addition & 1 deletion deltadb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int DeltaDB::recursive_traverse( GitObject *obj, GitObject *parent, GitObject *b
obj->inflate_object();
obj->apply_delta( parent );

base->parse( obj, arrows );
base->parse( obj, arrows, this );

int size = obj->get_delta_decoded_size();

Expand Down
3 changes: 1 addition & 2 deletions gitflip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ int main( int argc, char *argv[] )
char *pack_filename = argv[ 1 ];
char *idx_filename = argv[ 2 ];

ArrowStore *arrows = new ArrowStore();

try {
ArrowStore *arrows = new ArrowStore();
Pack *pack = new Pack( pack_filename, idx_filename );
DeltaDB *deltas = new DeltaDB( pack, arrows );

Expand Down
12 changes: 6 additions & 6 deletions objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,31 @@ class GitObject
return delta_decoded_data + index;
}

virtual void parse( GitObject *obj, ArrowStore *arrows ) = 0;
virtual void parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db ) = 0;
};

class Commit : public GitObject
{
public:
void parse( GitObject *obj, ArrowStore *arrows );
void parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db );
};

class Tree : public GitObject
{
public:
void parse( GitObject *obj, ArrowStore *arrows );
void parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db );
};

class Blob : public GitObject
{
public:
void parse( GitObject *obj, ArrowStore *arrows );
void parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db );
};

class Tag : public GitObject
{
public:
void parse( GitObject *obj, ArrowStore *arrows );
void parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db );
};

class Delta : public GitObject
Expand All @@ -170,7 +170,7 @@ class Delta : public GitObject
Delta() : reference_object( NULL ) {}
GitObject* get_reference( void ) const { return reference_object; }
void apply_delta( GitObject *parent );
void parse( GitObject *obj, ArrowStore *arrows );
void parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db );
};

class Ofs_Delta : public Delta
Expand Down
19 changes: 10 additions & 9 deletions objparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

#include "objects.hpp"
#include "arrowstore.hpp"
#include "deltadb.hpp"

/* These are member functions of the base object in a delta chain.
They parse either the base object or a derived, decoded delta,
based on its type. (A delta doesn't know its own type.)
*/

void Commit::parse( GitObject *obj, ArrowStore *arrows )
void Commit::parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db )
{
/* confirm "tree" */
unixassert( strncmp( (char *)obj->get_buf( 0, 5 ), "tree ", 5 ) );
sha1 tree;
tree.read( obj->get_buf( 5, 40 ) );
arrows->add( obj->get_hash()->str(), tree.str() );
arrows->add( obj, db->lookup_hash( tree ) );

/* get as many parents as are present */
/* we assume every commit has an author and commiter,
Expand All @@ -24,12 +25,12 @@ void Commit::parse( GitObject *obj, ArrowStore *arrows )
while ( 0 == strncmp( (char *)obj->get_buf( i, 7 ), "parent ", 7 ) ) {
sha1 parent;
parent.read( obj->get_buf( i + 7, 40 ) );
arrows->add( obj->get_hash()->str(), parent.str() );
arrows->add( obj, db->lookup_hash( parent ) );
i += 48;
}
}

void Tree::parse( GitObject *obj, ArrowStore *arrows )
void Tree::parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db )
{
/* null bytes signal end of filename, and immediately precede SHA-1 */
/* note tree uses binary SHA-1, unlike ASCII form */
Expand All @@ -48,31 +49,31 @@ void Tree::parse( GitObject *obj, ArrowStore *arrows )
printf( "\n" );
}
sha1 entry( (char *)(obj->get_buf( i + 1, 20 ) ) );
arrows->add( obj->get_hash()->str(), entry.str() );
arrows->add( obj, db->lookup_hash( entry ) );
i += 21;
} else {
i++;
}
}
}

void Tag::parse( GitObject *obj, ArrowStore *arrows )
void Tag::parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db )
{
/* confirm beginning */
unixassert( strncmp( (char *)obj->get_buf( 0, 7 ), "object ", 7 ) );

sha1 reference;
reference.read( obj->get_buf( 7, 40 ) );
arrows->add( obj->get_hash()->str(), reference.str() );
arrows->add( obj, db->lookup_hash( reference ) );
}

void Blob::parse( GitObject *obj, ArrowStore *arrows )
void Blob::parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db )
{
/* We're not interested in these. */
throw InternalError();
}

void Delta::parse( GitObject *obj, ArrowStore *arrows )
void Delta::parse( GitObject *obj, ArrowStore *arrows, const DeltaDB *db )
{
/* Delta should never be the base of a delta chain. */
throw InternalError();
Expand Down
2 changes: 1 addition & 1 deletion templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ template class unordered_map<string, GitObject *>;
template class unordered_map<off_t, GitObject *>;
template class unordered_multimap<GitObject *, GitObject *>;
template class unordered_map<GitObject *, char>;
template class unordered_multimap<string, string>;

0 comments on commit f191c66

Please sign in to comment.