From: haoyurenzhuxia@gmail.com
To: git@vger.kernel.org
Cc: avarab@gmail.com, me@ttaylorr.com, derrickstolee@github.com,
dyroneteng@gmail.com, Xia XiaoWen <haoyurenzhuxia@gmail.com>
Subject: [RFC PATCH] midx.c: clean up .rev file
Date: Wed, 22 Jun 2022 19:50:14 +0800 [thread overview]
Message-ID: <20220622115014.53754-1-haoyurenzhuxia@gmail.com> (raw)
From: Xia XiaoWen <haoyurenzhuxia@gmail.com>
The command: `git multi-pack-index write --bitmap` will create 3
files in `objects/pack/`:
* multi-pack-index
* multi-pack-index-*.bitmap
* multi-pack-index-*.rev
But if the command is terminated by the user (such as Ctl-C) or
the system, the midx reverse index file (`multi-pack-index-*.rev`)
is not removed and still exists in `objects/pack/`:
$ GIT_TEST_MIDX_WRITE_REV=1 git multi-pack-index write --bitmap
Selecting bitmap commits: 133020, done.
Building bitmaps: 0% (3/331)
^C^C
$ tree objects/pack/
objects/pack/
├── multi-pack-index-3b048d1b965842cd866e10b6ec1a3035dbede0a5.rev
├── pack-b7d425f1b01727d5f364f5d9fbab2d1900fcd5c0.idx
└── pack-b7d425f1b01727d5f364f5d9fbab2d1900fcd5c0.pack
This patch resolves this by adding a cleanup handler to the sigchain.
Signed-off-by: Xia XiaoWen <haoyurenzhuxia@gmail.com>
---
midx.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/midx.c b/midx.c
index 5f0dd386b0..6586051a62 100644
--- a/midx.c
+++ b/midx.c
@@ -17,6 +17,7 @@
#include "refs.h"
#include "revision.h"
#include "list-objects.h"
+#include "sigchain.h"
#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
#define MIDX_VERSION 1
@@ -41,6 +42,8 @@
#define PACK_EXPIRED UINT_MAX
+static struct strbuf rev_filename = STRBUF_INIT;
+
const unsigned char *get_midx_checksum(struct multi_pack_index *m)
{
return m->data + m->data_len - the_hash_algo->rawsz;
@@ -884,21 +887,29 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)
return pack_order;
}
+static void remove_rev_file_on_signal(int signo)
+{
+ if (unlink(rev_filename.buf))
+ die_errno(_("failed to remove %s"), rev_filename.buf);
+
+ sigchain_pop(signo);
+ raise(signo);
+}
+
static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
struct write_midx_context *ctx)
{
- struct strbuf buf = STRBUF_INIT;
const char *tmp_file;
- strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex(midx_hash));
+ strbuf_addf(&rev_filename, "%s-%s.rev", midx_name, hash_to_hex(midx_hash));
tmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,
midx_hash, WRITE_REV);
- if (finalize_object_file(tmp_file, buf.buf))
+ if (finalize_object_file(tmp_file, rev_filename.buf))
die(_("cannot store reverse index file"));
- strbuf_release(&buf);
+ sigchain_push_common(remove_rev_file_on_signal);
}
static void clear_midx_files_ext(const char *object_dir, const char *ext,
--
2.34.1.52.g9efd6505a3.dirty.agit.6.5.6
next reply other threads:[~2022-06-22 11:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-22 11:50 haoyurenzhuxia [this message]
2022-06-22 15:56 ` [RFC PATCH] midx.c: clean up .rev file Ævar Arnfjörð Bjarmason
2022-06-22 17:53 ` Junio C Hamano
2022-06-22 18:13 ` Taylor Blau
2022-06-22 19:58 ` Junio C Hamano
2022-06-22 21:31 ` Taylor Blau
2022-06-27 5:05 ` Xiaowen Xia
2022-06-23 12:38 ` Teng Long
2022-06-27 3:53 ` Xiaowen Xia
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220622115014.53754-1-haoyurenzhuxia@gmail.com \
--to=haoyurenzhuxia@gmail.com \
--cc=avarab@gmail.com \
--cc=derrickstolee@github.com \
--cc=dyroneteng@gmail.com \
--cc=git@vger.kernel.org \
--cc=me@ttaylorr.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).