From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Sat, 4 Mar 2017 12:22:46 +0000 Subject: [PATCH 1/1] git: update to v2.12.0 In-Reply-To: <20170301105755.12125-1-list@eworm.de> References: <20170301105755.12125-1-list@eworm.de> Message-ID: <20170304122246.GB2102@john.keeping.me.uk> On Wed, Mar 01, 2017 at 11:57:55AM +0100, Christian Hesse wrote: > From: Christian Hesse > > Update to git version v2.12.0: With commit 8aee769f (pathspec: copy and free > owned memory) member 'match' of 'struct pathspec_item' is no longer > 'const char*' but just 'char*'. > > Signed-off-by: Christian Hesse > --- > Makefile | 2 +- > cgit.h | 4 ++-- > git | 2 +- > shared.c | 4 ++-- > ui-blob.c | 2 +- > ui-blob.h | 2 +- > ui-commit.c | 2 +- > ui-commit.h | 2 +- > ui-diff.c | 4 ++-- > ui-diff.h | 2 +- > 10 files changed, 13 insertions(+), 13 deletions(-) This feels a bit invasive for a change that just affects pathspec_item. Can't we keep most of CGit's API the same (and keep prefixes "const") and just adjust at the lowest level? Maybe something like this instead? -- >8 -- The definition of struct pathspec_item has changed with the expectation that pathspecs will be managed dynamically. We work around this a bit by setting up a static structure, but let's allocate the match string to avoid needing to cast away const. Signed-off-by: John Keeping --- shared.c | 4 +++- ui-blob.c | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) --- a/shared.c +++ b/shared.c @@ -352,7 +352,7 @@ void cgit_diff_tree(const struct object_id *old_oid, opt.format_callback = cgit_diff_tree_cb; opt.format_callback_data = fn; if (prefix) { - item.match = prefix; + item.match = xstrdup(prefix); item.len = strlen(prefix); opt.pathspec.nr = 1; opt.pathspec.items = &item; @@ -365,6 +365,8 @@ void cgit_diff_tree(const struct object_id *old_oid, diff_root_tree_sha1(new_oid->hash, "", &opt); diffcore_std(&opt); diff_flush(&opt); + + free(item.match); } void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix) diff --git a/ui-blob.c b/ui-blob.c index 5f30de7..793817f 100644 --- a/ui-blob.c +++ b/ui-blob.c @@ -38,7 +38,7 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) struct object_id oid; unsigned long size; struct pathspec_item path_items = { - .match = path, + .match = xstrdup(path), .len = strlen(path) }; struct pathspec paths = { @@ -53,10 +53,13 @@ int cgit_ref_path_exists(const char *path, const char *ref, int file_only) }; if (get_oid(ref, &oid)) - return 0; + goto done; if (sha1_object_info(oid.hash, &size) != OBJ_COMMIT) - return 0; + goto done; read_tree_recursive(lookup_commit_reference(oid.hash)->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); + +done: + free(path_items.match); return walk_tree_ctx.found_path; } -- 2.12.0.rc2.230.ga28edc07cd