]> git.mjollnir.org Git - cil.git/commitdiff
Added ability to use a shortened hash for issues et al (closes #bf9badb4).
authorAndrew Chilton <andychilton@gmail.com>
Tue, 1 Jul 2008 11:17:26 +0000 (23:17 +1200)
committerAndrew Chilton <andychilton@gmail.com>
Tue, 1 Jul 2008 11:17:26 +0000 (23:17 +1200)
bin/cil
issues/c_95e81a14.cil [new file with mode: 0644]
issues/i_bf9badb4.cil
lib/CIL.pm

diff --git a/bin/cil b/bin/cil
index 8cbb57eda511d9684c132e96527855a4e8b3a167..15d8eac5ddde9055d3bfb8396eba9a79eb050183 100755 (executable)
--- a/bin/cil
+++ b/bin/cil
@@ -199,10 +199,7 @@ sub cmd_show {
     my ($cil, undef, $issue_name) = @_;
 
     # firstly, read the issue in
-    my $issue = CIL::Issue->new_from_name($cil, $issue_name);
-    unless ( defined $issue ) {
-        fatal("Couldn't load issue '$issue_name'");
-    }
+    my $issue = load_issue_fuzzy( $cil, $issue_name );
     display_issue_full($cil, $issue);
 }
 
@@ -214,10 +211,7 @@ sub cmd_status {
     }
 
     # firstly, read the issue in
-    my $issue = CIL::Issue->new_from_name($cil, $issue_name);
-    unless ( defined $issue ) {
-        fatal("Couldn't load issue '$issue_name'");
-    }
+    my $issue = load_issue_fuzzy( $cil, $issue_name );
 
     # set the status for this issue
     $issue->Status( $status );
@@ -243,10 +237,7 @@ sub cmd_add {
 sub cmd_edit {
     my ($cil, undef, $issue_name) = @_;
 
-    my $issue = CIL::Issue->new_from_name($cil, $issue_name);
-    unless ( defined $issue ) {
-        fatal("Couldn't load issue '$issue_name'");
-    }
+    my $issue = load_issue_fuzzy( $cil, $issue_name );
 
     CIL::Utils->ensure_interactive();
 
@@ -279,10 +270,7 @@ sub cmd_edit {
 sub cmd_comment {
     my ($cil, undef, $issue_name) = @_;
 
-    my $issue = CIL::Issue->new_from_name($cil, $issue_name);
-    unless ( defined $issue ) {
-        fatal("couldn't load issue '$issue_name'");
-    }
+    my $issue = load_issue_fuzzy( $cil, $issue_name );
 
     CIL::Utils->ensure_interactive();
 
@@ -298,10 +286,7 @@ sub cmd_comment {
 sub cmd_attach {
     my ($cil, undef, $issue_name, $filename) = @_;
 
-    my $issue = CIL::Issue->new_from_name($cil, $issue_name);
-    unless ( defined $issue ) {
-        fatal("couldn't load issue '$issue_name'");
-    }
+    my $issue = load_issue_fuzzy( $cil, $issue_name );
 
     # check to see if the file exists
     unless ( -r $filename ) {
@@ -351,10 +336,7 @@ EOF
 sub cmd_extract {
     my ($cil, $args, $attachment_name) = @_;
 
-    my $attachment = CIL::Attachment->new_from_name($cil, $attachment_name);
-    unless ( defined $attachment ) {
-        fatal("Couldn't load attachment '$attachment_name'");
-    }
+    my $attachment = load_attachment_fuzzy($cil, $attachment_name);
 
     my $filename = $args->{f} || $attachment->Filename();
     write_file( $filename, $attachment->as_binary );
@@ -570,6 +552,69 @@ sub cmd_am {
 ## ----------------------------------------------------------------------------
 # helpers
 
+sub load_issue_fuzzy {
+    my ($cil, $partial_name) = @_;
+
+    my $issues = $cil->list_issues_fuzzy( $partial_name );
+    unless ( defined $issues ) {
+        fatal("Couldn't find any issues using '$partial_name'");
+    }
+
+    if ( @$issues > 1 ) {
+        fatal('found multiple issues which match that name: ' . join(' ', map { $_->{name} } @$issues));
+    }
+
+    my $issue_name = $issues->[0]->{name};
+    my $issue = CIL::Issue->new_from_name($cil, $issue_name);
+    unless ( defined $issue ) {
+        fatal("Couldn't load issue '$issue_name'");
+    }
+
+    return $issue;
+}
+
+sub load_comment_fuzzy {
+    my ($cil, $partial_name) = @_;
+
+    my $comments = $cil->list_comments_fuzzy( $partial_name );
+    unless ( defined $comments ) {
+        fatal("Couldn't find any comments using '$partial_name'");
+    }
+
+    if ( @$comments > 1 ) {
+        fatal('found multiple comments which match that name: ' . join(' ', map { $_->{name} } @$comments));
+    }
+
+    my $comment_name = $comments->[0]->{name};
+    my $comment = CIL::comment->new_from_name($cil, $comment_name);
+    unless ( defined $comment ) {
+        fatal("Couldn't load comment '$comment_name'");
+    }
+
+    return $comment;
+}
+
+sub load_attachment_fuzzy {
+    my ($cil, $partial_name) = @_;
+
+    my $attachments = $cil->list_attachments_fuzzy( $partial_name );
+    unless ( defined $attachments ) {
+        fatal("Couldn't find any attachments using '$partial_name'");
+    }
+
+    if ( @$attachments > 1 ) {
+        fatal('found multiple attachments which match that name: ' . join(' ', map { $_->{name} } @$attachments));
+    }
+
+    my $attachment_name = $attachments->[0]->{name};
+    my $attachment = CIL::Attachment->new_from_name($cil, $attachment_name);
+    unless ( defined $attachment ) {
+        fatal("Couldn't load attachment '$partial_name'");
+    }
+
+    return $attachment;
+}
+
 sub ans {
     my ($msg) = @_;
     print $msg;
diff --git a/issues/c_95e81a14.cil b/issues/c_95e81a14.cil
new file mode 100644 (file)
index 0000000..27bdf26
--- /dev/null
@@ -0,0 +1,16 @@
+Issue: bf9badb4
+CreatedBy: Andrew Chilton <andychilton@gmail.com>
+Inserted: 2008-07-01T10:59:42
+Updated: 2008-07-01T11:00:46
+
+Now allows you to put in issue names as shortened versions of their full names.
+Also attachment names too. Provisions have already been added in case we want
+to do comment names too.
+
+e.g.
+
+   cil show cafe
+   cil edit cafe
+   cil extract dead
+
+and the like.
index d83762839bda89bfa95070fe6772d48c1420c5db..065c8d00c6f0c9961f8bd3eeb4f8319ca452e06c 100644 (file)
@@ -1,11 +1,12 @@
 Summary: Allow shortened hash names
-Status: New
+Status: Finished
 CreatedBy: Francois Marier <francois@debian.org>
 AssignedTo: Andrew Chilton <andychilton@gmail.com>
 Label: Milestone-v0.4
 Label: Type-Enhancement
+Comment: 95e81a14
 Inserted: 2008-06-29T13:20:11
-Updated: 2008-06-29T12:33:18
+Updated: 2008-07-01T11:15:35
 
 How about doing the same thing that git is doing for commit hashes: if you
 only type the first few characters of the hash, then as long as it's not
index bd01a88f9fbe62179d6f23e369f57aff5ccb6ef9..f64d67a0bc5a18ed68d6879c1b26bc00428eff52 100644 (file)
@@ -59,9 +59,11 @@ sub new {
 }
 
 sub list_entities {
-    my ($self, $prefix) = @_;
+    my ($self, $prefix, $base) = @_;
 
-    my $globpath = $self->IssueDir . "/${prefix}_*.cil";
+    $base = '' unless defined $base;
+
+    my $globpath = $self->IssueDir . "/${prefix}_${base}*.cil";
     my @filenames = bsd_glob($globpath);
 
     my @entities;
@@ -93,6 +95,24 @@ sub list_attachments {
     return $self->list_entities('a');
 }
 
+sub list_issues_fuzzy {
+    my ($self, $partial_name) = @_;
+
+    return $self->list_entities('i', $partial_name);
+}
+
+sub list_comments_fuzzy {
+    my ($self, $partial_name) = @_;
+
+    return $self->list_entities('c', $partial_name);
+}
+
+sub list_attachments_fuzzy {
+    my ($self, $partial_name) = @_;
+
+    return $self->list_entities('a', $partial_name);
+}
+
 sub get_issues {
     my ($self) = @_;