From: Johan Herland <johan@herland.net>
To: gitster@pobox.com
Cc: git@vger.kernel.org, johan@herland.net
Subject: [PATCHv12 20/23] builtin-notes: Add "prune" subcommand for removing notes for missing objects
Date: Wed, 27 Jan 2010 12:51:57 +0100 [thread overview]
Message-ID: <1264593120-4428-21-git-send-email-johan@herland.net> (raw)
In-Reply-To: <1264593120-4428-1-git-send-email-johan@herland.net>
"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>
---
Documentation/git-notes.txt | 4 +-
builtin-notes.c | 28 ++++++++-----
t/t3306-notes-prune.sh | 94 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 115 insertions(+), 11 deletions(-)
create mode 100755 t/t3306-notes-prune.sh
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index a52d23a..3973f90 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -8,7 +8,7 @@ git-notes - Add/inspect commit notes
SYNOPSIS
--------
[verse]
-'git notes' (edit [-F <file> | -m <msg>] | show | remove) [commit]
+'git notes' (edit [-F <file> | -m <msg>] | show | remove | prune) [commit]
DESCRIPTION
-----------
@@ -37,6 +37,8 @@ remove::
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 88b99a7..e84ab7a 100644
--- a/builtin-notes.c
+++ b/builtin-notes.c
@@ -20,6 +20,7 @@ static const char * const git_notes_usage[] = {
"git notes edit [-m <msg> | -F <file>] [<object>]",
"git notes show [<object>]",
"git notes remove [<object>]",
+ "git notes prune",
NULL
};
@@ -159,7 +160,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
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[] = {
@@ -180,8 +181,10 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
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) {
@@ -195,7 +198,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
}
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);
}
@@ -222,7 +225,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
return execv_git_cmd(show_args);
}
- /* edit/remove command */
+ /* edit/remove/prune command */
if (remove)
strbuf_reset(&buf);
@@ -236,12 +239,17 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
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
new file mode 100755
index 0000000..b0adc7e
--- /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
--
1.6.6.405.g80ed6
next prev parent reply other threads:[~2010-01-27 11:53 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-27 11:51 [PATCHv12 00/23] git notes Johan Herland
2010-01-27 11:51 ` [PATCHv12 01/23] Minor non-functional fixes to notes.c Johan Herland
2010-01-27 21:20 ` Junio C Hamano
2010-01-27 22:33 ` Johan Herland
2010-01-27 11:51 ` [PATCHv12 02/23] Notes API: get_commit_notes() -> format_note() + remove the commit restriction Johan Herland
2010-01-27 11:51 ` [PATCHv12 03/23] Add tests for checking correct handling of $GIT_NOTES_REF and core.notesRef Johan Herland
2010-01-27 11:51 ` [PATCHv12 04/23] Notes API: init_notes(): Initialize the notes tree from the given notes ref Johan Herland
2010-01-27 11:51 ` [PATCHv12 05/23] Notes API: add_note(): Add note objects to the internal notes tree structure Johan Herland
2010-01-27 11:51 ` [PATCHv12 06/23] Notes API: remove_note(): Remove note objects from the " Johan Herland
2010-01-27 11:51 ` [PATCHv12 07/23] Notes API: get_note(): Return the note annotating the given object Johan Herland
2010-01-27 11:51 ` [PATCHv12 08/23] Notes API: for_each_note(): Traverse the entire notes tree with a callback Johan Herland
2010-01-27 11:51 ` [PATCHv12 09/23] Notes API: write_notes_tree(): Store the notes tree in the database Johan Herland
2010-01-27 11:51 ` [PATCHv12 10/23] Notes API: Allow multiple concurrent notes trees with new struct notes_tree Johan Herland
2010-01-27 11:51 ` [PATCHv12 11/23] Refactor notes concatenation into a flexible interface for combining notes Johan Herland
2010-01-27 11:51 ` [PATCHv12 12/23] Builtin-ify git-notes Johan Herland
2010-01-27 11:51 ` [PATCHv12 13/23] t3301: Verify successful annotation of non-commits Johan Herland
2010-01-27 11:51 ` [PATCHv12 14/23] t3305: Verify that adding many notes with git-notes triggers increased fanout Johan Herland
2010-01-27 11:51 ` [PATCHv12 15/23] Teach notes code to properly preserve non-notes in the notes tree Johan Herland
2010-01-27 11:51 ` [PATCHv12 16/23] Teach builtin-notes to remove empty notes Johan Herland
2010-01-27 11:51 ` [PATCHv12 17/23] builtin-notes: Add "remove" subcommand for removing existing notes Johan Herland
2010-01-27 11:51 ` [PATCHv12 18/23] t3305: Verify that removing notes triggers automatic fanout consolidation Johan Herland
2010-01-27 11:51 ` [PATCHv12 19/23] Notes API: prune_notes(): Prune notes that belong to non-existing objects Johan Herland
2010-01-27 11:51 ` Johan Herland [this message]
2010-01-27 11:51 ` [PATCHv12 21/23] Documentation: Generalize git-notes docs to 'objects' instead of 'commits' Johan Herland
2010-01-27 11:51 ` [PATCHv12 22/23] builtin-notes: Add "list" subcommand for listing note objects Johan Herland
2010-01-27 11:52 ` [PATCHv12 23/23] builtin-notes: Add "add" subcommand for appending to " Johan Herland
2010-01-27 20:00 ` [PATCHv12 00/23] git notes Junio C Hamano
2010-01-27 20:18 ` Sverre Rabbelier
2010-01-27 23:05 ` Johan Herland
2010-01-28 0:02 ` Junio C Hamano
2010-01-28 1:17 ` Johan Herland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264593120-4428-21-git-send-email-johan@herland.net \
--to=johan@herland.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).