Skip to content

Commit 52e0938

Browse files
jeffhostetlerdscho
authored andcommitted
status: collect per-file data for --porcelain=v2
Collect extra per-file data for porcelain V2 format. The output of `git status --porcelain` leaves out many details about the current status that clients might like to have. This can force them to be less efficient as they may need to launch secondary commands (and try to match the logic within git) to accumulate this extra information. For example, a GUI IDE might want the file mode to display the correct icon for a changed item (without having to stat it afterwards). Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0a0d6db commit 52e0938

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

builtin/commit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ static int opt_parse_porcelain(const struct option *opt, const char *arg, int un
153153
*value = STATUS_FORMAT_PORCELAIN;
154154
else if (!strcmp(arg, "v1") || !strcmp(arg, "1"))
155155
*value = STATUS_FORMAT_PORCELAIN;
156+
else if (!strcmp(arg, "v2") || !strcmp(arg, "2"))
157+
*value = STATUS_FORMAT_PORCELAIN_V2;
156158
else
157159
die("unsupported porcelain version '%s'", arg);
158160

@@ -1104,6 +1106,7 @@ static struct status_deferred_config {
11041106
static void finalize_deferred_config(struct wt_status *s)
11051107
{
11061108
int use_deferred_config = (status_format != STATUS_FORMAT_PORCELAIN &&
1109+
status_format != STATUS_FORMAT_PORCELAIN_V2 &&
11071110
!s->null_termination);
11081111

11091112
if (s->null_termination) {

wt-status.c

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,31 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
434434
if (S_ISGITLINK(p->two->mode))
435435
d->new_submodule_commits = !!oidcmp(&p->one->oid,
436436
&p->two->oid);
437+
438+
switch (p->status) {
439+
case DIFF_STATUS_ADDED:
440+
die("BUG: worktree status add???");
441+
break;
442+
443+
case DIFF_STATUS_DELETED:
444+
d->mode_index = p->one->mode;
445+
oidcpy(&d->oid_index, &p->one->oid);
446+
/* mode_worktree is zero for a delete. */
447+
break;
448+
449+
case DIFF_STATUS_MODIFIED:
450+
case DIFF_STATUS_TYPE_CHANGED:
451+
case DIFF_STATUS_UNMERGED:
452+
d->mode_index = p->one->mode;
453+
d->mode_worktree = p->two->mode;
454+
oidcpy(&d->oid_index, &p->one->oid);
455+
break;
456+
457+
case DIFF_STATUS_UNKNOWN:
458+
die("BUG: worktree status unknown???");
459+
break;
460+
}
461+
437462
}
438463
}
439464

@@ -479,12 +504,36 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
479504
if (!d->index_status)
480505
d->index_status = p->status;
481506
switch (p->status) {
507+
case DIFF_STATUS_ADDED:
508+
/* Leave {mode,oid}_head zero for an add. */
509+
d->mode_index = p->two->mode;
510+
oidcpy(&d->oid_index, &p->two->oid);
511+
break;
512+
case DIFF_STATUS_DELETED:
513+
d->mode_head = p->one->mode;
514+
oidcpy(&d->oid_head, &p->one->oid);
515+
/* Leave {mode,oid}_index zero for a delete. */
516+
break;
517+
482518
case DIFF_STATUS_COPIED:
483519
case DIFF_STATUS_RENAMED:
484520
d->head_path = xstrdup(p->one->path);
521+
d->score = p->score * 100 / MAX_SCORE;
522+
/* fallthru */
523+
case DIFF_STATUS_MODIFIED:
524+
case DIFF_STATUS_TYPE_CHANGED:
525+
d->mode_head = p->one->mode;
526+
d->mode_index = p->two->mode;
527+
oidcpy(&d->oid_head, &p->one->oid);
528+
oidcpy(&d->oid_index, &p->two->oid);
485529
break;
486530
case DIFF_STATUS_UNMERGED:
487531
d->stagemask = unmerged_mask(p->two->path);
532+
/*
533+
* Don't bother setting {mode,oid}_{head,index} since the print
534+
* code will output the stage values directly and not use the
535+
* values in these fields.
536+
*/
488537
break;
489538
}
490539
}
@@ -565,9 +614,17 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
565614
if (ce_stage(ce)) {
566615
d->index_status = DIFF_STATUS_UNMERGED;
567616
d->stagemask |= (1 << (ce_stage(ce) - 1));
568-
}
569-
else
617+
/*
618+
* Don't bother setting {mode,oid}_{head,index} since the print
619+
* code will output the stage values directly and not use the
620+
* values in these fields.
621+
*/
622+
} else {
570623
d->index_status = DIFF_STATUS_ADDED;
624+
/* Leave {mode,oid}_head zero for adds. */
625+
d->mode_index = ce->ce_mode;
626+
hashcpy(d->oid_index.hash, ce->sha1);
627+
}
571628
}
572629
}
573630

@@ -1767,6 +1824,9 @@ void wt_status_print(struct wt_status *s)
17671824
case STATUS_FORMAT_PORCELAIN:
17681825
wt_porcelain_print(s);
17691826
break;
1827+
case STATUS_FORMAT_PORCELAIN_V2:
1828+
/* TODO */
1829+
break;
17701830
case STATUS_FORMAT_UNSPECIFIED:
17711831
die("BUG: finalize_deferred_config() should have been called");
17721832
break;

wt-status.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct wt_status_change_data {
3838
int worktree_status;
3939
int index_status;
4040
int stagemask;
41+
int score;
42+
int mode_head, mode_index, mode_worktree;
43+
struct object_id oid_head, oid_index;
4144
char *head_path;
4245
unsigned dirty_submodule : 2;
4346
unsigned new_submodule_commits : 1;
@@ -48,6 +51,7 @@ enum wt_status_format {
4851
STATUS_FORMAT_LONG,
4952
STATUS_FORMAT_SHORT,
5053
STATUS_FORMAT_PORCELAIN,
54+
STATUS_FORMAT_PORCELAIN_V2,
5155

5256
STATUS_FORMAT_UNSPECIFIED
5357
};

0 commit comments

Comments
 (0)