Skip to content

Commit 6e96cb5

Browse files
committed
rerere: allow approxidate in gc.rerereResolved/gc.rerereUnresolved
These two configuration variables are described in the documentation to take an expiry period expressed in the number of days: gc.rerereResolved:: Records of conflicted merge you resolved earlier are kept for this many days when 'git rerere gc' is run. The default is 60 days. gc.rerereUnresolved:: Records of conflicted merge you have not resolved are kept for this many days when 'git rerere gc' is run. The default is 15 days. There is no strong reason not to allow a more general "approxidate" expiry specification, e.g. "5.days.ago", or "never". Rename the config_get_expiry() helper introduced in the previous step to git_config_get_expiry_in_days() and move it to a more generic place, config.c, and use date.c::parse_expiry_date() to do so. Give it an ability to allow the caller to tell among three cases (i.e. there is no "gc.rerereResolved" config, there is and it is correctly parsed into the *expiry variable, and there was an error in parsing the given value). The current caller can work correctly without using the return value, though. In the future, we may find other variables that only allow an integer that specifies "this many days" or other unit of time, and when it happens we may need to drop "_days" suffix from the name of the function and instead pass the "scale" value as another parameter. But this will do for now. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ea8227 commit 6e96cb5

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

Documentation/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,11 +1553,13 @@ gc.<pattern>.reflogExpireUnreachable::
15531553
gc.rerereResolved::
15541554
Records of conflicted merge you resolved earlier are
15551555
kept for this many days when 'git rerere gc' is run.
1556+
You can also use more human-readable "1.month.ago", etc.
15561557
The default is 60 days. See linkgit:git-rerere[1].
15571558

15581559
gc.rerereUnresolved::
15591560
Records of conflicted merge you have not resolved are
15601561
kept for this many days when 'git rerere gc' is run.
1562+
You can also use more human-readable "1.month.ago", etc.
15611563
The default is 15 days. See linkgit:git-rerere[1].
15621564

15631565
gitcvs.commitMsgAnnotation::

config.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,28 @@ int git_config_get_expiry(const char *key, const char **output)
20662066
return ret;
20672067
}
20682068

2069+
int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamp_t now)
2070+
{
2071+
char *expiry_string;
2072+
intmax_t days;
2073+
timestamp_t when;
2074+
2075+
if (git_config_get_string(key, &expiry_string))
2076+
return 1; /* no such thing */
2077+
2078+
if (git_parse_signed(expiry_string, &days, maximum_signed_value_of_type(int))) {
2079+
const int scale = 86400;
2080+
*expiry = now - days * scale;
2081+
return 0;
2082+
}
2083+
2084+
if (!parse_expiry_date(expiry_string, &when)) {
2085+
*expiry = when;
2086+
return 0;
2087+
}
2088+
return -1; /* thing exists but cannot be parsed */
2089+
}
2090+
20692091
int git_config_get_untracked_cache(void)
20702092
{
20712093
int val = -1;

config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ extern int git_config_get_max_percent_split_change(void);
205205
/* This dies if the configured or default date is in the future */
206206
extern int git_config_get_expiry(const char *key, const char **output);
207207

208+
/* parse either "this many days" integer, or "5.days.ago" approxidate */
209+
extern int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
210+
208211
struct key_value_info {
209212
const char *filename;
210213
int linenr;

rerere.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,16 +1176,6 @@ static void prune_one(struct rerere_id *id,
11761176
unlink_rr_item(id);
11771177
}
11781178

1179-
static void config_get_expiry(const char *key, timestamp_t *cutoff, timestamp_t now)
1180-
{
1181-
int days;
1182-
1183-
if (!git_config_get_int(key, &days)) {
1184-
const int scale = 86400;
1185-
*cutoff = now - days * scale;
1186-
}
1187-
}
1188-
11891179
void rerere_gc(struct string_list *rr)
11901180
{
11911181
struct string_list to_remove = STRING_LIST_INIT_DUP;
@@ -1199,8 +1189,8 @@ void rerere_gc(struct string_list *rr)
11991189
if (setup_rerere(rr, 0) < 0)
12001190
return;
12011191

1202-
config_get_expiry("gc.rerereresolved", &cutoff_resolve, now);
1203-
config_get_expiry("gc.rerereunresolved", &cutoff_noresolve, now);
1192+
git_config_get_expiry_in_days("gc.rerereresolved", &cutoff_resolve, now);
1193+
git_config_get_expiry_in_days("gc.rerereunresolved", &cutoff_noresolve, now);
12041194
git_config(git_default_config, NULL);
12051195
dir = opendir(git_path("rr-cache"));
12061196
if (!dir)

t/t4200-rerere.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ rerere_gc_custom_expiry_test () {
274274

275275
rerere_gc_custom_expiry_test 5 0
276276

277+
rerere_gc_custom_expiry_test 5.days.ago now
278+
277279
test_expect_success 'setup: file2 added differently in two branches' '
278280
git reset --hard &&
279281

0 commit comments

Comments
 (0)