summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 00fbe63)
raw | patch | inline | side by side (parent: 00fbe63)
author | Johan Herland <johan@herland.net> | |
Sat, 13 Feb 2010 21:28:28 +0000 (22:28 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 14 Feb 2010 03:36:15 +0000 (19:36 -0800) |
"git notes prune" will remove all notes that annotate unreachable/non-
existing objects.
The patch includes tests verifying correct behaviour of the new subcommand.
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
existing objects.
The patch includes tests verifying correct behaviour of the new subcommand.
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-notes.txt | patch | blob | history | |
builtin-notes.c | patch | blob | history | |
t/t3306-notes-prune.sh | [new file with mode: 0755] | patch | blob |
index a52d23ac1182d76e282b291e0373c492111e163f..3973f902657eb4330d8af97d8301e35371d70e18 100644 (file)
SYNOPSIS
--------
[verse]
-'git notes' (edit [-F <file> | -m <msg>] | show | remove) [commit]
+'git notes' (edit [-F <file> | -m <msg>] | show | remove | prune) [commit]
DESCRIPTION
-----------
This is equivalent to specifying an empty note message to
the `edit` subcommand.
+prune::
+ Remove all notes for non-existing/unreachable objects.
OPTIONS
-------
diff --git a/builtin-notes.c b/builtin-notes.c
index 7c4007523bc3354dc3fdab897a7a2ac1645ed062..48bc455a1a10022e407ca46a74e3016110627ee9 100644 (file)
--- a/builtin-notes.c
+++ b/builtin-notes.c
"git notes edit [-m <msg> | -F <file>] [<object>]",
"git notes show [<object>]",
"git notes remove [<object>]",
+ "git notes prune",
NULL
};
const char *object_ref;
char logmsg[100];
- int edit = 0, show = 0, remove = 0;
+ int edit = 0, show = 0, remove = 0, prune = 0;
const char *msgfile = NULL;
struct msg_arg msg = { 0, STRBUF_INIT };
struct option options[] = {
show = 1;
else if (argc && !strcmp(argv[0], "remove"))
remove = 1;
+ else if (argc && !strcmp(argv[0], "prune"))
+ prune = 1;
- if (edit + show + remove != 1)
+ if (edit + show + remove + prune != 1)
usage_with_options(git_notes_usage, options);
if ((msg.given || msgfile) && !edit) {
}
object_ref = argc == 2 ? argv[1] : "HEAD";
- if (argc > 2) {
+ if (argc > 2 || (prune && argc > 1)) {
error("too many parameters");
usage_with_options(git_notes_usage, options);
}
return execv_git_cmd(show_args);
}
- /* edit/remove command */
+ /* edit/remove/prune command */
if (remove)
strbuf_reset(&buf);
die_errno("could not open or read '%s'", msgfile);
}
- create_note(object, &buf, msg.given || msgfile || remove, note,
- new_note);
- if (is_null_sha1(new_note))
- remove_note(t, object);
- else
- add_note(t, object, new_note, combine_notes_overwrite);
+ if (prune) {
+ hashclr(new_note);
+ prune_notes(t);
+ } else {
+ create_note(object, &buf, msg.given || msgfile || remove, note,
+ new_note);
+ if (is_null_sha1(new_note))
+ remove_note(t, object);
+ else
+ add_note(t, object, new_note, combine_notes_overwrite);
+ }
snprintf(logmsg, sizeof(logmsg), "Note %s by 'git notes %s'",
is_null_sha1(new_note) ? "removed" : "added", argv[0]);
commit_notes(t, logmsg);
diff --git a/t/t3306-notes-prune.sh b/t/t3306-notes-prune.sh
--- /dev/null
+++ b/t/t3306-notes-prune.sh
@@ -0,0 +1,94 @@
+#!/bin/sh
+
+test_description='Test git notes prune'
+
+. ./test-lib.sh
+
+test_expect_success 'setup: create a few commits with notes' '
+
+ : > file1 &&
+ git add file1 &&
+ test_tick &&
+ git commit -m 1st &&
+ git notes edit -m "Note #1" &&
+ : > file2 &&
+ git add file2 &&
+ test_tick &&
+ git commit -m 2nd &&
+ git notes edit -m "Note #2" &&
+ : > file3 &&
+ git add file3 &&
+ test_tick &&
+ git commit -m 3rd &&
+ git notes edit -m "Note #3"
+'
+
+cat > expect <<END_OF_LOG
+commit 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
+Author: A U Thor <author@example.com>
+Date: Thu Apr 7 15:15:13 2005 -0700
+
+ 3rd
+
+Notes:
+ Note #3
+
+commit 08341ad9e94faa089d60fd3f523affb25c6da189
+Author: A U Thor <author@example.com>
+Date: Thu Apr 7 15:14:13 2005 -0700
+
+ 2nd
+
+Notes:
+ Note #2
+
+commit ab5f302035f2e7aaf04265f08b42034c23256e1f
+Author: A U Thor <author@example.com>
+Date: Thu Apr 7 15:13:13 2005 -0700
+
+ 1st
+
+Notes:
+ Note #1
+END_OF_LOG
+
+test_expect_success 'verify commits and notes' '
+
+ git log > actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'remove some commits' '
+
+ git reset --hard HEAD~2 &&
+ git reflog expire --expire=now HEAD &&
+ git gc --prune=now
+'
+
+test_expect_success 'verify that commits are gone' '
+
+ ! git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+ ! git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
+ git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
+'
+
+test_expect_success 'verify that notes are still present' '
+
+ git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+ git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
+ git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
+'
+
+test_expect_success 'prune notes' '
+
+ git notes prune
+'
+
+test_expect_success 'verify that notes are gone' '
+
+ ! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
+ ! git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
+ git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
+'
+
+test_done