This is similar to is_bundle, but checks an in-memory buffer rather than a file. It also works on a partial buffer, checking only the bundle signature. This means the result is a three-way conditional: yes, no, or "we do not have enough data yet". Signed-off-by: Jeff King <peff@xxxxxxxx> --- bundle.c | 14 ++++++++++++++ bundle.h | 1 + 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/bundle.c b/bundle.c index e48fe2f..6f911bc 100644 --- a/bundle.c +++ b/bundle.c @@ -122,6 +122,20 @@ int is_bundle(const char *path, int quiet) return (fd >= 0); } +int is_bundle_buf(const char *s, int len) +{ + if (len > strlen(bundle_signature)) + len = strlen(bundle_signature); + /* If we don't match what we already have, then definitely not. */ + if (memcmp(s, bundle_signature, len)) + return 0; + /* If we have enough bytes, we can say yes */ + if (len == strlen(bundle_signature)) + return 1; + /* otherwise, we can only say "maybe" */ + return -1; +} + static int list_refs(struct ref_list *r, int argc, const char **argv) { int i; diff --git a/bundle.h b/bundle.h index 675cc97..8bec44d 100644 --- a/bundle.h +++ b/bundle.h @@ -15,6 +15,7 @@ struct bundle_header { }; int is_bundle(const char *path, int quiet); +int is_bundle_buf(const char *s, int len); int read_bundle_header(const char *path, struct bundle_header *header); int create_bundle(struct bundle_header *header, const char *path, int argc, const char **argv); -- 1.7.7.2.7.g9f96f -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html