* [PATCH] Add --path-prefix option to git-fast-import
@ 2009-12-29 12:51 Gisle Aas
2009-12-29 14:06 ` Sverre Rabbelier
2009-12-29 15:08 ` Shawn O. Pearce
0 siblings, 2 replies; 4+ messages in thread
From: Gisle Aas @ 2009-12-29 12:51 UTC (permalink / raw)
To: git; +Cc: gitster, Gisle Aas
From: Gisle Aas <gisle@aas.no>
I found this useful when import multiple external repositories to be merged
into a single git repo. Not having the files be renamed during the merge
made it easier to follow the history of the individual files.
Signed-off-by: Gisle Aas <gisle@aas.no>
---
Documentation/git-fast-import.txt | 6 ++++++
fast-import.c | 24 ++++++++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt
index 288032c..b8f9593 100644
--- a/Documentation/git-fast-import.txt
+++ b/Documentation/git-fast-import.txt
@@ -58,6 +58,12 @@ OPTIONS
Maximum number of branches to maintain active at once.
See ``Memory Utilization'' below for details. Default is 5.
+--path-prefix=<str>:
+ Prepend the given prefix to all the paths imported.
+ This can be used to import stuff into a subdirectory
+ of where the original files where located. Most likely
+ you want <str> to end with a slash.
+
--export-marks=<file>::
Dumps the internal marks table to <file> when complete.
Marks are written one per line as `:markid SHA-1`.
diff --git a/fast-import.c b/fast-import.c
index dd3c99d..32b0d70 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -351,6 +351,8 @@ static struct recent_command *rc_free;
static unsigned int cmd_save = 100;
static uintmax_t next_mark;
static struct strbuf new_data = STRBUF_INIT;
+static const char *path_prefix;
+static size_t path_prefix_len;
static void write_branch_report(FILE *rpt, struct branch *b)
{
@@ -1860,6 +1862,16 @@ static void load_branch(struct branch *b)
}
}
+static const char *path_prefix_prepend(struct strbuf *sb, const char *p)
+{
+ if (p != sb->buf) {
+ strbuf_reset(sb);
+ strbuf_addstr(sb, p);
+ }
+ strbuf_insert(sb, 0, path_prefix, path_prefix_len);
+ return sb->buf;
+}
+
static void file_change_m(struct branch *b)
{
const char *p = command_buf.buf + 2;
@@ -1909,6 +1921,8 @@ static void file_change_m(struct branch *b)
die("Garbage after path in: %s", command_buf.buf);
p = uq.buf;
}
+ if (path_prefix)
+ p = path_prefix_prepend(&uq, p);
if (S_ISGITLINK(mode)) {
if (inline_data)
@@ -1961,6 +1975,8 @@ static void file_change_d(struct branch *b)
die("Garbage after path in: %s", command_buf.buf);
p = uq.buf;
}
+ if (path_prefix)
+ p = path_prefix_prepend(&uq, p);
tree_content_remove(&b->branch_tree, p, NULL);
}
@@ -1984,6 +2000,8 @@ static void file_change_cr(struct branch *b, int rename)
strbuf_add(&s_uq, s, endp - s);
}
s = s_uq.buf;
+ if (path_prefix)
+ s = path_prefix_prepend(&s_uq, s);
endp++;
if (!*endp)
@@ -1996,6 +2014,8 @@ static void file_change_cr(struct branch *b, int rename)
die("Garbage after dest in: %s", command_buf.buf);
d = d_uq.buf;
}
+ if (path_prefix)
+ d = path_prefix_prepend(&d_uq, d);
memset(&leaf, 0, sizeof(leaf));
if (rename)
@@ -2523,6 +2543,10 @@ int main(int argc, const char **argv)
if (max_depth > MAX_DEPTH)
die("--depth cannot exceed %u", MAX_DEPTH);
}
+ else if (!prefixcmp(a, "--path-prefix=")) {
+ path_prefix = a + 14;
+ path_prefix_len = strlen(path_prefix);
+ }
else if (!prefixcmp(a, "--active-branches="))
max_active_branches = strtoul(a + 18, NULL, 0);
else if (!prefixcmp(a, "--import-marks="))
--
1.6.6.rc4.12.g269e7
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Add --path-prefix option to git-fast-import
2009-12-29 12:51 [PATCH] Add --path-prefix option to git-fast-import Gisle Aas
@ 2009-12-29 14:06 ` Sverre Rabbelier
2009-12-30 8:17 ` Gisle Aas
2009-12-29 15:08 ` Shawn O. Pearce
1 sibling, 1 reply; 4+ messages in thread
From: Sverre Rabbelier @ 2009-12-29 14:06 UTC (permalink / raw)
To: Gisle Aas; +Cc: git, gitster, Gisle Aas
Heya,
On Tue, Dec 29, 2009 at 06:51, Gisle Aas <gisle.aas@it.uib.no> wrote:
> +static const char *path_prefix_prepend(struct strbuf *sb, const char *p)
> +{
> + if (p != sb->buf) {
> + strbuf_reset(sb);
> + strbuf_addstr(sb, p);
> + }
> + strbuf_insert(sb, 0, path_prefix, path_prefix_len);
> + return sb->buf;
> +}
> +
> static void file_change_m(struct branch *b)
> {
> const char *p = command_buf.buf + 2;
> @@ -1909,6 +1921,8 @@ static void file_change_m(struct branch *b)
> die("Garbage after path in: %s", command_buf.buf);
> p = uq.buf;
> }
> + if (path_prefix)
> + p = path_prefix_prepend(&uq, p);
You could reduce the size of this change by having path_prefix_prepend
check for path_prefix and just do nothing if it is not set.
--
Cheers,
Sverre Rabbelier
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add --path-prefix option to git-fast-import
2009-12-29 14:06 ` Sverre Rabbelier
@ 2009-12-30 8:17 ` Gisle Aas
0 siblings, 0 replies; 4+ messages in thread
From: Gisle Aas @ 2009-12-30 8:17 UTC (permalink / raw)
To: Sverre Rabbelier; +Cc: git, gitster, Gisle Aas
On Dec 29, 2009, at 15:06, Sverre Rabbelier wrote:
> Heya,
>
> On Tue, Dec 29, 2009 at 06:51, Gisle Aas <gisle.aas@it.uib.no> wrote:
>> +static const char *path_prefix_prepend(struct strbuf *sb, const char *p)
>> +{
>> + if (p != sb->buf) {
>> + strbuf_reset(sb);
>> + strbuf_addstr(sb, p);
>> + }
>> + strbuf_insert(sb, 0, path_prefix, path_prefix_len);
>> + return sb->buf;
>> +}
>> +
>> static void file_change_m(struct branch *b)
>> {
>> const char *p = command_buf.buf + 2;
>> @@ -1909,6 +1921,8 @@ static void file_change_m(struct branch *b)
>> die("Garbage after path in: %s", command_buf.buf);
>> p = uq.buf;
>> }
>> + if (path_prefix)
>> + p = path_prefix_prepend(&uq, p);
>
> You could reduce the size of this change by having path_prefix_prepend
> check for path_prefix and just do nothing if it is not set.
I felt the explict test was better style -- more obvious that nothing happens to p
when there is no path_prefix.
--Gisle
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add --path-prefix option to git-fast-import
2009-12-29 12:51 [PATCH] Add --path-prefix option to git-fast-import Gisle Aas
2009-12-29 14:06 ` Sverre Rabbelier
@ 2009-12-29 15:08 ` Shawn O. Pearce
1 sibling, 0 replies; 4+ messages in thread
From: Shawn O. Pearce @ 2009-12-29 15:08 UTC (permalink / raw)
To: Gisle Aas; +Cc: git, gitster, Gisle Aas
Gisle Aas <gisle.aas@it.uib.no> wrote:
> I found this useful when import multiple external repositories to be merged
> into a single git repo. Not having the files be renamed during the merge
> made it easier to follow the history of the individual files.
>
> Signed-off-by: Gisle Aas <gisle@aas.no>
> ---
> Documentation/git-fast-import.txt | 6 ++++++
> fast-import.c | 24 ++++++++++++++++++++++++
> 2 files changed, 30 insertions(+), 0 deletions(-)
Interesting. Test cases?
> +static const char *path_prefix_prepend(struct strbuf *sb, const char *p)
> +{
> + if (p != sb->buf) {
> + strbuf_reset(sb);
> + strbuf_addstr(sb, p);
> + }
I'd be a bit happier about the change if you could check not only
that p != sb->buf, but that p is not within sb->buf + sb->alloc.
I can't remember if all of the cases below are safe such that
any time you call the function with a p that p isn't pointing to
something within the strbuf you are handing in.
--
Shawn.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-12-30 8:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-29 12:51 [PATCH] Add --path-prefix option to git-fast-import Gisle Aas
2009-12-29 14:06 ` Sverre Rabbelier
2009-12-30 8:17 ` Gisle Aas
2009-12-29 15:08 ` Shawn O. Pearce
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).