git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Karsten Blees <karsten.blees@gmail.com>
To: Git List <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Cc: Thomas Rast <tr@thomasrast.ch>,
	Jens Lehmann <Jens.Lehmann@web.de>,
	Karsten Blees <karsten.blees@gmail.com>
Subject: [PATCH v5 13/14] builtin/update-index.c: cleanup update_one
Date: Thu, 14 Nov 2013 20:24:08 +0100	[thread overview]
Message-ID: <52852358.9020808@gmail.com> (raw)
In-Reply-To: <52851FB5.4050406@gmail.com>

do_reupdate calls update_one with a cache_entry.name, there's no need for
the extra sanitation / normalization that happens in prefix_path.
cmd_update_index calls update_one with an already prefixed path, no need to
prefix_path twice.

Remove the extra prefix_path from update_one. Also remove the now unused
'prefix' and 'prefix_length' parameters.

As of d089eba "setup: sanitize absolute and funny paths in get_pathspec()",
prefix_path uncoditionally returns a copy, even if the passed in path isn't
changed. Lets unconditionally free() the result.

Signed-off-by: Karsten Blees <blees@dcon.de>
---
 builtin/update-index.c | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index d180d80..c8f0d5f 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -274,36 +274,32 @@ static void chmod_path(int flip, const char *path)
 	die("git update-index: cannot chmod %cx '%s'", flip, path);
 }
 
-static void update_one(const char *path, const char *prefix, int prefix_length)
+static void update_one(const char *path)
 {
-	const char *p = prefix_path(prefix, prefix_length, path);
-	if (!verify_path(p)) {
+	if (!verify_path(path)) {
 		fprintf(stderr, "Ignoring path %s\n", path);
-		goto free_return;
+		return;
 	}
 	if (mark_valid_only) {
-		if (mark_ce_flags(p, CE_VALID, mark_valid_only == MARK_FLAG))
+		if (mark_ce_flags(path, CE_VALID, mark_valid_only == MARK_FLAG))
 			die("Unable to mark file %s", path);
-		goto free_return;
+		return;
 	}
 	if (mark_skip_worktree_only) {
-		if (mark_ce_flags(p, CE_SKIP_WORKTREE, mark_skip_worktree_only == MARK_FLAG))
+		if (mark_ce_flags(path, CE_SKIP_WORKTREE, mark_skip_worktree_only == MARK_FLAG))
 			die("Unable to mark file %s", path);
-		goto free_return;
+		return;
 	}
 
 	if (force_remove) {
-		if (remove_file_from_cache(p))
+		if (remove_file_from_cache(path))
 			die("git update-index: unable to remove %s", path);
 		report("remove '%s'", path);
-		goto free_return;
+		return;
 	}
-	if (process_path(p))
+	if (process_path(path))
 		die("Unable to process path %s", path);
 	report("add '%s'", path);
- free_return:
-	if (p < path || p > path + strlen(path))
-		free((char *)p);
 }
 
 static void read_index_info(int line_termination)
@@ -579,7 +575,7 @@ static int do_reupdate(int ac, const char **av,
 		 * or worse yet 'allow_replace', active_nr may decrease.
 		 */
 		save_nr = active_nr;
-		update_one(ce->name, NULL, 0);
+		update_one(ce->name);
 		if (save_nr != active_nr)
 			goto redo;
 	}
@@ -836,11 +832,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 
 			setup_work_tree();
 			p = prefix_path(prefix, prefix_length, path);
-			update_one(p, NULL, 0);
+			update_one(p);
 			if (set_executable_bit)
 				chmod_path(set_executable_bit, p);
-			if (p < path || p > path + strlen(path))
-				free((char *)p);
+			free((char *)p);
 			ctx.argc--;
 			ctx.argv++;
 			break;
@@ -879,11 +874,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 				strbuf_swap(&buf, &nbuf);
 			}
 			p = prefix_path(prefix, prefix_length, buf.buf);
-			update_one(p, NULL, 0);
+			update_one(p);
 			if (set_executable_bit)
 				chmod_path(set_executable_bit, p);
-			if (p < buf.buf || p > buf.buf + buf.len)
-				free((char *)p);
+			free((char *)p);
 		}
 		strbuf_release(&nbuf);
 		strbuf_release(&buf);
-- 
1.8.5.rc0.333.g5394214

  parent reply	other threads:[~2013-11-14 19:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-14 19:08 [PATCH v5 00/14] New hash table implementation Karsten Blees
2013-11-14 19:17 ` [PATCH v5 01/14] submodule: don't access the .gitmodules cache entry after removing it Karsten Blees
2013-11-14 19:17 ` [PATCH v5 02/14] add a hashtable implementation that supports O(1) removal Karsten Blees
2013-12-14  2:04   ` Jonathan Nieder
2013-12-14  2:05     ` [PATCH 1/2] Add test-hashmap to .gitignore Jonathan Nieder
2013-12-14  2:06     ` [PATCH 2/2] Drop unnecessary #includes from test-hashmap Jonathan Nieder
2013-12-18 13:11     ` [PATCH v5 02/14] add a hashtable implementation that supports O(1) removal Karsten Blees
2013-11-14 19:18 ` [PATCH v5 03/14] buitin/describe.c: use new hash map implementation Karsten Blees
2013-11-14 19:19 ` [PATCH v5 04/14] diffcore-rename.c: move code around to prepare for the next patch Karsten Blees
2013-11-14 19:19 ` [PATCH v5 05/14] diffcore-rename.c: simplify finding exact renames Karsten Blees
2013-11-14 19:20 ` [PATCH v5 06/14] diffcore-rename.c: use new hash map implementation Karsten Blees
2013-11-14 19:20 ` [PATCH v5 07/14] name-hash.c: use new hash map implementation for directories Karsten Blees
2013-11-14 19:21 ` [PATCH v5 08/14] name-hash.c: remove unreferenced directory entries Karsten Blees
2013-11-14 19:21 ` [PATCH v5 09/14] name-hash.c: use new hash map implementation for cache entries Karsten Blees
2013-11-14 19:22 ` [PATCH v5 10/14] name-hash.c: remove cache entries instead of marking them CE_UNHASHED Karsten Blees
2013-11-14 19:23 ` [PATCH v5 11/14] remove old hash.[ch] implementation Karsten Blees
2013-11-14 19:23 ` [PATCH v5 12/14] fix 'git update-index --verbose --again' output Karsten Blees
2013-11-14 19:24 ` Karsten Blees [this message]
2013-11-14 19:24 ` [PATCH v5 14/14] read-cache.c: fix memory leaks caused by removed cache entries Karsten Blees
2013-11-14 22:07 ` [PATCH v5 00/14] New hash table implementation Karsten Blees

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=52852358.9020808@gmail.com \
    --to=karsten.blees@gmail.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=tr@thomasrast.ch \
    /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).