aboutsummaryrefslogtreecommitdiff
path: root/builtin-branch.c
Commit message (Collapse)AuthorAge
* git-fetch, git-branch: Support local --track via a special remote '.'Paolo Bonzini2007-03-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds support for a dummy remote '.' to avoid having to declare a fake remote like [remote "local"] url = . fetch = refs/heads/*:refs/heads/* Such a builtin remote simplifies the operation of "git-fetch", which will populate FETCH_HEAD but will not pretend that two repositories are in use, will not create a thin pack, and will not perform any useless remapping of names. The speed improvement is around 20%, and it should improve more if "git-fetch" is converted to a builtin. To this end, git-parse-remote is grown with a new kind of remote, 'builtin'. In git-fetch.sh, we treat the builtin remote specially in that it needs no pack/store operations. In fact, doing git-fetch on a builtin remote will simply populate FETCH_HEAD appropriately. The patch also improves of the --track/--no-track support, extending it so that branch.<name>.remote items referring '.' can be created. Finally, it fixes a typo in git-checkout.sh. Signed-off-by: Paolo Bonzini <bonzini@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Fix broken create_branch() in builtin-branch.Junio C Hamano2007-03-10
| | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
* git-branch, git-checkout: autosetup for remote branch trackingPaolo Bonzini2007-03-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | In order to track and build on top of a branch 'topic' you track from your upstream repository, you often would end up doing this sequence: git checkout -b mytopic origin/topic git config --add branch.mytopic.remote origin git config --add branch.mytopic.merge refs/heads/topic This would first fork your own 'mytopic' branch from the 'topic' branch you track from the 'origin' repository; then it would set up two configuration variables so that 'git pull' without parameters does the right thing while you are on your own 'mytopic' branch. This commit adds a --track option to git-branch, so that "git branch --track mytopic origin/topic" performs the latter two actions when creating your 'mytopic' branch. If the configuration variable branch.autosetupmerge is set to true, you do not have to pass the --track option explicitly; further patches in this series allow setting the variable with a "git remote add" option. The configuration variable is off by default, and there is a --no-track option to countermand it even if the variable is set. Signed-off-by: Paolo Bonzini <bonzini@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* General const correctness fixesShawn O. Pearce2007-03-07
| | | | | | | | | | | | | | | | We shouldn't attempt to assign constant strings into char*, as the string is not writable at runtime. Likewise we should always be treating unsigned values as unsigned values, not as signed values. Most of these are very straightforward. The only exception is the (unnecessary) xstrdup/free in builtin-branch.c for the detached head case. Since this is a user-level interactive type program and that particular code path is executed no more than once, I feel that the extra xstrdup call is well worth the easy elimination of this warning. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* git-branch: improve abbreviation of sha1s in verbose modeJulian Phillips2007-03-02
| | | | | | | | | | git-branch has an --abbrev= command line option, but it does no checking of the input. Take the argument parsing code from setup_revisions in revisions.c, and also the code for parsing the --no-abbrev option. Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Mechanical conversion to use prefixcmp()Junio C Hamano2007-02-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This mechanically converts strncmp() to use prefixcmp(), but only when the parameters match specific patterns, so that they can be verified easily. Leftover from this will be fixed in a separate step, including idiotic conversions like if (!strncmp("foo", arg, 3)) => if (!(-prefixcmp(arg, "foo"))) This was done by using this script in px.perl #!/usr/bin/perl -i.bak -p if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) { s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|; } if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) { s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|; } and running: $ git grep -l strncmp -- '*.c' | xargs perl px.perl Signed-off-by: Junio C Hamano <junkio@cox.net>
* Merge branch 'jc/merge-base' (early part)Junio C Hamano2007-02-13
|\ | | | | | | | | This contains an evil merge to fast-import, in order to resolve in_merge_bases() update.
| * Allow in_merge_bases() to take more than one reference commits.Junio C Hamano2007-01-09
| | | | | | | | | | | | | | | | | | The internal function in_merge_bases(A, B) is used to make sure that commit A is an ancestor of commit B. This changes the signature of it to take an array of B's and updates its current callers. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | Merge branch 'master' into np/dreflogJunio C Hamano2007-02-03
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | This is to resolve conflicts early in preparation for possible inclusion of "reflog on detached HEAD" series by Nico, as having it in 1.5.0 would really help us remove confusion between detached and attached states. Signed-off-by: Junio C Hamano <junkio@cox.net>
| * | Assorted typo fixesPavel Roskin2007-02-03
| | | | | | | | | | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
| * | fix reflog entries for "git-branch"Junio C Hamano2007-02-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Even when -l is not given from the command line, the repository may have the configuration variable core.logallrefupdates set, or an old-timer might have done ": >.git/logs/refs/heads/new" before running "git branch new". In these cases, the code gave an uninitialized msg[] from the stack to be written out as the reflog message. This also passes a different message when '-f' option is used. Saying "git branch -f branch some-commit" is a moral equilvalent of doing "git-reset some-commit" while on the branch. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | | add logref support to git-symbolic-refNicolas Pitre2007-01-28
|/ / | | | | | | | | Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* | Don't force everybody to call setup_ident().Junio C Hamano2007-01-28
| | | | | | | | | | | | | | | | | | | | | | | | Back when only handful commands that created commit and tag were the only users of committer identity information, it made sense to explicitly call setup_ident() to pre-fill the default value from the gecos information. But it is much simpler for programs to make the call automatic when get_ident() is called these days, since many more programs want to use the information when updating the reflog. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | branch -f: no reason to forbid updating the current branch in a bare repo.Junio C Hamano2007-01-20
| | | | | | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
* | Detached HEAD (experimental)Junio C Hamano2007-01-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows "git checkout v1.4.3" to dissociate the HEAD of repository from any branch. After this point, "git branch" starts reporting that you are not on any branch. You can go back to an existing branch by saying "git checkout master", for example. This is still experimental. While I think it makes sense to allow commits on top of detached HEAD, it is rather dangerous unless you are careful in the current form. Next "git checkout master" will obviously lose what you have done, so we might want to require "git checkout -f" out of a detached HEAD if we find that the HEAD commit is not an ancestor of any other branches. There is no such safety valve implemented right now. On the other hand, the reason the user did not start the ad-hoc work on a new branch with "git checkout -b" was probably because the work was of a throw-away nature, so the convenience of not having that safety valve might be even better. The user, after accumulating some commits on top of a detached HEAD, can always create a new branch with "git checkout -b" not to lose useful work done while the HEAD was detached. We'll see. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | git-branch: show detached HEADLars Hjemli2007-01-08
|/ | | | | | | This makes git-branch show a detached HEAD as '* (no branch)'. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Refactor print-functions in builtin-branchLars Hjemli2007-01-03
| | | | | | | | This moves the guts of print_ref_list() into a revamped print_ref_info(), which at the same time gets renamed to print_ref_item(). Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Add documentation for git-branch's color configuration.Brian Gernhardt2007-01-03
| | | | | | | | | | | | | Added color.branch and color.branch.<slot> to configuration list. Style copied from color.status and meanings derived from the code. Moved the color meanings from color.diff.<slot> to color.branch.<slot> since the latter comes first alphabetically. Added --color and --no-color to git-branch's usage and documentation. Signed-off-by: Brian Gernhardt <benji@silverinsanity.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Move in_merge_bases() to commit.cJunio C Hamano2006-12-20
| | | | This reasonably useful function was hidden inside builtin-branch.c
* Merge branch 'jc/branch-remove-remote'Junio C Hamano2006-12-20
|\ | | | | | | | | | | * jc/branch-remove-remote: git-branch -d: do not stop at the first failure. Teach git-branch to delete tracking branches with -r -d
| * git-branch -d: do not stop at the first failure.Quy Tonthat2006-12-18
| | | | | | | | | | | | | | | | | | If there are more than one branches to be deleted, failure on one will no longer stop git-branch to process the next ones. The command still reports failures by exitting non-zero status. Signed-off-by: Quy Tonthat <qtonthat@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
| * Teach git-branch to delete tracking branches with -r -dJunio C Hamano2006-12-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because -r already means "remote" when listing, you can say: $ git branch -d -r origin/todo origin/html origin/man I just twisted it not to check fast-forwardness with the current branch when you are removing a tracking branch. Most likely, removal of a tracking branch is not because you are "done with" it (for a local branch, it usually means "you merged it up"), but because you are not even interested in it. In other words, remote tracking branches are more like tags than branches. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | simplify inclusion of system header files.Junio C Hamano2006-12-20
|/ | | | | | | | | | | | | | | | | | | | This is a mechanical clean-up of the way *.c files include system header files. (1) sources under compat/, platform sha-1 implementations, and xdelta code are exempt from the following rules; (2) the first #include must be "git-compat-util.h" or one of our own header file that includes it first (e.g. config.h, builtin.h, pkt-line.h); (3) system headers that are included in "git-compat-util.h" need not be included in individual C source files. (4) "git-compat-util.h" does not have to include subsystem specific header files (e.g. expat.h). Signed-off-by: Junio C Hamano <junkio@cox.net>
* Merge branch 'lh/branch-rename'Junio C Hamano2006-12-13
|\ | | | | | | | | | | | | | | | | | | | | * lh/branch-rename: git-branch: let caller specify logmsg rename_ref: use lstat(2) when testing for symlink git-branch: add options and tests for branch renaming Conflicts: builtin-branch.c
| * git-branch: let caller specify logmsgLars Hjemli2006-12-05
| | | | | | | | | | | | | | | | | | | | | | This changes the signature of rename_ref() in refs.[hc] to include a logmessage for the reflogs. Also, builtin-branch.c is modified to provide a proper logmessage + call setup_ident() before any logmessages are written. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
| * git-branch: add options and tests for branch renamingLars Hjemli2006-12-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Extend git-branch with the following options: git-branch -m|-M [<oldbranch>] newbranch The -M variation is required to force renaming over an exsisting branchname. This also indroduces $GIT_DIR/RENAME_REF which is a "metabranch" used when renaming branches. It will always hold the original sha1 for the latest renamed branch. Additionally, if $GIT_DIR/logs/RENAME_REF exists, all branch rename events are logged there. Finally, some testcases are added to verify the new options. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
* | branch --color: change default color selection.Junio C Hamano2006-12-13
| | | | | | | | | | | | | | | | | | | | | | Showing local and remote branches in green and red was simply overkill, as all we wanted was to make it easy to tell them apart (local ones can be built on top by committing, but the remote tracking ones can't). Use plain coloring for local branches and paint remotes in red. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | Colourise git-branch outputAndy Parkins2006-12-12
|/ | | | | | | | | | | | | | | | | | | | | | I wanted to have a visual indication of which branches are local and which are remote in git-branch -a output; however Junio was concerned that someone might be using the output in a script. This patch addresses the problem by colouring the git-branch output - which in "auto" mode won't be activated. I've based it off the colouring code for builtin-diff.c; which means there is a branch color configuration variable that needs setting to something before the color will appear. The colour parameter is "color.branch" rather than "branch.color" to avoid clashing with the default namespace for default branch merge definitions. This patch chooses green for local, red for remote and bold green for current. Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
* git-branch -D: make it work even when on a yet-to-be-born branchJunio C Hamano2006-11-24
| | | | | | | | | | | | | | | | | | | | | This makes "git branch -D other_branch" work even when HEAD points at a yet-to-be-born branch. Earlier, we checked the HEAD ref for the purpose of "subset" check even when the deletion was forced (i.e. not -d but -D). Because of this, you cannot delete a branch even with -D while on a yet-to-be-born branch. With this change, the following sequence that now works: mkdir newdir && cd newdir git init-db git fetch -k $other_repo refs/heads/master:refs/heads/othre # oops, typo git branch other othre git branch -D othre Signed-off-by: Junio C Hamano <junkio@cox.net>
* Add -v and --abbrev options to git-branchLars Hjemli2006-11-24
| | | | | | | | | | | The new -v option makes git-branch show the abbreviated sha1 + subjectline for each branch. Additionally, minimum abbreviation length can be specified with --abbrev=<length> Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Add support to git-branch to show local and remote branchesAndy Parkins2006-11-21
| | | | | | | | | | | | | | | | | | | | | | | Instead of storing a list of refnames in append_ref, a list of structures is created. Each of these stores the refname and a symbolic constant representing its type. The creation of the list is filtered based on a command line switch; no switch means "local branches only", "-r" means "remote branches only" (as they always did); but now "-a" means "local branches or remote branches". As a side effect, the list is now not global, but allocated in print_ref_list() where it used. Also a memory leak is plugged, the memory allocated during the list creation was never freed. It lays a groundwork to also display tags, but the command being 'git branch' it is not currently used. Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Remove uneccessarily similar printf() from print_ref_list() in builtin-branchAndy Parkins2006-11-02
| | | | | Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Make git-branch a builtinLars Hjemli2006-10-23
This replaces git-branch.sh with builtin-branch.c The changes is basically a patch from Kristian Høgsberg, updated to apply onto current 'next' Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>