Skip to content

Commit aa54845

Browse files
peffgitster
authored andcommitted
fast-export: de-obfuscate --anonymize-map handling
When we handle an --anonymize-map option, we parse the orig/anon pair, and then feed the "orig" string to anonymize_str(), along with a generator function that duplicates the "anon" string to be cached in the map. This works, because anonymize_str() says "ah, there is no mapping yet for orig; I'll add one from the generator". But there are some downsides: 1. It's a bit too clever, as it's not obvious what the code is trying to do or why it works. 2. It requires allowing generator functions to take an extra void pointer, which is not something any of the normal callers of anonymize_str() want. 3. It does the wrong thing if the same token is provided twice. When there are conflicting options, like: git fast-export --anonymize \ --anonymize-map=foo:one \ --anonymize-map=foo:two we usually let the second one override the first. But by using anonymize_str(), which has first-one-wins logic, we do the opposite. So instead of relying on anonymize_str(), let's directly add the entry ourselves. We can tweak the tests to show that we handle overridden options correctly now. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dcc4e13 commit aa54845

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

builtin/fast-export.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,11 +1140,6 @@ static void handle_deletes(void)
11401140
}
11411141
}
11421142

1143-
static char *anonymize_seed(void *data)
1144-
{
1145-
return xstrdup(data);
1146-
}
1147-
11481143
static int parse_opt_anonymize_map(const struct option *opt,
11491144
const char *arg, int unset)
11501145
{
@@ -1166,7 +1161,8 @@ static int parse_opt_anonymize_map(const struct option *opt,
11661161
if (!keylen || !*value)
11671162
return error(_("--anonymize-map token cannot be empty"));
11681163

1169-
anonymize_str(map, anonymize_seed, arg, keylen, (void *)value);
1164+
add_anonymized_entry(map, memhash(arg, keylen), arg, keylen,
1165+
xstrdup(value));
11701166

11711167
return 0;
11721168
}

t/t9351-fast-export-anonymize.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test_expect_success 'setup simple repo' '
2525
test_expect_success 'export anonymized stream' '
2626
git fast-export --anonymize --all \
2727
--anonymize-map=retain-me \
28+
--anonymize-map=xyzzy:should-not-appear \
2829
--anonymize-map=xyzzy:custom-name \
2930
--anonymize-map=other \
3031
>stream
@@ -41,6 +42,7 @@ test_expect_success 'stream omits path names' '
4142

4243
test_expect_success 'stream contains user-specified names' '
4344
grep retain-me stream &&
45+
! grep should-not-appear stream &&
4446
grep custom-name stream
4547
'
4648

0 commit comments

Comments
 (0)