1 //
2 //      aegis - project change supervisor
3 //      Copyright (C) 1999, 2001-2008, 2012 Peter Miller
4 //
5 //      This program is free software; you can redistribute it and/or modify
6 //      it under the terms of the GNU General Public License as published by
7 //      the Free Software Foundation; either version 3 of the License, or
8 //      (at your option) any later version.
9 //
10 //      This program is distributed in the hope that it will be useful,
11 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //      GNU General Public License for more details.
14 //
15 //      You should have received a copy of the GNU General Public License
16 //      along with this program. If not, see
17 //      <http://www.gnu.org/licenses/>.
18 //
19 
20 #include <common/ac/assert.h>
21 
22 #include <common/str_list.h>
23 #include <common/trace.h>
24 #include <libaegis/ael/change/inappropriat.h>
25 #include <libaegis/ael/column_width.h>
26 #include <libaegis/ael/project/history.h>
27 #include <libaegis/change.h>
28 #include <libaegis/change/identifier.h>
29 #include <libaegis/col.h>
30 #include <libaegis/cstate.fmtgen.h>
31 #include <libaegis/option.h>
32 #include <libaegis/output.h>
33 #include <libaegis/project.h>
34 #include <libaegis/project/history.h>
35 #include <libaegis/user.h>
36 
37 
38 void
list_project_history(change_identifier & cid,string_list_ty *)39 list_project_history(change_identifier &cid, string_list_ty *)
40 {
41     output::pointer name_col;
42     output::pointer delta_col;
43     output::pointer date_col;
44     output::pointer change_col;
45     output::pointer description_col;
46     size_t          j, k;
47     string_ty       *line1;
48     int             left;
49 
50     trace(("list_project_history()\n{\n"));
51     if (cid.set())
52         list_change_inappropriate();
53 
54     //
55     // create the columns
56     //
57     col::pointer colp = col::open((string_ty *)0);
58     line1 = str_format("Project \"%s\"", cid.get_pp()->name_get()->str_text);
59     colp->title(line1->str_text, "History");
60     str_free(line1);
61 
62     // the delta name column is the whole page wide
63     name_col = colp->create(0, 0, (const char *)0);
64 
65     left = 0;
66     delta_col = colp->create(left, left + CHANGE_WIDTH, "Delta\n-------");
67     left += CHANGE_WIDTH + 1;
68 
69     if (!option_terse_get())
70     {
71         date_col =
72             colp->create
73             (
74                 left,
75                 left + WHEN_WIDTH,
76                 "Date and Time\n---------------"
77             );
78         left += WHEN_WIDTH + 1;
79 
80         change_col =
81             colp->create(left, left + CHANGE_WIDTH, "Change\n-------");
82         left += CHANGE_WIDTH + 1;
83 
84         description_col =
85             colp->create(left, 0, "Description\n-------------");
86     }
87 
88     //
89     // list the project's successful integrations
90     //
91     for (j = 0; ; ++j)
92     {
93         long            cn;
94         long            dn;
95         string_list_ty  name;
96 
97         if (!project_history_nth(cid.get_pp(), j, &cn, &dn, &name))
98             break;
99         if (!option_terse_get() && name.nstrings)
100         {
101             colp->need(4);
102             name_col->fprintf("Name%s: ", (name.nstrings == 1 ? "" : "s"));
103             for (k = 0; k < name.nstrings; ++k)
104             {
105                 if (k)
106                     name_col->fputs(", ");
107                 name_col->fprintf("\"%s\"", name.string[k]->str_text);
108             }
109 
110             //
111             // If we don't eoln here, and there are lots
112             // of names, then they get intermingled with
113             // the date and description lines, and it
114             // looks weird.
115             //
116             colp->eoln();
117         }
118         delta_col->fprintf("%4ld", dn);
119         if (!option_terse_get())
120         {
121             change::pointer cp = change_alloc(cid.get_pp(), cn);
122             change_bind_existing(cp);
123             cstate_ty *cstate_data = cp->cstate_get();
124             time_t t =
125                 cstate_data->history->list
126                 [
127                         cstate_data->history->length - 1
128                 ]->when;
129             date_col->fputs(ctime(&t));
130             change_col->fprintf("%4ld", magic_zero_decode(cn));
131             assert(cstate_data->brief_description);
132             description_col->fputs(cstate_data->brief_description);
133             change_free(cp);
134         }
135         colp->eoln();
136     }
137     trace(("}\n"));
138 }
139 
140 
141 // vim: set ts=8 sw=4 et :
142