9 #include "../UI/LogWindow.h" 11 #include <InterfaceKit.h> 69 void check_lg2(
int error,
const char* message,
const char* extra)
71 const char *lg_msg =
"";
75 const git_error* err = giterr_last();
77 lg_msg = err->message;
79 BString buffer(
"Error : %s. %s");
80 buffer.ReplaceFirst(
"%s", message);
81 buffer.ReplaceFirst(
"%s", lg_msg);
82 BAlert* alert =
new BAlert(
"", buffer.String(),
"Cancel",
83 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
91 static void print_time(
const git_time *intime,
const char *prefix,
96 int offset, hours, minutes;
99 offset = intime->offset;
108 minutes = offset % 60;
110 t = (time_t)intime->time + (intime->offset * 60);
113 strftime(out,
sizeof(out),
"%a %b %e %T %Y", intm);
115 text << prefix << out <<
" "<< sign << hours << minutes <<
"\n";
125 char buf[GIT_OID_HEXSZ + 1];
127 const git_signature *sig;
128 const char *scan, *eol;
130 git_oid_tostr(buf,
sizeof(buf), git_commit_id(commit));
131 text <<
"commit " << buf <<
"\n";
133 if ((count = (
int)git_commit_parentcount(commit)) > 1) {
135 for (i = 0; i < count; ++i) {
136 git_oid_tostr(buf, 8, git_commit_parent_id(commit, i));
142 if ((sig = git_commit_author(commit)) != NULL) {
143 text <<
"Author: " << sig->name <<
" <" << sig->email <<
">\n";
148 for (scan = git_commit_message(commit); scan && *scan; ) {
149 for (eol = scan; *eol && *eol !=
'\n'; ++eol) ;
151 text <<
"\t" << scan <<
"\n";
152 scan = *eol ? eol + 1 : NULL;
163 hide = s->
hide ^ hide;
168 "Could not create revision walker", NULL);
174 "Could not find repository HEAD", NULL);
177 "Reference does not refer to a commit", NULL);
180 "Reference does not refer to a commit", NULL);
182 git_object_free(obj);
197 "Could not open repository", s->
repodir);
205 if (*revstr ==
'^') {
206 revs.flags = GIT_REVPARSE_SINGLE;
209 if (git_revparse_single(&revs.from, s->
repo, revstr + 1) < 0)
211 }
else if (git_revparse(&revs, s->
repo, revstr) < 0)
214 if ((revs.flags & GIT_REVPARSE_SINGLE) != 0)
219 if ((revs.flags & GIT_REVPARSE_MERGE_BASE) != 0) {
222 git_object_id(revs.from), git_object_id(revs.to)),
223 "Could not find merge base", revstr);
225 git_object_lookup(&revs.to, s->
repo, &base, GIT_OBJ_COMMIT),
226 "Could not find merge base commit", NULL);
245 git_repository *repo = NULL;
247 int i, count = 0, printed = 0, parents;
250 git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
252 git_commit *commit = NULL;
253 git_pathspec *ps = NULL;
257 memset(&s, 0,
sizeof(s));
261 memset(&opt, 0,
sizeof(opt));
272 for (; !git_revwalk_next(&oid, s.
walker); git_commit_free(commit)) {
274 "Failed to look up commit", NULL);
279 git_pathspec_free(ps);
280 git_repository_free(repo);
281 git_libgit2_shutdown();
virtual void Execute()
Log command execution.
Status Options structure.
log_options holds other command line options that affect log output
virtual void Quit()
The function to Quit the window.
Log(BString)
Log class Constructor.
BString GetLogText()
Constructs the entire Log Text for given repo.
static void print_time(const git_time *intime, const char *prefix, BString &text)
Helper to format a git_time value like Git.
Header file of Log command.
log_state represents walker being configured while handling options
void SetText(BString)
Sets Text of the View in Window.
static void print_commit(git_commit *commit, struct log_options *opts, BString &text)
Helper to print a commit object.
LogWindow * fLogWindow
The Log Window.
void check_lg2(int error, const char *message, const char *extra)
Checks if libgit2 api was successfully executed.
The TrackGit Window class.
virtual TrackGitWindow * GetWindow()
This returns pointer to the log window.
static void push_rev(struct log_state *s, git_object *obj, int hide)
Push object (for hide or show) onto revwalker.
static int add_revision(struct log_state *s, const char *revstr)
Parse revision string and add revs to walker.
BString fRepo
The repo/directory where command is called.