pack: move find_pack_entry() and make it global
This function needs to be global as it is used by sha1_file.c and will be used by packfile.c. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Aug 18, 2017 at 15:20 UTC
1a1e5d4f47fd77dec1b7e7ef0867939a251252b6
3 files changed
+55
-53
packfile.c
+53
@@ -1787,3 +1787,56 @@ struct packed_git *find_sha1_pack(const unsigned char *sha1,
1787
return NULL;
1788
1789
}
1790
+
1791
+static int fill_pack_entry(const unsigned char *sha1,
1792
+ struct pack_entry *e,
1793
+ struct packed_git *p)
1794
+{
1795
+ off_t offset;
1796
+
1797
+ if (p->num_bad_objects) {
1798
+ unsigned i;
1799
+ for (i = 0; i < p->num_bad_objects; i++)
1800
+ if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))
1801
+ return 0;
1802
+ }
1803
+
1804
+ offset = find_pack_entry_one(sha1, p);
1805
+ if (!offset)
1806
+ return 0;
1807
+
1808
+ /*
1809
+ * We are about to tell the caller where they can locate the
1810
+ * requested object. We better make sure the packfile is
1811
+ * still here and can be accessed before supplying that
1812
+ * answer, as it may have been deleted since the index was
1813
+ * loaded!
1814
+ */
1815
+ if (!is_pack_valid(p))
1816
+ return 0;
1817
+ e->offset = offset;
1818
+ e->p = p;
1819
+ hashcpy(e->sha1, sha1);
1820
+ return 1;
1821
+}
1822
+
1823
+/*
1824
+ * Iff a pack file contains the object named by sha1, return true and
1825
+ * store its location to e.
1826
+ */
1827
+int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
1828
+{
1829
+ struct mru_entry *p;
1830
+
1831
+ prepare_packed_git();
1832
+ if (!packed_git)
1833
+ return 0;
1834
+
1835
+ for (p = packed_git_mru->head; p; p = p->next) {
1836
+ if (fill_pack_entry(sha1, e, p->item)) {
1837
+ mru_mark(packed_git_mru, p);
1838
+ return 1;
1839
+ }
1840
+ }
1841
+ return 0;
1842
+}
packfile.h
+2
@@ -118,4 +118,6 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje
118
extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1);
119
extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1);
120
121
+extern int find_pack_entry(const unsigned char *sha1, struct pack_entry *e);
122
+
123
#endif
sha1_file.c
-53
@@ -1075,59 +1075,6 @@ int parse_sha1_header(const char *hdr, unsigned long *sizep)
1075
return parse_sha1_header_extended(hdr, &oi, 0);
1076
}
1077
1078
-static int fill_pack_entry(const unsigned char *sha1,
1079
- struct pack_entry *e,
1080
- struct packed_git *p)
1081
-{
1082
- off_t offset;
1083
-
1084
- if (p->num_bad_objects) {
1085
- unsigned i;
1086
- for (i = 0; i < p->num_bad_objects; i++)
1087
- if (!hashcmp(sha1, p->bad_object_sha1 + 20 * i))
1088
- return 0;
1089
- }
1090
-
1091
- offset = find_pack_entry_one(sha1, p);
1092
- if (!offset)
1093
- return 0;
1094
-
1095
- /*
1096
- * We are about to tell the caller where they can locate the
1097
- * requested object. We better make sure the packfile is
1098
- * still here and can be accessed before supplying that
1099
- * answer, as it may have been deleted since the index was
1100
- * loaded!
1101
- */
1102
- if (!is_pack_valid(p))
1103
- return 0;
1104
- e->offset = offset;
1105
- e->p = p;
1106
- hashcpy(e->sha1, sha1);
1107
- return 1;
1108
-}
1109
-
1110
-/*
1111
- * Iff a pack file contains the object named by sha1, return true and
1112
- * store its location to e.
1113
- */
1114
-static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
1115
-{
1116
- struct mru_entry *p;
1117
-
1118
- prepare_packed_git();
1119
- if (!packed_git)
1120
- return 0;
1121
-
1122
- for (p = packed_git_mru->head; p; p = p->next) {
1123
- if (fill_pack_entry(sha1, e, p->item)) {
1124
- mru_mark(packed_git_mru, p);
1125
- return 1;
1126
- }
1127
- }
1128
- return 0;
1129
-}
1130
-
1078
static int sha1_loose_object_info(const unsigned char *sha1,
1079
struct object_info *oi,
1080
int flags)