Skip to content

Commit cadd8a7

Browse files
author
Junio C Hamano
committed
Merge branch 'master' into jc/globfetch
This is to pick up the fix made on master: git-fetch: exit with non-zero status when fast-forward check fails
2 parents 5677882 + f64d7fd commit cadd8a7

18 files changed

+1014
-311
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ i18n.commitEncoding::
219219
browser (and possibly at other places in the future or in other
220220
porcelains). See e.g. gitlink:git-mailinfo[1]. Defaults to 'utf-8'.
221221

222+
log.showroot::
223+
If true, the initial commit will be shown as a big creation event.
224+
This is equivalent to a diff against an empty tree.
225+
Tools like gitlink:git-log[1] or gitlink:git-whatchanged[1], which
226+
normally hide the root commit will now show it. True by default.
227+
222228
merge.summary::
223229
Whether to include summaries of merged commits in newly created
224230
merge commit messages. False by default.

Documentation/git-branch.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ git-branch - List, create, or delete branches.
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git-branch' [-r]
11+
'git-branch' [-r] [-a] [-v] [--abbrev=<length>]
1212
'git-branch' [-l] [-f] <branchname> [<start-point>]
1313
'git-branch' (-d | -D) <branchname>...
1414

1515
DESCRIPTION
1616
-----------
17-
With no arguments given (or just `-r`) a list of available branches
17+
With no arguments given a list of existing branches
1818
will be shown, the current branch will be highlighted with an asterisk.
19+
Option `-r` causes the remote-tracking branches to be listed,
20+
and option `-a` shows both.
1921

2022
In its second form, a new branch named <branchname> will be created.
2123
It will start out with a head equal to the one given as <start-point>.
@@ -45,7 +47,17 @@ OPTIONS
4547
a branch that already exists with the same name.
4648

4749
-r::
48-
List only the "remote" branches.
50+
List the remote-tracking branches.
51+
52+
-a::
53+
List both remote-tracking branches and local branches.
54+
55+
-v::
56+
Show sha1 and subject message for each head.
57+
58+
--abbrev=<length>::
59+
Alter minimum display length for sha1 in output listing,
60+
default value is 7.
4961

5062
<branchname>::
5163
The name of the branch to create or delete.

Documentation/git-clone.txt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ SYNOPSIS
1111
[verse]
1212
'git-clone' [--template=<template_directory>] [-l [-s]] [-q] [-n] [--bare]
1313
[-o <name>] [-u <upload-pack>] [--reference <repository>]
14-
[--use-separate-remote] <repository> [<directory>]
14+
[--use-separate-remote | --use-immingled-remote] <repository>
15+
[<directory>]
1516

1617
DESCRIPTION
1718
-----------
@@ -71,9 +72,13 @@ OPTIONS
7172
Make a 'bare' GIT repository. That is, instead of
7273
creating `<directory>` and placing the administrative
7374
files in `<directory>/.git`, make the `<directory>`
74-
itself the `$GIT_DIR`. This implies `-n` option. When
75-
this option is used, neither the `origin` branch nor the
76-
default `remotes/origin` file is created.
75+
itself the `$GIT_DIR`. This obviously implies the `-n`
76+
because there is nowhere to check out the working tree.
77+
Also the branch heads at the remote are copied directly
78+
to corresponding local branch heads, without mapping
79+
them to `refs/remotes/origin/`. When this option is
80+
used, neither the `origin` branch nor the default
81+
`remotes/origin` file is created.
7782

7883
--origin <name>::
7984
-o <name>::
@@ -97,8 +102,15 @@ OPTIONS
97102

98103
--use-separate-remote::
99104
Save remotes heads under `$GIT_DIR/remotes/origin/` instead
100-
of `$GIT_DIR/refs/heads/`. Only the master branch is saved
101-
in the latter.
105+
of `$GIT_DIR/refs/heads/`. Only the local master branch is
106+
saved in the latter. This is the default.
107+
108+
--use-immingled-remote::
109+
Save remotes heads in the same namespace as the local
110+
heads, `$GIT_DIR/refs/heads/'. In regular repositories,
111+
this is a legacy setup git-clone created by default in
112+
older Git versions, and will be removed before the next
113+
major release.
102114

103115
<repository>::
104116
The (possibly remote) repository to clone from. It can

builtin-apply.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,11 @@ static void numstat_patch_list(struct patch *patch)
21192119
for ( ; patch; patch = patch->next) {
21202120
const char *name;
21212121
name = patch->new_name ? patch->new_name : patch->old_name;
2122-
printf("%d\t%d\t", patch->lines_added, patch->lines_deleted);
2122+
if (patch->is_binary)
2123+
printf("-\t-\t");
2124+
else
2125+
printf("%d\t%d\t",
2126+
patch->lines_added, patch->lines_deleted);
21232127
if (line_termination && quote_c_style(name, NULL, NULL, 0))
21242128
quote_c_style(name, NULL, stdout, 0);
21252129
else

builtin-branch.c

Lines changed: 127 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "builtin.h"
1212

1313
static const char builtin_branch_usage[] =
14-
"git-branch (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>] | [-r]";
14+
"git-branch (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>] | [-r | -a] [-v] [--abbrev=<length>] ";
1515

1616

1717
static const char *head;
@@ -38,12 +38,16 @@ static int in_merge_bases(const unsigned char *sha1,
3838

3939
static void delete_branches(int argc, const char **argv, int force)
4040
{
41-
struct commit *rev, *head_rev;
41+
struct commit *rev, *head_rev = head_rev;
4242
unsigned char sha1[20];
4343
char *name;
4444
int i;
4545

46-
head_rev = lookup_commit_reference(head_sha1);
46+
if (!force) {
47+
head_rev = lookup_commit_reference(head_sha1);
48+
if (!head_rev)
49+
die("Couldn't look up commit object for HEAD");
50+
}
4751
for (i = 0; i < argc; i++) {
4852
if (!strcmp(head, argv[i]))
4953
die("Cannot delete the branch you are currently on.");
@@ -53,8 +57,8 @@ static void delete_branches(int argc, const char **argv, int force)
5357
die("Branch '%s' not found.", argv[i]);
5458

5559
rev = lookup_commit_reference(sha1);
56-
if (!rev || !head_rev)
57-
die("Couldn't look up commit objects.");
60+
if (!rev)
61+
die("Couldn't look up commit object for '%s'", name);
5862

5963
/* This checks whether the merge bases of branch and
6064
* HEAD contains branch -- which means that the HEAD
@@ -79,46 +83,129 @@ static void delete_branches(int argc, const char **argv, int force)
7983
}
8084
}
8185

82-
static int ref_index, ref_alloc;
83-
static char **ref_list;
86+
#define REF_UNKNOWN_TYPE 0x00
87+
#define REF_LOCAL_BRANCH 0x01
88+
#define REF_REMOTE_BRANCH 0x02
89+
#define REF_TAG 0x04
90+
91+
struct ref_item {
92+
char *name;
93+
unsigned int kind;
94+
unsigned char sha1[20];
95+
};
96+
97+
struct ref_list {
98+
int index, alloc, maxwidth;
99+
struct ref_item *list;
100+
int kinds;
101+
};
84102

85-
static int append_ref(const char *refname, const unsigned char *sha1, int flags,
86-
void *cb_data)
103+
static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
87104
{
88-
if (ref_index >= ref_alloc) {
89-
ref_alloc = alloc_nr(ref_alloc);
90-
ref_list = xrealloc(ref_list, ref_alloc * sizeof(char *));
105+
struct ref_list *ref_list = (struct ref_list*)(cb_data);
106+
struct ref_item *newitem;
107+
int kind = REF_UNKNOWN_TYPE;
108+
int len;
109+
110+
/* Detect kind */
111+
if (!strncmp(refname, "refs/heads/", 11)) {
112+
kind = REF_LOCAL_BRANCH;
113+
refname += 11;
114+
} else if (!strncmp(refname, "refs/remotes/", 13)) {
115+
kind = REF_REMOTE_BRANCH;
116+
refname += 13;
117+
} else if (!strncmp(refname, "refs/tags/", 10)) {
118+
kind = REF_TAG;
119+
refname += 10;
120+
}
121+
122+
/* Don't add types the caller doesn't want */
123+
if ((kind & ref_list->kinds) == 0)
124+
return 0;
125+
126+
/* Resize buffer */
127+
if (ref_list->index >= ref_list->alloc) {
128+
ref_list->alloc = alloc_nr(ref_list->alloc);
129+
ref_list->list = xrealloc(ref_list->list,
130+
ref_list->alloc * sizeof(struct ref_item));
91131
}
92132

93-
ref_list[ref_index++] = xstrdup(refname);
133+
/* Record the new item */
134+
newitem = &(ref_list->list[ref_list->index++]);
135+
newitem->name = xstrdup(refname);
136+
newitem->kind = kind;
137+
hashcpy(newitem->sha1, sha1);
138+
len = strlen(newitem->name);
139+
if (len > ref_list->maxwidth)
140+
ref_list->maxwidth = len;
94141

95142
return 0;
96143
}
97144

145+
static void free_ref_list(struct ref_list *ref_list)
146+
{
147+
int i;
148+
149+
for (i = 0; i < ref_list->index; i++)
150+
free(ref_list->list[i].name);
151+
free(ref_list->list);
152+
}
153+
98154
static int ref_cmp(const void *r1, const void *r2)
99155
{
100-
return strcmp(*(char **)r1, *(char **)r2);
156+
struct ref_item *c1 = (struct ref_item *)(r1);
157+
struct ref_item *c2 = (struct ref_item *)(r2);
158+
159+
if (c1->kind != c2->kind)
160+
return c1->kind - c2->kind;
161+
return strcmp(c1->name, c2->name);
162+
}
163+
164+
static void print_ref_info(const unsigned char *sha1, int abbrev)
165+
{
166+
struct commit *commit;
167+
char subject[256];
168+
169+
170+
commit = lookup_commit(sha1);
171+
if (commit && !parse_commit(commit))
172+
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
173+
subject, sizeof(subject), 0,
174+
NULL, NULL, 0);
175+
else
176+
strcpy(subject, " **** invalid ref ****");
177+
178+
printf(" %s %s\n", find_unique_abbrev(sha1, abbrev), subject);
101179
}
102180

103-
static void print_ref_list(int remote_only)
181+
static void print_ref_list(int kinds, int verbose, int abbrev)
104182
{
105183
int i;
106184
char c;
185+
struct ref_list ref_list;
107186

108-
if (remote_only)
109-
for_each_remote_ref(append_ref, NULL);
110-
else
111-
for_each_branch_ref(append_ref, NULL);
187+
memset(&ref_list, 0, sizeof(ref_list));
188+
ref_list.kinds = kinds;
189+
for_each_ref(append_ref, &ref_list);
112190

113-
qsort(ref_list, ref_index, sizeof(char *), ref_cmp);
191+
qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp);
114192

115-
for (i = 0; i < ref_index; i++) {
193+
for (i = 0; i < ref_list.index; i++) {
116194
c = ' ';
117-
if (!strcmp(ref_list[i], head))
195+
if (ref_list.list[i].kind == REF_LOCAL_BRANCH &&
196+
!strcmp(ref_list.list[i].name, head))
118197
c = '*';
119198

120-
printf("%c %s\n", c, ref_list[i]);
199+
if (verbose) {
200+
printf("%c %-*s", c, ref_list.maxwidth,
201+
ref_list.list[i].name);
202+
print_ref_info(ref_list.list[i].sha1, abbrev);
203+
}
204+
else
205+
printf("%c %s\n", c, ref_list.list[i].name);
121206
}
207+
208+
free_ref_list(&ref_list);
122209
}
123210

124211
static void create_branch(const char *name, const char *start,
@@ -160,8 +247,10 @@ static void create_branch(const char *name, const char *start,
160247

161248
int cmd_branch(int argc, const char **argv, const char *prefix)
162249
{
163-
int delete = 0, force_delete = 0, force_create = 0, remote_only = 0;
250+
int delete = 0, force_delete = 0, force_create = 0;
251+
int verbose = 0, abbrev = DEFAULT_ABBREV;
164252
int reflog = 0;
253+
int kinds = REF_LOCAL_BRANCH;
165254
int i;
166255

167256
git_config(git_default_config);
@@ -189,13 +278,25 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
189278
continue;
190279
}
191280
if (!strcmp(arg, "-r")) {
192-
remote_only = 1;
281+
kinds = REF_REMOTE_BRANCH;
282+
continue;
283+
}
284+
if (!strcmp(arg, "-a")) {
285+
kinds = REF_REMOTE_BRANCH | REF_LOCAL_BRANCH;
193286
continue;
194287
}
195288
if (!strcmp(arg, "-l")) {
196289
reflog = 1;
197290
continue;
198291
}
292+
if (!strncmp(arg, "--abbrev=", 9)) {
293+
abbrev = atoi(arg+9);
294+
continue;
295+
}
296+
if (!strcmp(arg, "-v")) {
297+
verbose = 1;
298+
continue;
299+
}
199300
usage(builtin_branch_usage);
200301
}
201302

@@ -209,7 +310,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
209310
if (delete)
210311
delete_branches(argc - i, argv + i, force_delete);
211312
else if (i == argc)
212-
print_ref_list(remote_only);
313+
print_ref_list(kinds, verbose, abbrev);
213314
else if (i == argc - 1)
214315
create_branch(argv[i], head, force_create, reflog);
215316
else if (i == argc - 2)

0 commit comments

Comments
 (0)