List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [PATCH 1/1] git: update to v2.12.0
Date: Sat, 4 Mar 2017 12:22:46 +0000	[thread overview]
Message-ID: <20170304122246.GB2102@john.keeping.me.uk> (raw)
In-Reply-To: <20170301105755.12125-1-list@eworm.de>

On Wed, Mar 01, 2017 at 11:57:55AM +0100, Christian Hesse wrote:
> From: Christian Hesse <mail at eworm.de>
> 
> 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 <mail at eworm.de>
> ---
>  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 <john at keeping.me.uk>
---
 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



  reply	other threads:[~2017-03-04 12:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-01 10:57 list
2017-03-04 12:22 ` john [this message]
2017-06-06 14:12   ` list

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170304122246.GB2102@john.keeping.me.uk \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).