From: "Sun Chao via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Sun Chao <16657101987@163.com>, Sun Chao <16657101987@163.com>
Subject: [PATCH v4 1/2] packfile: rename `derive_filename()` to `derive_pack_filename()`
Date: Sun, 15 Aug 2021 17:08:46 +0000 [thread overview]
Message-ID: <81afc69d22c0c782eea80719557161ae19a4f72e.1629047327.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1043.v4.git.git.1629047327.gitgitgadget@gmail.com>
From: Sun Chao <16657101987@163.com>
In order to allow some function get a new file name from `.pack` file
with a new suffix, move `derive_filename()` in `builtin/index-pack.c`
to `packfile.c` with a new name `derive_pack_filename(), and export
it from `packfile.h`.
Signed-off-by: Sun Chao <16657101987@163.com>
---
builtin/index-pack.c | 19 +++----------------
packfile.c | 13 +++++++++++++
packfile.h | 7 +++++++
3 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 8336466865c..3c83789ccef 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1435,19 +1435,6 @@ static void fix_unresolved_deltas(struct hashfile *f)
free(sorted_by_pos);
}
-static const char *derive_filename(const char *pack_name, const char *strip,
- const char *suffix, struct strbuf *buf)
-{
- size_t len;
- if (!strip_suffix(pack_name, strip, &len) || !len ||
- pack_name[len - 1] != '.')
- die(_("packfile name '%s' does not end with '.%s'"),
- pack_name, strip);
- strbuf_add(buf, pack_name, len);
- strbuf_addstr(buf, suffix);
- return buf->buf;
-}
-
static void write_special_file(const char *suffix, const char *msg,
const char *pack_name, const unsigned char *hash,
const char **report)
@@ -1458,7 +1445,7 @@ static void write_special_file(const char *suffix, const char *msg,
int msg_len = strlen(msg);
if (pack_name)
- filename = derive_filename(pack_name, "pack", suffix, &name_buf);
+ filename = derive_pack_filename(pack_name, "pack", suffix, &name_buf);
else
filename = odb_pack_name(&name_buf, hash, suffix);
@@ -1853,13 +1840,13 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
if (from_stdin && hash_algo)
die(_("--object-format cannot be used with --stdin"));
if (!index_name && pack_name)
- index_name = derive_filename(pack_name, "pack", "idx", &index_name_buf);
+ index_name = derive_pack_filename(pack_name, "pack", "idx", &index_name_buf);
opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
if (rev_index) {
opts.flags |= verify ? WRITE_REV_VERIFY : WRITE_REV;
if (index_name)
- rev_index_name = derive_filename(index_name,
+ rev_index_name = derive_pack_filename(index_name,
"idx", "rev",
&rev_index_name_buf);
}
diff --git a/packfile.c b/packfile.c
index 9ef6d982928..315c3da259a 100644
--- a/packfile.c
+++ b/packfile.c
@@ -40,6 +40,19 @@ char *sha1_pack_index_name(const unsigned char *sha1)
return odb_pack_name(&buf, sha1, "idx");
}
+const char *derive_pack_filename(const char *pack_name, const char *strip,
+ const char *suffix, struct strbuf *buf)
+{
+ size_t len;
+ if (!strip_suffix(pack_name, strip, &len) || !len ||
+ pack_name[len - 1] != '.')
+ die(_("packfile name '%s' does not end with '.%s'"),
+ pack_name, strip);
+ strbuf_add(buf, pack_name, len);
+ strbuf_addstr(buf, suffix);
+ return buf->buf;
+}
+
static unsigned int pack_used_ctr;
static unsigned int pack_mmap_calls;
static unsigned int peak_pack_open_windows;
diff --git a/packfile.h b/packfile.h
index 3ae117a8aef..ff702b22e6a 100644
--- a/packfile.h
+++ b/packfile.h
@@ -31,6 +31,13 @@ char *sha1_pack_name(const unsigned char *sha1);
*/
char *sha1_pack_index_name(const unsigned char *sha1);
+/*
+ * Return the corresponding filename with given suffix from "file_name"
+ * which must has "strip" suffix.
+ */
+const char *derive_pack_filename(const char *file_name, const char *strip,
+ const char *suffix, struct strbuf *buf);
+
/*
* Return the basename of the packfile, omitting any containing directory
* (e.g., "pack-1234abcd[...].pack").
--
gitgitgadget
next prev parent reply other threads:[~2021-08-15 17:09 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-10 19:01 [PATCH] packfile: enhance the mtime of packfile by idx file Sun Chao via GitGitGadget
2021-07-11 23:44 ` Ævar Arnfjörð Bjarmason
2021-07-12 16:17 ` Sun Chao
2021-07-14 1:28 ` [PATCH v2] packfile: freshen the mtime of packfile by configuration Sun Chao via GitGitGadget
2021-07-14 1:39 ` Ævar Arnfjörð Bjarmason
2021-07-14 2:52 ` Taylor Blau
2021-07-14 16:46 ` Sun Chao
2021-07-14 17:04 ` Taylor Blau
2021-07-14 18:19 ` Ævar Arnfjörð Bjarmason
2021-07-14 19:11 ` Martin Fick
2021-07-14 19:41 ` Ævar Arnfjörð Bjarmason
2021-07-14 20:20 ` Martin Fick
2021-07-20 6:32 ` Ævar Arnfjörð Bjarmason
2021-07-15 8:23 ` Son Luong Ngoc
2021-07-20 6:29 ` Ævar Arnfjörð Bjarmason
2021-07-14 19:30 ` Taylor Blau
2021-07-14 19:32 ` Ævar Arnfjörð Bjarmason
2021-07-14 19:52 ` Taylor Blau
2021-07-14 21:40 ` Junio C Hamano
2021-07-15 16:30 ` Sun Chao
2021-07-15 16:42 ` Taylor Blau
2021-07-15 16:48 ` Sun Chao
2021-07-14 16:11 ` Sun Chao
2021-07-19 19:53 ` [PATCH v3] " Sun Chao via GitGitGadget
2021-07-19 20:51 ` Taylor Blau
2021-07-20 0:07 ` Junio C Hamano
2021-07-20 15:07 ` Sun Chao
2021-07-20 6:19 ` Ævar Arnfjörð Bjarmason
2021-07-20 15:34 ` Sun Chao
2021-07-20 15:00 ` Sun Chao
2021-07-20 16:53 ` Taylor Blau
2021-08-15 17:08 ` [PATCH v4 0/2] " Sun Chao via GitGitGadget
2021-08-15 17:08 ` Sun Chao via GitGitGadget [this message]
2021-08-15 17:08 ` [PATCH v4 2/2] packfile: freshen the mtime of packfile by bump file Sun Chao via GitGitGadget
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=81afc69d22c0c782eea80719557161ae19a4f72e.1629047327.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=16657101987@163.com \
--cc=git@vger.kernel.org \
/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).