pack-objects: factor out name_hash
As the pack-objects system grows beyond the single pack-objects.c file, more parts (like the soon-to-exist bitmap code) will need to compute hashes for matching deltas. Factor out name_hash to make it available to other files. Signed-off-by: Vicent Marti <tanoku@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Vicent Marti committed
Oct 24, 2013 at 14:01 UTC
68fb36eb92ff98ec81a066592a07b3f411450a1d
2 files changed
+22
-22
builtin/pack-objects.c
+2
-22
@@ -778,26 +778,6 @@ static void write_pack_file(void)
778
written, nr_result);
779
}
780
781
-static uint32_t name_hash(const char *name)
782
-{
783
- uint32_t c, hash = 0;
784
-
785
- if (!name)
786
- return 0;
787
-
788
- /*
789
- * This effectively just creates a sortable number from the
790
- * last sixteen non-whitespace characters. Last characters
791
- * count "most", so things that end in ".c" sort together.
792
- */
793
- while ((c = *name++) != 0) {
794
- if (isspace(c))
795
- continue;
796
- hash = (hash >> 2) + (c << 24);
797
- }
798
- return hash;
799
-}
800
-
781
static void setup_delta_attr_check(struct git_attr_check *check)
782
{
783
static struct git_attr *attr_delta;
@@ -826,7 +806,7 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
806
struct object_entry *entry;
807
struct packed_git *p, *found_pack = NULL;
808
off_t found_offset = 0;
829
- uint32_t hash = name_hash(name);
809
+ uint32_t hash = pack_name_hash(name);
810
uint32_t index_pos;
811
812
entry = packlist_find(&to_pack, sha1, &index_pos);
@@ -1082,7 +1062,7 @@ static void add_preferred_base_object(const char *name)
1062
{
1063
struct pbase_tree *it;
1064
int cmplen;
1085
- unsigned hash = name_hash(name);
1065
+ unsigned hash = pack_name_hash(name);
1066
1067
if (!num_preferred_base || check_pbase_path(hash))
1068
return;
pack-objects.h
+20
@@ -44,4 +44,24 @@ struct object_entry *packlist_find(struct packing_data *pdata,
44
const unsigned char *sha1,
45
uint32_t *index_pos);
46
47
+static inline uint32_t pack_name_hash(const char *name)
48
+{
49
+ uint32_t c, hash = 0;
50
+
51
+ if (!name)
52
+ return 0;
53
+
54
+ /*
55
+ * This effectively just creates a sortable number from the
56
+ * last sixteen non-whitespace characters. Last characters
57
+ * count "most", so things that end in ".c" sort together.
58
+ */
59
+ while ((c = *name++) != 0) {
60
+ if (isspace(c))
61
+ continue;
62
+ hash = (hash >> 2) + (c << 24);
63
+ }
64
+ return hash;
65
+}
66
+
67
#endif