static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const char *line) { char *date; int namelen; unsigned long time; int tz, ret; const char *filler = " "; if (fmt == CMIT_FMT_ONELINE) return 0; date = strchr(line, '>'); if (!date) return 0; namelen = ++date - line; time = strtoul(date, &date, 10); tz = strtol(date, NULL, 10); ret = sprintf(buf, "%s: %.*s%.*s\n", what, (fmt == CMIT_FMT_FULLER) ? 4 : 0, filler, namelen, line); switch (fmt) { case CMIT_FMT_MEDIUM: ret += sprintf(buf + ret, "Date: %s\n", show_date(time, tz)); break; case CMIT_FMT_FULLER: ret += sprintf(buf + ret, "%sDate: %s\n", what, show_date(time, tz)); break; default: /* notin' */ break; } return ret; }
static char *emit_suspect_detail(struct blame_origin *suspect) { struct commitinfo *info; struct strbuf detail = STRBUF_INIT; info = cgit_parse_commit(suspect->commit); strbuf_addf(&detail, "author %s", info->author); if (!ctx.cfg.noplainemail) strbuf_addf(&detail, " %s", info->author_email); strbuf_addf(&detail, " %s\n", show_date(info->author_date, info->author_tz, cgit_date_mode(DATE_ISO8601))); strbuf_addf(&detail, "committer %s", info->committer); if (!ctx.cfg.noplainemail) strbuf_addf(&detail, " %s", info->committer_email); strbuf_addf(&detail, " %s\n\n", show_date(info->committer_date, info->committer_tz, cgit_date_mode(DATE_ISO8601))); strbuf_addstr(&detail, info->subject); cgit_free_commitinfo(info); return strbuf_detach(&detail, NULL); }
void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb, const char *line, enum date_mode dmode, const char *encoding) { char *date; int namelen; unsigned long time; int tz; const char *filler = " "; if (fmt == CMIT_FMT_ONELINE) return; date = strchr(line, '>'); if (!date) return; namelen = ++date - line; time = strtoul(date, &date, 10); tz = strtol(date, NULL, 10); if (fmt == CMIT_FMT_EMAIL) { char *name_tail = strchr(line, '<'); int display_name_length; if (!name_tail) return; while (line < name_tail && isspace(name_tail[-1])) name_tail--; display_name_length = name_tail - line; filler = ""; strbuf_addstr(sb, "From: "); add_rfc2047(sb, line, display_name_length, encoding); strbuf_add(sb, name_tail, namelen - display_name_length); strbuf_addch(sb, '\n'); } else { strbuf_addf(sb, "%s: %.*s%.*s\n", what, (fmt == CMIT_FMT_FULLER) ? 4 : 0, filler, namelen, line); } switch (fmt) { case CMIT_FMT_MEDIUM: strbuf_addf(sb, "Date: %s\n", show_date(time, tz, dmode)); break; case CMIT_FMT_EMAIL: strbuf_addf(sb, "Date: %s\n", show_date(time, tz, DATE_RFC2822)); break; case CMIT_FMT_FULLER: strbuf_addf(sb, "%sDate: %s\n", what, show_date(time, tz, dmode)); break; default: /* notin' */ break; } }
int main(int argc, char **argv) { int opt; //struct timeval tv; getopt_init(); while (-1 != (opt = getopt(argc, argv, "hs:"))) { printf("\n"); switch (opt) { case 'h': /* show help */ print_usage(); break; case 's': /* set date*/ set_date(argv[2]); break; default: break; } } /* show date and kernel time */ if (argc == 1) { show_date(); //ktime_get_timeval(&tv); //printf("ktime_get_timeval %d:%d (s:ms)\n", (int)tv.tv_sec, (int)tv.tv_usec/1000); return 0; } check_format(argv[argc-1]); return 0; }
static const char *format_time(timestamp_t time, const char *tz_str, int show_raw_time) { static struct strbuf time_buf = STRBUF_INIT; strbuf_reset(&time_buf); if (show_raw_time) { strbuf_addf(&time_buf, "%"PRItime" %s", time, tz_str); } else { const char *time_str; size_t time_width; int tz; tz = atoi(tz_str); time_str = show_date(time, tz, &blame_date_mode); strbuf_addstr(&time_buf, time_str); /* * Add space paddings to time_buf to display a fixed width * string, and use time_width for display width calibration. */ for (time_width = utf8_strwidth(time_str); time_width < blame_date_width; time_width++) strbuf_addch(&time_buf, ' '); } return time_buf.buf; }
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc) { put_format(b, " <divecomputer"); show_utf8(b, dc->model, " model='", "'", 1); if (dc->deviceid) put_format(b, " deviceid='%08x'", dc->deviceid); if (dc->diveid) put_format(b, " diveid='%08x'", dc->diveid); if (dc->when && dc->when != dive->when) show_date(b, dc->when); if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) put_duration(b, dc->duration, " duration='", " min'"); if (dc->divemode != OC) { for (enum dive_comp_type i = 0; i < NUM_DC_TYPE; i++) if (dc->divemode == i) show_utf8(b, divemode_text[i], " dctype='", "'", 1); if (dc->no_o2sensors) put_format(b," no_o2sensors='%d'", dc->no_o2sensors); } put_format(b, ">\n"); save_depths(b, dc); save_temperatures(b, dc); save_airpressure(b, dc); save_salinity(b, dc); put_duration(b, dc->surfacetime, " <surfacetime>", " min</surfacetime>\n"); save_extra_data(b, dc->extra_data); save_events(b, dc->events); save_samples(b, dc->samples, dc->sample); put_format(b, " </divecomputer>\n"); }
void save_one_dive_to_mb(struct membuffer *b, struct dive *dive) { struct divecomputer *dc; put_string(b, "<dive"); if (dive->number) put_format(b, " number='%d'", dive->number); if (dive->tripflag == NO_TRIP) put_format(b, " tripflag='NOTRIP'"); if (dive->rating) put_format(b, " rating='%d'", dive->rating); if (dive->visibility) put_format(b, " visibility='%d'", dive->visibility); save_tags(b, dive->tag_list); if (dive->dive_site_uuid) put_format(b, " divesiteid='%8x'", dive->dive_site_uuid); show_date(b, dive->when); put_format(b, " duration='%u:%02u min'>\n", FRACTION(dive->dc.duration.seconds, 60)); save_overview(b, dive); save_cylinder_info(b, dive); save_weightsystem_info(b, dive); save_dive_temperature(b, dive); /* Save the dive computer data */ for_each_dc(dive, dc) save_dc(b, dive, dc); FOR_EACH_PICTURE(dive) save_picture(b, picture); put_format(b, "</dive>\n"); }
void get_reflog_selector(struct strbuf *sb, struct reflog_walk_info *reflog_info, const struct date_mode *dmode, int force_date, int shorten) { struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; struct reflog_info *info; const char *printed_ref; if (!commit_reflog) return; if (shorten) { if (!commit_reflog->reflogs->short_ref) commit_reflog->reflogs->short_ref = shorten_unambiguous_ref(commit_reflog->reflogs->ref, 0); printed_ref = commit_reflog->reflogs->short_ref; } else { printed_ref = commit_reflog->reflogs->ref; } strbuf_addf(sb, "%s@{", printed_ref); if (commit_reflog->selector == SELECTOR_DATE || (commit_reflog->selector == SELECTOR_NONE && force_date)) { info = &commit_reflog->reflogs->items[commit_reflog->recno+1]; strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode)); } else { strbuf_addf(sb, "%d", commit_reflog->reflogs->nr - 2 - commit_reflog->recno); } strbuf_addch(sb, '}'); }
static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1, const char *email, unsigned long timestamp, int tz, const char *message, void *cb_data) { struct read_ref_at_cb *cb = cb_data; cb->reccnt++; cb->tz = tz; cb->date = timestamp; if (timestamp <= cb->at_time || cb->cnt == 0) { if (cb->msg) *cb->msg = xstrdup(message); if (cb->cutoff_time) *cb->cutoff_time = timestamp; if (cb->cutoff_tz) *cb->cutoff_tz = tz; if (cb->cutoff_cnt) *cb->cutoff_cnt = cb->reccnt - 1; /* * we have not yet updated cb->[n|o]sha1 so they still * hold the values for the previous record. */ if (!is_null_sha1(cb->osha1)) { hashcpy(cb->sha1, nsha1); if (hashcmp(cb->osha1, nsha1)) warning("Log for ref %s has gap after %s.", cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822))); } else if (cb->date == cb->at_time) hashcpy(cb->sha1, nsha1); else if (hashcmp(nsha1, cb->sha1)) warning("Log for ref %s unexpectedly ended on %s.", cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822))); hashcpy(cb->osha1, osha1); hashcpy(cb->nsha1, nsha1); cb->found_it = 1; return 1; } hashcpy(cb->osha1, osha1); hashcpy(cb->nsha1, nsha1); if (cb->cnt > 0) cb->cnt--; return 0; }
static void parse_approxidate(const char **argv, struct timeval *now) { for (; *argv; argv++) { time_t t; t = approxidate_relative(*argv, now); printf("%s -> %s\n", *argv, show_date(t, 0, DATE_MODE(ISO8601))); } }
int main (int args, char *argv[]) { if (wiringPiSetup () == -1) exit (1) ; int fd = lcdInit (2, 16, 4, RS, EN, D0,D1,D2,D3,D0,D1,D2,D3) ; if (fd == -1) { printf ("lcdInit 1 failed\n") ; return 1 ; } sleep (1) ; //显示屏初始化 lcdPosition (fd, 0, 0); lcdPuts (fd, " Raspberry Pi!"); //启动信息 sleep(1); if(argv[1]) { lcdPosition (fd, 0, 0) ; lcdPuts (fd, " ") ; //清空第一行 lcdPosition (fd, 0, 0) ; lcdPuts (fd, argv[1]) ; //命令行参数显示至第一行 } int start,now; while(1) { show_date(fd); cls(fd); show_sys_info(fd); sleep(5); cls(fd); start = show_run_time(fd); while(now - start < 5){ now = show_run_time(fd); sleep(1); } cls(fd); show_net_info(fd); sleep(5); cls(fd); show_client_count(fd); sleep(3); cls(fd); show_client_info(fd); cls(fd); show_temp(fd); sleep(5); cls(fd); } return 0; }
int myDate::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QLCDNumber::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: show_date(); break; default: ; } _id -= 1; } return _id; }
static void parse_dates(char **argv, struct timeval *now) { for (; *argv; argv++) { char result[100]; unsigned long t; int tz; result[0] = 0; parse_date(*argv, result, sizeof(result)); if (sscanf(result, "%lu %d", &t, &tz) == 2) printf("%s -> %s\n", *argv, show_date(t, tz, DATE_ISO8601)); else printf("%s -> bad\n", *argv); } }
static int show_widget (CmdConfig *cmd_config, CameraWidget *widget) { CameraWidget *parent; CameraWidgetType type; CHECK (gp_widget_get_type (widget, &type)); switch (type) { case GP_WIDGET_WINDOW: case GP_WIDGET_SECTION: CHECK (show_section (cmd_config, widget)); break; case GP_WIDGET_DATE: CHECK (show_date (cmd_config, widget)); CHECK (show_time (cmd_config, widget)); CHECK (gp_widget_get_parent (widget, &parent)); CHECK (show_widget (cmd_config, parent)); break; case GP_WIDGET_MENU: case GP_WIDGET_RADIO: CHECK (show_radio (cmd_config, widget)); CHECK (gp_widget_get_parent (widget, &parent)); CHECK (show_widget (cmd_config, parent)); break; case GP_WIDGET_RANGE: CHECK (show_range (cmd_config, widget)); CHECK (gp_widget_get_parent (widget, &parent)); CHECK (show_widget (cmd_config, parent)); break; case GP_WIDGET_TEXT: CHECK (show_text (cmd_config, widget)); CHECK (gp_widget_get_parent (widget, &parent)); CHECK (show_widget (cmd_config, parent)); break; case GP_WIDGET_TOGGLE: CHECK (show_toggle (cmd_config, widget)); CHECK (gp_widget_get_parent (widget, &parent)); CHECK (show_widget (cmd_config, parent)); break; default: return (GP_ERROR_NOT_SUPPORTED); } return (GP_OK); }
static void parse_dates(const char **argv, struct timeval *now) { struct strbuf result = STRBUF_INIT; for (; *argv; argv++) { unsigned long t; int tz; strbuf_reset(&result); parse_date(*argv, &result); if (sscanf(result.buf, "%lu %d", &t, &tz) == 2) printf("%s -> %s\n", *argv, show_date(t, tz, DATE_MODE(ISO8601))); else printf("%s -> bad\n", *argv); } strbuf_release(&result); }
const char *show_ident_date(const struct ident_split *ident, enum date_mode mode) { unsigned long date = 0; long tz = 0; if (ident->date_begin && ident->date_end) date = strtoul(ident->date_begin, NULL, 10); if (date_overflows(date)) date = 0; else { if (ident->tz_begin && ident->tz_end) tz = strtol(ident->tz_begin, NULL, 10); if (tz >= INT_MAX || tz <= INT_MIN) tz = 0; } return show_date(date, tz, mode); }
const char *show_ident_date(const struct ident_split *ident, const struct date_mode *mode) { timestamp_t date = 0; long tz = 0; if (ident->date_begin && ident->date_end) date = parse_timestamp(ident->date_begin, NULL, 10); if (date_overflows(date)) date = 0; else { if (ident->tz_begin && ident->tz_end) tz = strtol(ident->tz_begin, NULL, 10); if (tz >= INT_MAX || tz <= INT_MIN) tz = 0; } return show_date(date, tz, mode); }
static void show_tagger(char *buf, int len, struct rev_info *rev) { char *email_end, *p; unsigned long date; int tz; email_end = memchr(buf, '>', len); if (!email_end) return; p = ++email_end; while (isspace(*p)) p++; date = strtoul(p, &p, 10); while (isspace(*p)) p++; tz = (int)strtol(p, NULL, 10); printf("Tagger: %.*s\nDate: %s\n", (int)(email_end - buf), buf, show_date(date, tz, rev->date_mode)); }
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc) { show_utf8(b, "model ", dc->model, "\n"); if (dc->deviceid) put_format(b, "deviceid %08x\n", dc->deviceid); if (dc->diveid) put_format(b, "diveid %08x\n", dc->diveid); if (dc->when && dc->when != dive->when) show_date(b, dc->when); if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) put_duration(b, dc->duration, "duration ", "min\n"); save_depths(b, dc); save_temperatures(b, dc); save_airpressure(b, dc); save_salinity(b, dc); put_duration(b, dc->surfacetime, "surfacetime ", "min\n"); save_events(b, dc->events); save_samples(b, dc->samples, dc->sample); }
static void show_dates(const char **argv, const char *format) { struct date_mode mode; parse_date_format(format, &mode); for (; *argv; argv++) { char *arg; time_t t; int tz; /* * Do not use our normal timestamp parsing here, as the point * is to test the formatting code in isolation. */ t = strtol(*argv, &arg, 10); while (*arg == ' ') arg++; tz = atoi(arg); printf("%s -> %s\n", *argv, show_date(t, tz, &mode)); } }
int main(int argc, const char* argv[]) { STU *head = NULL; char choice; int flag = 1; put("please choice:"); choice = getchar(); getchar(); while(flag) { switch(choice) { case '1' : head = add_mate(head);break; case '2' : head = delate_mate(head);break; case '3' : show_date(head);break; // case '4' : save_date(head);break; case '5' : flag = 0;break; default :printf("sorry NO this choice,ARE YOU OK?\n"); } } return 0; }
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc) { put_format(b, " <divecomputer"); show_utf8(b, dc->model, " model='", "'", 1); if (dc->deviceid) put_format(b, " deviceid='%08x'", dc->deviceid); if (dc->diveid) put_format(b, " diveid='%08x'", dc->diveid); if (dc->when && dc->when != dive->when) show_date(b, dc->when); if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) put_duration(b, dc->duration, " duration='", " min'"); put_format(b, ">\n"); save_depths(b, dc); save_temperatures(b, dc); save_airpressure(b, dc); save_salinity(b, dc); put_duration(b, dc->surfacetime, " <surfacetime>", " min</surfacetime>\n"); save_events(b, dc->events); save_samples(b, dc->samples, dc->sample); put_format(b, " </divecomputer>\n"); }
static void save_trip(struct membuffer *b, dive_trip_t *trip) { int i; struct dive *dive; put_format(b, "<trip"); show_date(b, trip->when); show_utf8(b, trip->location, " location=\'", "\'", 1); put_format(b, ">\n"); show_utf8(b, trip->notes, "<notes>", "</notes>\n", 0); /* * Incredibly cheesy: we want to save the dives sorted, and they * are sorted in the dive array.. So instead of using the dive * list in the trip, we just traverse the global dive array and * check the divetrip pointer.. */ for_each_dive(i, dive) { if (dive->divetrip == trip) save_one_dive_to_mb(b, dive); } put_format(b, "</trip>\n"); }
int main(int argn ,char *argv[]) { char in[100]; while(1) { int n = strlen(para[0]); printf("%s->", para[0]); memset(in, 0, sizeof(in)); gets(in); int choice = explain(in); //根据命令解释器的返回结果执行相对应的命令 switch(choice) { case -1: printf("' %s '不是内部或外部命令,也不是可运行的程序\n或批处理文件。\n", in);break; case 0 : show_time();break; case 1 : show_version();break; case 2 : show_date();break; case 3 : clrscr(0, 0);break; case 4 : show_directory();break; case 5 : help();break; case 6 : show_current_tree(para[0], 0);break; case 7 : return 0; case 8 : print_text(para[0]);break; case 9 : if(del_dir(para[0]) == 0) del_files(para[0]);break;//如果para[0]是文件夹,则执行删除文件夹函数,否则执行文件删除函数 case 10 : creat_dir(para[0]);break; case 11 : rename_file(para[0], para[1]);break; case 12 : change_path(in);break; }//{"time", "version", "date", "cls", "dir", "help", "tree", "print", "del", "mkdir", "ren"}; if(choice != 12)//如果没有改变路径,则每次都把当前工作目录下的以外的其它字符清除 { memset(para[0] + n, 0, (100 - n) * sizeof(char)); memset(para[1] + n, 0, (100 - n) * sizeof(char)); } } return 0; }
int cmd_show_branch(int ac, const char **av, const char *prefix) { struct commit *rev[MAX_REVS], *commit; char *reflog_msg[MAX_REVS]; struct commit_list *list = NULL, *seen = NULL; unsigned int rev_mask[MAX_REVS]; int num_rev, i, extra = 0; int all_heads = 0, all_remotes = 0; int all_mask, all_revs; int lifo = 1; char head[128]; const char *head_p; int head_len; unsigned char head_sha1[20]; int merge_base = 0; int independent = 0; int no_name = 0; int sha1_name = 0; int shown_merge_point = 0; int with_current_branch = 0; int head_at = -1; int topics = 0; int dense = 1; const char *reflog_base = NULL; struct option builtin_show_branch_options[] = { OPT_BOOLEAN('a', "all", &all_heads, "show remote-tracking and local branches"), OPT_BOOLEAN('r', "remotes", &all_remotes, "show remote-tracking branches"), OPT__COLOR(&showbranch_use_color, "color '*!+-' corresponding to the branch"), { OPTION_INTEGER, 0, "more", &extra, "n", "show <n> more commits after the common ancestor", PARSE_OPT_OPTARG, NULL, (intptr_t)1 }, OPT_SET_INT(0, "list", &extra, "synonym to more=-1", -1), OPT_BOOLEAN(0, "no-name", &no_name, "suppress naming strings"), OPT_BOOLEAN(0, "current", &with_current_branch, "include the current branch"), OPT_BOOLEAN(0, "sha1-name", &sha1_name, "name commits with their object names"), OPT_BOOLEAN(0, "merge-base", &merge_base, "show possible merge bases"), OPT_BOOLEAN(0, "independent", &independent, "show refs unreachable from any other ref"), OPT_BOOLEAN(0, "topo-order", &lifo, "show commits in topological order"), OPT_BOOLEAN(0, "topics", &topics, "show only commits not on the first branch"), OPT_SET_INT(0, "sparse", &dense, "show merges reachable from only one tip", 0), OPT_SET_INT(0, "date-order", &lifo, "show commits where no parent comes before its " "children", 0), { OPTION_CALLBACK, 'g', "reflog", &reflog_base, "<n>[,<base>]", "show <n> most recent ref-log entries starting at " "base", PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parse_reflog_param }, OPT_END() }; git_config(git_show_branch_config, NULL); if (showbranch_use_color == -1) showbranch_use_color = git_use_color_default; /* If nothing is specified, try the default first */ if (ac == 1 && default_num) { ac = default_num; av = default_arg; } ac = parse_options(ac, av, prefix, builtin_show_branch_options, show_branch_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (all_heads) all_remotes = 1; if (extra || reflog) { /* "listing" mode is incompatible with * independent nor merge-base modes. */ if (independent || merge_base) usage_with_options(show_branch_usage, builtin_show_branch_options); if (reflog && ((0 < extra) || all_heads || all_remotes)) /* * Asking for --more in reflog mode does not * make sense. --list is Ok. * * Also --all and --remotes do not make sense either. */ die("--reflog is incompatible with --all, --remotes, " "--independent or --merge-base"); } /* If nothing is specified, show all branches by default */ if (ac + all_heads + all_remotes == 0) all_heads = 1; if (reflog) { unsigned char sha1[20]; char nth_desc[256]; char *ref; int base = 0; if (ac == 0) { static const char *fake_av[2]; const char *refname; refname = resolve_ref("HEAD", sha1, 1, NULL); fake_av[0] = xstrdup(refname); fake_av[1] = NULL; av = fake_av; ac = 1; } if (ac != 1) die("--reflog option needs one branch name"); if (MAX_REVS < reflog) die("Only %d entries can be shown at one time.", MAX_REVS); if (!dwim_ref(*av, strlen(*av), sha1, &ref)) die("No such ref %s", *av); /* Has the base been specified? */ if (reflog_base) { char *ep; base = strtoul(reflog_base, &ep, 10); if (*ep) { /* Ah, that is a date spec... */ unsigned long at; at = approxidate(reflog_base); read_ref_at(ref, at, -1, sha1, NULL, NULL, NULL, &base); } } for (i = 0; i < reflog; i++) { char *logmsg, *m; const char *msg; unsigned long timestamp; int tz; if (read_ref_at(ref, 0, base+i, sha1, &logmsg, ×tamp, &tz, NULL)) { reflog = i; break; } msg = strchr(logmsg, '\t'); if (!msg) msg = "(none)"; else msg++; m = xmalloc(strlen(msg) + 200); sprintf(m, "(%s) %s", show_date(timestamp, tz, 1), msg); reflog_msg[i] = m; free(logmsg); sprintf(nth_desc, "%s@{%d}", *av, base+i); append_ref(nth_desc, sha1, 1); } } else if (all_heads + all_remotes) snarf_refs(all_heads, all_remotes); else { while (0 < ac) { append_one_rev(*av); ac--; av++; } } head_p = resolve_ref("HEAD", head_sha1, 1, NULL); if (head_p) { head_len = strlen(head_p); memcpy(head, head_p, head_len + 1); } else { head_len = 0; head[0] = 0; } if (with_current_branch && head_p) { int has_head = 0; for (i = 0; !has_head && i < ref_name_cnt; i++) { /* We are only interested in adding the branch * HEAD points at. */ if (rev_is_head(head, head_len, ref_name[i], head_sha1, NULL)) has_head++; } if (!has_head) { int offset = !prefixcmp(head, "refs/heads/") ? 11 : 0; append_one_rev(head + offset); } } if (!ref_name_cnt) { fprintf(stderr, "No revs to be shown.\n"); exit(0); } for (num_rev = 0; ref_name[num_rev]; num_rev++) { unsigned char revkey[20]; unsigned int flag = 1u << (num_rev + REV_SHIFT); if (MAX_REVS <= num_rev) die("cannot handle more than %d revs.", MAX_REVS); if (get_sha1(ref_name[num_rev], revkey)) die("'%s' is not a valid ref.", ref_name[num_rev]); commit = lookup_commit_reference(revkey); if (!commit) die("cannot find commit %s (%s)", ref_name[num_rev], revkey); parse_commit(commit); mark_seen(commit, &seen); /* rev#0 uses bit REV_SHIFT, rev#1 uses bit REV_SHIFT+1, * and so on. REV_SHIFT bits from bit 0 are used for * internal bookkeeping. */ commit->object.flags |= flag; if (commit->object.flags == flag) commit_list_insert_by_date(commit, &list); rev[num_rev] = commit; } for (i = 0; i < num_rev; i++) rev_mask[i] = rev[i]->object.flags; if (0 <= extra) join_revs(&list, &seen, num_rev, extra); commit_list_sort_by_date(&seen); if (merge_base) return show_merge_base(seen, num_rev); if (independent) return show_independent(rev, num_rev, ref_name, rev_mask); /* Show list; --more=-1 means list-only */ if (1 < num_rev || extra < 0) { for (i = 0; i < num_rev; i++) { int j; int is_head = rev_is_head(head, head_len, ref_name[i], head_sha1, rev[i]->object.sha1); if (extra < 0) printf("%c [%s] ", is_head ? '*' : ' ', ref_name[i]); else { for (j = 0; j < i; j++) putchar(' '); printf("%s%c%s [%s] ", get_color_code(i % COLUMN_COLORS_MAX), is_head ? '*' : '!', get_color_reset_code(), ref_name[i]); } if (!reflog) { /* header lines never need name */ show_one_commit(rev[i], 1); } else puts(reflog_msg[i]); if (is_head) head_at = i; } if (0 <= extra) { for (i = 0; i < num_rev; i++) putchar('-'); putchar('\n'); } } if (extra < 0) exit(0); /* Sort topologically */ sort_in_topological_order(&seen, lifo); /* Give names to commits */ if (!sha1_name && !no_name) name_commits(seen, rev, ref_name, num_rev); all_mask = ((1u << (REV_SHIFT + num_rev)) - 1); all_revs = all_mask & ~((1u << REV_SHIFT) - 1); while (seen) { struct commit *commit = pop_one_commit(&seen); int this_flag = commit->object.flags; int is_merge_point = ((this_flag & all_revs) == all_revs); shown_merge_point |= is_merge_point; if (1 < num_rev) { int is_merge = !!(commit->parents && commit->parents->next); if (topics && !is_merge_point && (this_flag & (1u << REV_SHIFT))) continue; if (dense && is_merge && omit_in_dense(commit, rev, num_rev)) continue; for (i = 0; i < num_rev; i++) { int mark; if (!(this_flag & (1u << (i + REV_SHIFT)))) mark = ' '; else if (is_merge) mark = '-'; else if (i == head_at) mark = '*'; else mark = '+'; printf("%s%c%s", get_color_code(i % COLUMN_COLORS_MAX), mark, get_color_reset_code()); } putchar(' '); } show_one_commit(commit, no_name); if (shown_merge_point && --extra < 0) break; } return 0; }
static size_t format_person_part(struct strbuf *sb, char part, const char *msg, int len, enum date_mode dmode) { /* currently all placeholders have same length */ const int placeholder_len = 2; int start, end, tz = 0; unsigned long date = 0; char *ep; const char *name_start, *name_end, *mail_start, *mail_end, *msg_end = msg+len; char person_name[1024]; char person_mail[1024]; /* advance 'end' to point to email start delimiter */ for (end = 0; end < len && msg[end] != '<'; end++) ; /* do nothing */ /* * When end points at the '<' that we found, it should have * matching '>' later, which means 'end' must be strictly * below len - 1. */ if (end >= len - 2) goto skip; /* Seek for both name and email part */ name_start = msg; name_end = msg+end; while (name_end > name_start && isspace(*(name_end-1))) name_end--; mail_start = msg+end+1; mail_end = mail_start; while (mail_end < msg_end && *mail_end != '>') mail_end++; if (mail_end == msg_end) goto skip; end = mail_end-msg; if (part == 'N' || part == 'E') { /* mailmap lookup */ strlcpy(person_name, name_start, name_end-name_start+1); strlcpy(person_mail, mail_start, mail_end-mail_start+1); mailmap_name(person_mail, sizeof(person_mail), person_name, sizeof(person_name)); name_start = person_name; name_end = name_start + strlen(person_name); mail_start = person_mail; mail_end = mail_start + strlen(person_mail); } if (part == 'n' || part == 'N') { /* name */ strbuf_add(sb, name_start, name_end-name_start); return placeholder_len; } if (part == 'e' || part == 'E') { /* email */ strbuf_add(sb, mail_start, mail_end-mail_start); return placeholder_len; } /* advance 'start' to point to date start delimiter */ for (start = end + 1; start < len && isspace(msg[start]); start++) ; /* do nothing */ if (start >= len) goto skip; date = strtoul(msg + start, &ep, 10); if (msg + start == ep) goto skip; if (part == 't') { /* date, UNIX timestamp */ strbuf_add(sb, msg + start, ep - (msg + start)); return placeholder_len; } /* parse tz */ for (start = ep - msg + 1; start < len && isspace(msg[start]); start++) ; /* do nothing */ if (start + 1 < len) { tz = strtoul(msg + start + 1, NULL, 10); if (msg[start] == '-') tz = -tz; } switch (part) { case 'd': /* date */ strbuf_addstr(sb, show_date(date, tz, dmode)); return placeholder_len; case 'D': /* date, RFC2822 style */ strbuf_addstr(sb, show_date(date, tz, DATE_RFC2822)); return placeholder_len; case 'r': /* date, relative */ strbuf_addstr(sb, show_date(date, tz, DATE_RELATIVE)); return placeholder_len; case 'i': /* date, ISO 8601 */ strbuf_addstr(sb, show_date(date, tz, DATE_ISO8601)); return placeholder_len; } skip: /* * bogus commit, 'sb' cannot be updated, but we still need to * compute a valid return value. */ if (part == 'n' || part == 'e' || part == 't' || part == 'd' || part == 'D' || part == 'r' || part == 'i') return placeholder_len; return 0; /* unknown placeholder */ }
static void hdr_date(const char *name, unsigned long when) { const char *value = show_date(when, 0, DATE_RFC2822); hdr_str(name, value); }
static void hdr_date(struct strbuf *hdr, const char *name, unsigned long when) { const char *value = show_date(when, 0, DATE_MODE(RFC2822)); hdr_str(hdr, name, value); }
static void pprint_tag(const unsigned char *sha1, const char *buf, unsigned long size) { /* the parser in tag.c is useless here. */ const char *endp = buf + size; const char *cp = buf; while (cp < endp) { char c = *cp++; if (c != '\n') continue; if (7 <= endp - cp && !memcmp("tagger ", cp, 7)) { const char *tagger = cp; /* Found the tagger line. Copy out the contents * of the buffer so far. */ write_or_die(1, buf, cp - buf); /* * Do something intelligent, like pretty-printing * the date. */ while (cp < endp) { if (*cp++ == '\n') { /* tagger to cp is a line * that has ident and time. */ const char *sp = tagger; char *ep; unsigned long date; long tz; while (sp < cp && *sp != '>') sp++; if (sp == cp) { /* give up */ write_or_die(1, tagger, cp - tagger); break; } while (sp < cp && !('0' <= *sp && *sp <= '9')) sp++; write_or_die(1, tagger, sp - tagger); date = strtoul(sp, &ep, 10); tz = strtol(ep, NULL, 10); sp = show_date(date, tz, 0); write_or_die(1, sp, strlen(sp)); xwrite(1, "\n", 1); break; } } break; } if (cp < endp && *cp == '\n') /* end of header */ break; } /* At this point, we have copied out the header up to the end of * the tagger line and cp points at one past \n. It could be the * next header line after the tagger line, or it could be another * \n that marks the end of the headers. We need to copy out the * remainder as is. */ if (cp < endp) write_or_die(1, cp, endp - cp); }
int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt) { const char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec; char *tz_c; int logfd, tz, reccnt = 0; struct stat st; unsigned long date; unsigned char logged_sha1[20]; void *log_mapped; size_t mapsz; logfile = git_path("logs/%s", ref); logfd = open(logfile, O_RDONLY, 0); if (logfd < 0) die_errno("Unable to read log '%s'", logfile); fstat(logfd, &st); if (!st.st_size) die("Log %s is empty.", logfile); mapsz = xsize_t(st.st_size); log_mapped = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, logfd, 0); logdata = log_mapped; close(logfd); lastrec = NULL; rec = logend = logdata + st.st_size; while (logdata < rec) { reccnt++; if (logdata < rec && *(rec-1) == '\n') rec--; lastgt = NULL; while (logdata < rec && *(rec-1) != '\n') { rec--; if (*rec == '>') lastgt = rec; } if (!lastgt) die("Log %s is corrupt.", logfile); date = strtoul(lastgt + 1, &tz_c, 10); if (date <= at_time || cnt == 0) { tz = strtoul(tz_c, NULL, 10); if (msg) *msg = ref_msg(rec, logend); if (cutoff_time) *cutoff_time = date; if (cutoff_tz) *cutoff_tz = tz; if (cutoff_cnt) *cutoff_cnt = reccnt - 1; if (lastrec) { if (get_sha1_hex(lastrec, logged_sha1)) die("Log %s is corrupt.", logfile); if (get_sha1_hex(rec + 41, sha1)) die("Log %s is corrupt.", logfile); if (hashcmp(logged_sha1, sha1)) { warning("Log %s has gap after %s.", logfile, show_date(date, tz, DATE_RFC2822)); } } else if (date == at_time) { if (get_sha1_hex(rec + 41, sha1)) die("Log %s is corrupt.", logfile); } else { if (get_sha1_hex(rec + 41, logged_sha1)) die("Log %s is corrupt.", logfile); if (hashcmp(logged_sha1, sha1)) { warning("Log %s unexpectedly ended on %s.", logfile, show_date(date, tz, DATE_RFC2822)); } } munmap(log_mapped, mapsz); return 0; } lastrec = rec; if (cnt > 0) cnt--; } rec = logdata; while (rec < logend && *rec != '>' && *rec != '\n') rec++; if (rec == logend || *rec == '\n') die("Log %s is corrupt.", logfile); date = strtoul(rec + 1, &tz_c, 10); tz = strtoul(tz_c, NULL, 10); if (get_sha1_hex(logdata, sha1)) die("Log %s is corrupt.", logfile); if (is_null_sha1(sha1)) { if (get_sha1_hex(logdata + 41, sha1)) die("Log %s is corrupt.", logfile); } if (msg) *msg = ref_msg(logdata, logend); munmap(log_mapped, mapsz); if (cutoff_time) *cutoff_time = date; if (cutoff_tz) *cutoff_tz = tz; if (cutoff_cnt) *cutoff_cnt = reccnt; return 1; }