Merge branch 'mg/notes-dry-run'
* mg/notes-dry-run: notes: dry-run and verbose options for prune
This commit is contained in:
commit
2d4fef9b86
@ -15,7 +15,7 @@ SYNOPSIS
|
|||||||
'git notes' edit [<object>]
|
'git notes' edit [<object>]
|
||||||
'git notes' show [<object>]
|
'git notes' show [<object>]
|
||||||
'git notes' remove [<object>]
|
'git notes' remove [<object>]
|
||||||
'git notes' prune
|
'git notes' prune [-n | -v]
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
@ -128,6 +128,13 @@ OPTIONS
|
|||||||
'GIT_NOTES_REF' and the "core.notesRef" configuration. The ref
|
'GIT_NOTES_REF' and the "core.notesRef" configuration. The ref
|
||||||
is taken to be in `refs/notes/` if it is not qualified.
|
is taken to be in `refs/notes/` if it is not qualified.
|
||||||
|
|
||||||
|
-n::
|
||||||
|
Do not remove anything; just report the object names whose notes
|
||||||
|
would be removed.
|
||||||
|
|
||||||
|
-v::
|
||||||
|
Report all object names whose notes are removed.
|
||||||
|
|
||||||
|
|
||||||
DISCUSSION
|
DISCUSSION
|
||||||
----------
|
----------
|
||||||
|
@ -26,7 +26,7 @@ static const char * const git_notes_usage[] = {
|
|||||||
"git notes [--ref <notes_ref>] edit [<object>]",
|
"git notes [--ref <notes_ref>] edit [<object>]",
|
||||||
"git notes [--ref <notes_ref>] show [<object>]",
|
"git notes [--ref <notes_ref>] show [<object>]",
|
||||||
"git notes [--ref <notes_ref>] remove [<object>]",
|
"git notes [--ref <notes_ref>] remove [<object>]",
|
||||||
"git notes [--ref <notes_ref>] prune",
|
"git notes [--ref <notes_ref>] prune [-n | -v]",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ static const char * const git_notes_remove_usage[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const char * const git_notes_prune_usage[] = {
|
static const char * const git_notes_prune_usage[] = {
|
||||||
"git notes prune",
|
"git notes prune [<options>]",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -792,7 +792,10 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
|
|||||||
static int prune(int argc, const char **argv, const char *prefix)
|
static int prune(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
struct notes_tree *t;
|
struct notes_tree *t;
|
||||||
|
int show_only = 0, verbose = 0;
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
|
OPT_BOOLEAN('n', NULL, &show_only, "do not remove, show only"),
|
||||||
|
OPT_BOOLEAN('v', NULL, &verbose, "report pruned notes"),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -806,8 +809,10 @@ static int prune(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
t = init_notes_check("prune");
|
t = init_notes_check("prune");
|
||||||
|
|
||||||
prune_notes(t);
|
prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
|
||||||
commit_notes(t, "Notes removed by 'git notes prune'");
|
(show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
|
||||||
|
if (!show_only)
|
||||||
|
commit_notes(t, "Notes removed by 'git notes prune'");
|
||||||
free_notes(t);
|
free_notes(t);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
7
notes.c
7
notes.c
@ -1083,7 +1083,7 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void prune_notes(struct notes_tree *t)
|
void prune_notes(struct notes_tree *t, int flags)
|
||||||
{
|
{
|
||||||
struct note_delete_list *l = NULL;
|
struct note_delete_list *l = NULL;
|
||||||
|
|
||||||
@ -1094,7 +1094,10 @@ void prune_notes(struct notes_tree *t)
|
|||||||
for_each_note(t, 0, prune_notes_helper, &l);
|
for_each_note(t, 0, prune_notes_helper, &l);
|
||||||
|
|
||||||
while (l) {
|
while (l) {
|
||||||
remove_note(t, l->sha1);
|
if (flags & NOTES_PRUNE_VERBOSE)
|
||||||
|
printf("%s\n", sha1_to_hex(l->sha1));
|
||||||
|
if (!(flags & NOTES_PRUNE_DRYRUN))
|
||||||
|
remove_note(t, l->sha1);
|
||||||
l = l->next;
|
l = l->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
notes.h
5
notes.h
@ -171,6 +171,9 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
|
|||||||
*/
|
*/
|
||||||
int write_notes_tree(struct notes_tree *t, unsigned char *result);
|
int write_notes_tree(struct notes_tree *t, unsigned char *result);
|
||||||
|
|
||||||
|
/* Flags controlling the operation of prune */
|
||||||
|
#define NOTES_PRUNE_VERBOSE 1
|
||||||
|
#define NOTES_PRUNE_DRYRUN 2
|
||||||
/*
|
/*
|
||||||
* Remove all notes annotating non-existing objects from the given notes tree
|
* Remove all notes annotating non-existing objects from the given notes tree
|
||||||
*
|
*
|
||||||
@ -181,7 +184,7 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result);
|
|||||||
* structure are not persistent until a subsequent call to write_notes_tree()
|
* structure are not persistent until a subsequent call to write_notes_tree()
|
||||||
* returns zero.
|
* returns zero.
|
||||||
*/
|
*/
|
||||||
void prune_notes(struct notes_tree *t);
|
void prune_notes(struct notes_tree *t, int flags);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free (and de-initialize) the given notes_tree structure
|
* Free (and de-initialize) the given notes_tree structure
|
||||||
|
@ -60,7 +60,7 @@ test_expect_success 'verify commits and notes' '
|
|||||||
|
|
||||||
test_expect_success 'remove some commits' '
|
test_expect_success 'remove some commits' '
|
||||||
|
|
||||||
git reset --hard HEAD~2 &&
|
git reset --hard HEAD~1 &&
|
||||||
git reflog expire --expire=now HEAD &&
|
git reflog expire --expire=now HEAD &&
|
||||||
git gc --prune=now
|
git gc --prune=now
|
||||||
'
|
'
|
||||||
@ -68,7 +68,7 @@ test_expect_success 'remove some commits' '
|
|||||||
test_expect_success 'verify that commits are gone' '
|
test_expect_success 'verify that commits are gone' '
|
||||||
|
|
||||||
! git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
|
! git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
|
||||||
! git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
|
git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
|
||||||
git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
|
git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -79,11 +79,55 @@ test_expect_success 'verify that notes are still present' '
|
|||||||
git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
|
git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'prune -n does not remove notes' '
|
||||||
|
|
||||||
|
git notes list > expect &&
|
||||||
|
git notes prune -n &&
|
||||||
|
git notes list > actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
cat > expect <<EOF
|
||||||
|
5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'prune -n lists prunable notes' '
|
||||||
|
|
||||||
|
|
||||||
|
git notes prune -n > actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
|
||||||
test_expect_success 'prune notes' '
|
test_expect_success 'prune notes' '
|
||||||
|
|
||||||
git notes prune
|
git notes prune
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'verify that notes are gone' '
|
||||||
|
|
||||||
|
! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
|
||||||
|
git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
|
||||||
|
git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'remove some commits' '
|
||||||
|
|
||||||
|
git reset --hard HEAD~1 &&
|
||||||
|
git reflog expire --expire=now HEAD &&
|
||||||
|
git gc --prune=now
|
||||||
|
'
|
||||||
|
|
||||||
|
cat > expect <<EOF
|
||||||
|
08341ad9e94faa089d60fd3f523affb25c6da189
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'prune -v notes' '
|
||||||
|
|
||||||
|
git notes prune -v > actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'verify that notes are gone' '
|
test_expect_success 'verify that notes are gone' '
|
||||||
|
|
||||||
! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
|
! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
|
||||||
|
Loading…
Reference in New Issue
Block a user