Skip to content

Commit aec4bc4

Browse files
committed
Merge 'sequencer-i' into HEAD
2 parents 49981d8 + de74a6c commit aec4bc4

File tree

14 files changed

+2892
-474
lines changed

14 files changed

+2892
-474
lines changed

Documentation/git-status.txt

Lines changed: 127 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ OPTIONS
3232
--branch::
3333
Show the branch and tracking info even in short-format.
3434

35-
--porcelain::
35+
--porcelain[=<version>]::
3636
Give the output in an easy-to-parse format for scripts.
3737
This is similar to the short output, but will remain stable
3838
across Git versions and regardless of user configuration. See
3939
below for details.
40+
+
41+
The version parameter is used to specify the format version.
42+
This is optional and defaults to the original version 'v1' format.
4043

4144
--long::
4245
Give the output in the long-format. This is the default.
@@ -96,7 +99,7 @@ configuration variable documented in linkgit:git-config[1].
9699

97100
-z::
98101
Terminate entries with NUL, instead of LF. This implies
99-
the `--porcelain` output format if no other format is given.
102+
the `--porcelain=v1` output format if no other format is given.
100103

101104
--column[=<options>]::
102105
--no-column::
@@ -180,12 +183,12 @@ in which case `XY` are `!!`.
180183

181184
If -b is used the short-format status is preceded by a line
182185

183-
## branchname tracking info
186+
## branchname tracking info
184187

185-
Porcelain Format
186-
~~~~~~~~~~~~~~~~
188+
Porcelain Format Version 1
189+
~~~~~~~~~~~~~~~~~~~~~~~~~~
187190

188-
The porcelain format is similar to the short format, but is guaranteed
191+
Version 1 porcelain format is similar to the short format, but is guaranteed
189192
not to change in a backwards-incompatible way between Git versions or
190193
based on user configuration. This makes it ideal for parsing by scripts.
191194
The description of the short format above also describes the porcelain
@@ -207,6 +210,124 @@ field from the first filename). Third, filenames containing special
207210
characters are not specially formatted; no quoting or
208211
backslash-escaping is performed.
209212

213+
Porcelain Format Version 2
214+
~~~~~~~~~~~~~~~~~~~~~~~~~~
215+
216+
Version 2 format adds more detailed information about the state of
217+
the worktree and changed items. Version 2 also defines an extensible
218+
set of easy to parse optional headers.
219+
220+
Header lines start with "#" and are added in response to specific
221+
command line arguments. Parsers should ignore headers they
222+
don't recognize.
223+
224+
### Branch Headers
225+
226+
If `--branch` is given, a series of header lines are printed with
227+
information about the current branch.
228+
229+
Line Notes
230+
------------------------------------------------------------
231+
# branch.oid <commit> | (initial) Current commit.
232+
# branch.head <branch> | (detached) Current branch.
233+
# branch.upstream <upstream_branch> If upstream is set.
234+
# branch.ab +<ahead> -<behind> If upstream is set and
235+
the commit is present.
236+
------------------------------------------------------------
237+
238+
### Changed Tracked Entries
239+
240+
Following the headers, a series of lines are printed for tracked
241+
entries. One of three different line formats may be used to describe
242+
an entry depending on the type of change. Tracked entries are printed
243+
in an undefined order; parsers should allow for a mixture of the 3
244+
line types in any order.
245+
246+
Ordinary changed entries have the following format:
247+
248+
1 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <path>
249+
250+
Renamed or copied entries have the following format:
251+
252+
2 <XY> <sub> <mH> <mI> <mW> <hH> <hI> <X><score> <path><sep><origPath>
253+
254+
Field Meaning
255+
--------------------------------------------------------
256+
<XY> A 2 character field containing the staged and
257+
unstaged XY values described in the short format,
258+
with unchanged indicated by a "." rather than
259+
a space.
260+
<sub> A 4 character field describing the submodule state.
261+
"N..." when the entry is not a submodule.
262+
"S<c><m><u>" when the entry is a submodule.
263+
<c> is "C" if the commit changed; otherwise ".".
264+
<m> is "M" if it has tracked changes; otherwise ".".
265+
<u> is "U" if there are untracked changes; otherwise ".".
266+
<mH> The octal file mode in HEAD.
267+
<mI> The octal file mode in the index.
268+
<mW> The octal file mode in the worktree.
269+
<hH> The object name in HEAD.
270+
<hI> The object name in the index.
271+
<X><score> The rename or copy score (denoting the percentage
272+
of similarity between the source and target of the
273+
move or copy). For example "R100" or "C75".
274+
<path> The pathname. In a renamed/copied entry, this
275+
is the path in the index and in the working tree.
276+
<sep> When the `-z` option is used, the 2 pathnames are separated
277+
with a NUL (ASCII 0x00) byte; otherwise, a tab (ASCII 0x09)
278+
byte separates them.
279+
<origPath> The pathname in the commit at HEAD. This is only
280+
present in a renamed/copied entry, and tells
281+
where the renamed/copied contents came from.
282+
--------------------------------------------------------
283+
284+
Unmerged entries have the following format; the first character is
285+
a "u" to distinguish from ordinary changed entries.
286+
287+
u <xy> <sub> <m1> <m2> <m3> <mW> <h1> <h2> <h3> <path>
288+
289+
Field Meaning
290+
--------------------------------------------------------
291+
<XY> A 2 character field describing the conflict type
292+
as described in the short format.
293+
<sub> A 4 character field describing the submodule state
294+
as described above.
295+
<m1> The octal file mode in stage 1.
296+
<m2> The octal file mode in stage 2.
297+
<m3> The octal file mode in stage 3.
298+
<mW> The octal file mode in the worktree.
299+
<h1> The object name in stage 1.
300+
<h2> The object name in stage 2.
301+
<h3> The object name in stage 3.
302+
<path> The pathname.
303+
--------------------------------------------------------
304+
305+
### Other Items
306+
307+
Following the tracked entries (and if requested), a series of
308+
lines will be printed for untracked and then ignored items
309+
found in the worktree.
310+
311+
Untracked items have the following format:
312+
313+
? <path>
314+
315+
Ignored items have the following format:
316+
317+
! <path>
318+
319+
### Pathname Format Notes and -z
320+
321+
When the `-z` option is given, pathnames are printed as is and
322+
without any quoting and lines are terminated with a NUL (ASCII 0x00)
323+
byte.
324+
325+
Otherwise, all pathnames will be "C-quoted" if they contain any tab,
326+
linefeed, double quote, or backslash characters. In C-quoting, these
327+
characters will be replaced with the corresponding C-style escape
328+
sequences and the resulting pathname will be double quoted.
329+
330+
210331
CONFIGURATION
211332
-------------
212333

builtin/commit.c

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,24 @@ static int show_ignored_in_status, have_option_m;
142142
static const char *only_include_assumed;
143143
static struct strbuf message = STRBUF_INIT;
144144

145-
static enum status_format {
146-
STATUS_FORMAT_NONE = 0,
147-
STATUS_FORMAT_LONG,
148-
STATUS_FORMAT_SHORT,
149-
STATUS_FORMAT_PORCELAIN,
145+
static enum wt_status_format status_format = STATUS_FORMAT_UNSPECIFIED;
150146

151-
STATUS_FORMAT_UNSPECIFIED
152-
} status_format = STATUS_FORMAT_UNSPECIFIED;
147+
static int opt_parse_porcelain(const struct option *opt, const char *arg, int unset)
148+
{
149+
enum wt_status_format *value = (enum wt_status_format *)opt->value;
150+
if (unset)
151+
*value = STATUS_FORMAT_NONE;
152+
else if (!arg)
153+
*value = STATUS_FORMAT_PORCELAIN;
154+
else if (!strcmp(arg, "v1") || !strcmp(arg, "1"))
155+
*value = STATUS_FORMAT_PORCELAIN;
156+
else if (!strcmp(arg, "v2") || !strcmp(arg, "2"))
157+
*value = STATUS_FORMAT_PORCELAIN_V2;
158+
else
159+
die("unsupported porcelain version '%s'", arg);
160+
161+
return 0;
162+
}
153163

154164
static int opt_parse_m(const struct option *opt, const char *arg, int unset)
155165
{
@@ -173,7 +183,7 @@ static void determine_whence(struct wt_status *s)
173183
whence = FROM_MERGE;
174184
else if (file_exists(git_path_cherry_pick_head())) {
175185
whence = FROM_CHERRY_PICK;
176-
if (file_exists(git_path(SEQ_DIR)))
186+
if (file_exists(git_path_seq_dir()))
177187
sequencer_in_use = 1;
178188
}
179189
else
@@ -500,24 +510,13 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
500510
s->fp = fp;
501511
s->nowarn = nowarn;
502512
s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
513+
if (!s->is_initial)
514+
hashcpy(s->sha1_commit, sha1);
515+
s->status_format = status_format;
516+
s->ignore_submodule_arg = ignore_submodule_arg;
503517

504518
wt_status_collect(s);
505-
506-
switch (status_format) {
507-
case STATUS_FORMAT_SHORT:
508-
wt_shortstatus_print(s);
509-
break;
510-
case STATUS_FORMAT_PORCELAIN:
511-
wt_porcelain_print(s);
512-
break;
513-
case STATUS_FORMAT_UNSPECIFIED:
514-
die("BUG: finalize_deferred_config() should have been called");
515-
break;
516-
case STATUS_FORMAT_NONE:
517-
case STATUS_FORMAT_LONG:
518-
wt_status_print(s);
519-
break;
520-
}
519+
wt_status_print(s);
521520

522521
return s->commitable;
523522
}
@@ -1099,7 +1098,7 @@ static const char *read_commit_message(const char *name)
10991098
* is not in effect here.
11001099
*/
11011100
static struct status_deferred_config {
1102-
enum status_format status_format;
1101+
enum wt_status_format status_format;
11031102
int show_branch;
11041103
} status_deferred_config = {
11051104
STATUS_FORMAT_UNSPECIFIED,
@@ -1109,6 +1108,7 @@ static struct status_deferred_config {
11091108
static void finalize_deferred_config(struct wt_status *s)
11101109
{
11111110
int use_deferred_config = (status_format != STATUS_FORMAT_PORCELAIN &&
1111+
status_format != STATUS_FORMAT_PORCELAIN_V2 &&
11121112
!s->null_termination);
11131113

11141114
if (s->null_termination) {
@@ -1336,9 +1336,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13361336
N_("show status concisely"), STATUS_FORMAT_SHORT),
13371337
OPT_BOOL('b', "branch", &s.show_branch,
13381338
N_("show branch information")),
1339-
OPT_SET_INT(0, "porcelain", &status_format,
1340-
N_("machine-readable output"),
1341-
STATUS_FORMAT_PORCELAIN),
1339+
{ OPTION_CALLBACK, 0, "porcelain", &status_format,
1340+
N_("version"), N_("machine-readable output"),
1341+
PARSE_OPT_OPTARG, opt_parse_porcelain },
13421342
OPT_SET_INT(0, "long", &status_format,
13431343
N_("show status in long format (default)"),
13441344
STATUS_FORMAT_LONG),
@@ -1380,7 +1380,13 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13801380
fd = hold_locked_index(&index_lock, 0);
13811381

13821382
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
1383+
if (!s.is_initial)
1384+
hashcpy(s.sha1_commit, sha1);
1385+
13831386
s.ignore_submodule_arg = ignore_submodule_arg;
1387+
s.status_format = status_format;
1388+
s.verbose = verbose;
1389+
13841390
wt_status_collect(&s);
13851391

13861392
if (0 <= fd)
@@ -1389,23 +1395,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13891395
if (s.relative_paths)
13901396
s.prefix = prefix;
13911397

1392-
switch (status_format) {
1393-
case STATUS_FORMAT_SHORT:
1394-
wt_shortstatus_print(&s);
1395-
break;
1396-
case STATUS_FORMAT_PORCELAIN:
1397-
wt_porcelain_print(&s);
1398-
break;
1399-
case STATUS_FORMAT_UNSPECIFIED:
1400-
die("BUG: finalize_deferred_config() should have been called");
1401-
break;
1402-
case STATUS_FORMAT_NONE:
1403-
case STATUS_FORMAT_LONG:
1404-
s.verbose = verbose;
1405-
s.ignore_submodule_arg = ignore_submodule_arg;
1406-
wt_status_print(&s);
1407-
break;
1408-
}
1398+
wt_status_print(&s);
14091399
return 0;
14101400
}
14111401

builtin/pull.c

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "revision.h"
1818
#include "tempfile.h"
1919
#include "lockfile.h"
20+
#include "wt-status.h"
2021

2122
enum rebase_type {
2223
REBASE_INVALID = -1,
@@ -325,73 +326,6 @@ static int git_pull_config(const char *var, const char *value, void *cb)
325326
return git_default_config(var, value, cb);
326327
}
327328

328-
/**
329-
* Returns 1 if there are unstaged changes, 0 otherwise.
330-
*/
331-
static int has_unstaged_changes(const char *prefix)
332-
{
333-
struct rev_info rev_info;
334-
int result;
335-
336-
init_revisions(&rev_info, prefix);
337-
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
338-
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
339-
diff_setup_done(&rev_info.diffopt);
340-
result = run_diff_files(&rev_info, 0);
341-
return diff_result_code(&rev_info.diffopt, result);
342-
}
343-
344-
/**
345-
* Returns 1 if there are uncommitted changes, 0 otherwise.
346-
*/
347-
static int has_uncommitted_changes(const char *prefix)
348-
{
349-
struct rev_info rev_info;
350-
int result;
351-
352-
if (is_cache_unborn())
353-
return 0;
354-
355-
init_revisions(&rev_info, prefix);
356-
DIFF_OPT_SET(&rev_info.diffopt, IGNORE_SUBMODULES);
357-
DIFF_OPT_SET(&rev_info.diffopt, QUICK);
358-
add_head_to_pending(&rev_info);
359-
diff_setup_done(&rev_info.diffopt);
360-
result = run_diff_index(&rev_info, 1);
361-
return diff_result_code(&rev_info.diffopt, result);
362-
}
363-
364-
/**
365-
* If the work tree has unstaged or uncommitted changes, dies with the
366-
* appropriate message.
367-
*/
368-
static void die_on_unclean_work_tree(const char *prefix)
369-
{
370-
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
371-
int do_die = 0;
372-
373-
hold_locked_index(lock_file, 0);
374-
refresh_cache(REFRESH_QUIET);
375-
update_index_if_able(&the_index, lock_file);
376-
rollback_lock_file(lock_file);
377-
378-
if (has_unstaged_changes(prefix)) {
379-
error(_("Cannot pull with rebase: You have unstaged changes."));
380-
do_die = 1;
381-
}
382-
383-
if (has_uncommitted_changes(prefix)) {
384-
if (do_die)
385-
error(_("Additionally, your index contains uncommitted changes."));
386-
else
387-
error(_("Cannot pull with rebase: Your index contains uncommitted changes."));
388-
do_die = 1;
389-
}
390-
391-
if (do_die)
392-
exit(1);
393-
}
394-
395329
/**
396330
* Appends merge candidates from FETCH_HEAD that are not marked not-for-merge
397331
* into merge_heads.
@@ -875,7 +809,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
875809
die(_("Updating an unborn branch with changes added to the index."));
876810

877811
if (!autostash)
878-
die_on_unclean_work_tree(prefix);
812+
require_clean_work_tree(N_("pull with rebase"),
813+
"Please commit or stash them.", 1, 0);
879814

880815
if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
881816
hashclr(rebase_fork_point);

0 commit comments

Comments
 (0)