path: root/builtin/show-branch.c
AgeCommit message (Collapse)Author
2017-06-24Merge branch 'bw/config-h'Junio C Hamano
Fix configuration codepath to pay proper attention to commondir that is used in multi-worktree situation, and isolate config API into its own header file. * bw/config-h: config: don't implicitly use gitdir or commondir config: respect commondir setup: teach discover_git_directory to respect the commondir config: don't include config.h by default config: remove git_config_iter config: create config.h
2017-06-22Merge branch 'pc/dir-count-slashes'Junio C Hamano
Three instances of the same helper function have been consolidated to one. * pc/dir-count-slashes: dir: create function count_slashes()
2017-06-15config: don't include config.h by defaultBrandon Williams
Stop including config.h by default in cache.h. Instead only include config.h in those files which require use of the config system. Signed-off-by: Brandon Williams <> Signed-off-by: Junio C Hamano <>
2017-06-12dir: create function count_slashes()Prathamesh Chavan
Similar functions exist in apply.c and builtin/show-branch.c for counting the number of slashes in a string. Also in the later patches, we introduce a third caller for the same. Hence, we unify it now by cleaning the existing functions and declaring a common function count_slashes in dir.h and implementing it in dir.c to remove this code duplication. Mentored-by: Christian Couder <> Mentored-by: Stefan Beller <> Signed-off-by: Junio C Hamano <> Signed-off-by: Prathamesh Chavan <> Signed-off-by: Junio C Hamano <>
2017-05-29Merge branch 'bc/object-id'Junio C Hamano
Conversion from uchar[20] to struct object_id continues. * bc/object-id: (53 commits) object: convert parse_object* to take struct object_id tree: convert parse_tree_indirect to struct object_id sequencer: convert do_recursive_merge to struct object_id diff-lib: convert do_diff_cache to struct object_id builtin/ls-tree: convert to struct object_id merge: convert checkout_fast_forward to struct object_id sequencer: convert fast_forward_to to struct object_id builtin/ls-files: convert overlay_tree_on_cache to object_id builtin/read-tree: convert to struct object_id sha1_name: convert internals of peel_onion to object_id upload-pack: convert remaining parse_object callers to object_id revision: convert remaining parse_object callers to object_id revision: rename add_pending_sha1 to add_pending_oid http-push: convert process_ls_object and descendants to object_id refs/files-backend: convert many internals to struct object_id refs: convert struct ref_update to use struct object_id ref-filter: convert some static functions to struct object_id Convert struct ref_array_item to struct object_id Convert the verify_pack callback to struct object_id Convert lookup_tag to struct object_id ...
2017-05-08Convert lookup_commit* to struct object_idbrian m. carlson
Convert lookup_commit, lookup_commit_or_die, lookup_commit_reference, and lookup_commit_reference_gently to take struct object_id arguments. Introduce a temporary in parse_object buffer in order to convert this function. This is required since in order to convert parse_object and parse_object_buffer, lookup_commit_reference_gently and lookup_commit_or_die would need to be converted. Not introducing a temporary would therefore require that lookup_commit_or_die take a struct object_id *, but lookup_commit would take unsigned char *, leaving a confusing and hard-to-use interface. parse_object_buffer will lose this temporary in a later patch. This commit was created with manual changes to commit.c, commit.h, and object.c, plus the following semantic patch: @@ expression E1, E2; @@ - lookup_commit_reference_gently(E1.hash, E2) + lookup_commit_reference_gently(&E1, E2) @@ expression E1, E2; @@ - lookup_commit_reference_gently(E1->hash, E2) + lookup_commit_reference_gently(E1, E2) @@ expression E1; @@ - lookup_commit_reference(E1.hash) + lookup_commit_reference(&E1) @@ expression E1; @@ - lookup_commit_reference(E1->hash) + lookup_commit_reference(E1) @@ expression E1; @@ - lookup_commit(E1.hash) + lookup_commit(&E1) @@ expression E1; @@ - lookup_commit(E1->hash) + lookup_commit(E1) @@ expression E1, E2; @@ - lookup_commit_or_die(E1.hash, E2) + lookup_commit_or_die(&E1, E2) @@ expression E1, E2; @@ - lookup_commit_or_die(E1->hash, E2) + lookup_commit_or_die(E1, E2) Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2017-04-27timestamp_t: a new data type for timestampsJohannes Schindelin
Git's source code assumes that unsigned long is at least as precise as time_t. Which is incorrect, and causes a lot of problems, in particular where unsigned long is only 32-bit (notably on Windows, even in 64-bit versions). So let's just use a more appropriate data type instead. In preparation for this, we introduce the new `timestamp_t` data type. By necessity, this is a very, very large patch, as it has to replace all timestamps' data type in one go. As we will use a data type that is not necessarily identical to `time_t`, we need to be very careful to use `time_t` whenever we interact with the system functions, and `timestamp_t` everywhere else. Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
2017-02-27Merge branch 'jk/show-branch-lift-name-len-limit'Junio C Hamano
"git show-branch" expected there were only very short branch names in the repository and used a fixed-length buffer to hold them without checking for overflow. * jk/show-branch-lift-name-len-limit: show-branch: use skip_prefix to drop magic numbers show-branch: store resolved head in heap buffer show-branch: drop head_len variable
2017-02-15show-branch: use skip_prefix to drop magic numbersJeff King
We make several starts_with() calls, only to advance pointers. This is exactly what skip_prefix() is for, which lets us avoid manually-counted magic numbers. Helped-by: Pranit Bauva <> Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2017-02-14show-branch: store resolved head in heap bufferJeff King
We resolve HEAD and copy the result to a fixed-size buffer with memcpy, never checking that it actually fits. This bug dates back to 8098a178b (Add git-symbolic-ref, 2005-09-30). Before that we used readlink(), which took a maximum buffer size. We can fix this by using resolve_refdup(), which duplicates the buffer on the heap. That also lets us just check for a NULL pointer to see if we have resolved HEAD, and drop the extra head_p variable. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2017-02-14show-branch: drop head_len variableJeff King
We copy the result of resolving HEAD into a buffer and keep track of its length. But we never actually use the length for anything besides the copy. Let's stop passing it around. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2016-10-03show-branch: use QSORTRené Scharfe
Shorten the code by using QSORT instead of calling qsort(3) directly, as the former determines the element size automatically and checks if there are at least two elements to sort already. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2016-09-15i18n: show-branch: mark plural strings for translationVasco Almeida
Mark plural string for translation using Q_(). Although we already know that the plural sentence is always used in the English source, other languages have complex plural rules they must comply according to the value of MAX_REVS. Signed-off-by: Vasco Almeida <> Signed-off-by: Junio C Hamano <>
2016-09-15i18n: show-branch: mark error messages for translationVasco Almeida
Spell the first word of messages in lowercase, following the usual style. Signed-off-by: Vasco Almeida <> Signed-off-by: Junio C Hamano <>
2015-11-20Remove get_object_hash.brian m. carlson
Convert all instances of get_object_hash to use an appropriate reference to the hash member of the oid member of struct object. This provides no functional change, as it is essentially a macro substitution. Signed-off-by: brian m. carlson <> Signed-off-by: Jeff King <>
2015-11-20Convert struct object to object_idbrian m. carlson
struct object is one of the major data structures dealing with object IDs. Convert it to use struct object_id instead of an unsigned char array. Convert get_object_hash to refer to the new member as well. Signed-off-by: brian m. carlson <> Signed-off-by: Jeff King <>
2015-11-20Add several uses of get_object_hash.brian m. carlson
Convert most instances where the sha1 member of struct object is dereferenced to use get_object_hash. Most instances that are passed to functions that have versions taking struct object_id, such as get_sha1_hex/get_oid_hex, or instances that can be trivially converted to use struct object_id instead, are not converted. Signed-off-by: brian m. carlson <> Signed-off-by: Jeff King <>
2015-11-03Merge branch 'rs/show-branch-argv-array'Junio C Hamano
Code simplification. * rs/show-branch-argv-array: show-branch: use argv_array for default arguments
2015-11-01show-branch: use argv_array for default argumentsRené Scharfe
Use argv_array instead of open-coding it. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2015-10-30Merge branch 'rs/pop-commit'Junio C Hamano
Code simplification. * rs/pop-commit: use pop_commit() for consuming the first entry of a struct commit_list
2015-10-26use pop_commit() for consuming the first entry of a struct commit_listRené Scharfe
Instead of open-coding the function pop_commit() just call it. This makes the intent clearer and reduces code size. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2015-09-25show-branch: avoid segfault with --reflog of unborn branchJeff King
When no branch is given to the "--reflog" option, we resolve HEAD to get the default branch. However, if HEAD points to an unborn branch, resolve_ref returns NULL, and we later segfault trying to access it. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2015-09-09Sync with 2.5.2Junio C Hamano
2015-09-04Sync with 2.4.9Junio C Hamano
2015-09-04Sync with 2.3.9Junio C Hamano
2015-09-04Sync with 2.2.3Junio C Hamano
2015-09-04show-branch: use a strbuf for reflog descriptionsJeff King
When we show "branch@{0}", we format into a fixed-size buffer using sprintf. This can overflow if you have long branch names. We can fix it by using a temporary strbuf. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2015-06-29convert "enum date_mode" into a structJeff King
In preparation for adding date modes that may carry extra information beyond the mode itself, this patch converts the date_mode enum into a struct. Most of the conversion is fairly straightforward; we pass the struct as a pointer and dereference the type field where necessary. Locations that declare a date_mode can use a "{}" constructor. However, the tricky case is where we use the enum labels as constants, like: show_date(t, tz, DATE_NORMAL); Ideally we could say: show_date(t, tz, &{ DATE_NORMAL }); but of course C does not allow that. Likewise, we cannot cast the constant to a struct, because we need to pass an actual address. Our options are basically: 1. Manually add a "struct date_mode d = { DATE_NORMAL }" definition to each caller, and pass "&d". This makes the callers uglier, because they sometimes do not even have their own scope (e.g., they are inside a switch statement). 2. Provide a pre-made global "date_normal" struct that can be passed by address. We'd also need "date_rfc2822", "date_iso8601", and so forth. But at least the ugliness is defined in one place. 3. Provide a wrapper that generates the correct struct on the fly. The big downside is that we end up pointing to a single global, which makes our wrapper non-reentrant. But show_date is already not reentrant, so it does not matter. This patch implements 3, along with a minor macro to keep the size of the callers sane. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2015-06-29show-branch: use DATE_RELATIVE instead of magic numberJeff King
This is more readable, and won't break if we ever change the order of the date_mode enum. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2015-05-25cmd_show_branch(): fix error messageMichael Haggerty
We need to convert the SHA-1 to hexadecimal before printing it. Signed-off-by: Michael Haggerty <> Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2015-05-25builtin/show-branch: rewrite functions to work with object_idMichael Haggerty
Signed-off-by: Michael Haggerty <> Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2015-05-25append_one_rev(): rewrite to work with object_idMichael Haggerty
Signed-off-by: Michael Haggerty <> Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2015-05-25builtin/show-branch: rewrite functions to take object_id argumentsMichael Haggerty
Signed-off-by: Michael Haggerty <> Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2015-05-25append_matching_ref(): rewrite to take an object_id argumentMichael Haggerty
Signed-off-by: Michael Haggerty <> Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2015-05-25each_ref_fn: change to take an object_id parameterMichael Haggerty
Change typedef each_ref_fn to take a "const struct object_id *oid" parameter instead of "const unsigned char *sha1". To aid this transition, implement an adapter that can be used to wrap old-style functions matching the old typedef, which is now called "each_ref_sha1_fn"), and make such functions callable via the new interface. This requires the old function and its cb_data to be wrapped in a "struct each_ref_fn_sha1_adapter", and that object to be used as the cb_data for an adapter function, each_ref_fn_adapter(). This is an enormous diff, but most of it consists of simple, mechanical changes to the sites that call any of the "for_each_ref" family of functions. Subsequent to this change, the call sites can be rewritten one by one to use the new interface. Signed-off-by: Michael Haggerty <> Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2015-05-06Merge branch 'mh/show-branch-topic'Junio C Hamano
"git show-branch --topics HEAD" (with no other arguments) did not do anything interesting. Instead, contrast the given revision against all the local branches by default. * mh/show-branch-topic: show-branch: show all local heads when only giving one rev along --topics
2015-03-31show-branch: show all local heads when only giving one rev along --topicsMike Hommey
"git show-branch --topics <rev> <revs>..." displays ancestry graph, only considering commits that are in all given revs, except the first one. "git show-branch" displays ancestry graph for all local branches. Unfortunately, "git show-branch --topics <rev>" only prints out the rev info for the given rev, and nothing else, e.g.: $ git show-branch --topics origin/master [origin/master] Sync with 2.3.3 While there is an option to add all remote-tracking branches (-r), and another to add all local+remote branches (-a), there is no option to add only local branches. Adding such an option could be considered, but a user would likely already expect that the above command line considers the lack of rev other than for --topics as meaning all local branches, like when there is no argument at all. Moreover, when using -r and -a along with --topics, the first local or remote-tracking branch, depending on alphabetic order is used instead of the one given after --topics (any rev given on the command line is actually simply ignored when either -r or -a is given). And if no rev is given at all, the fact that the first alphetical branch is the base of topics is probably not expected by users (Maybe --topics should always require one rev on the command line?) This change makes "show-branch --topics $rev" act as "show-branch --topics $rev $(git for-each-ref refs/heads --format='%(refname:short)')" "show-branch -r --topics $rev ..." act as "show-branch --topics $rev ... $(git for-each-ref refs/remotes --format='%(refname:short)')" instead of "show-branch --topics $(git for-each-ref refs/remotes --format='%(refname:short)')" and "show-branch -a --topics $rev ..." act as "show-branch --topics $rev ... $(git for-each-ref refs/heads refs/remotes --format='%(refname:short)')" instead of "show-branch --topics $(git for-each-ref refs/heads refs/remotes --format='%(refname:short)')" Signed-off-by: Mike Hommey <> Signed-off-by: Junio C Hamano <>
2015-02-11Merge branch 'ah/usage-strings'Junio C Hamano
* ah/usage-strings: standardize usage info string format
2015-01-21Merge branch 'ak/show-branch-usage-string'Junio C Hamano
* ak/show-branch-usage-string: show-branch: fix indentation of usage string
2015-01-21show-branch: fix indentation of usage stringRalf Thielow
Noticed-by: Jean-Noël Avila <> Signed-off-by: Ralf Thielow <> Signed-off-by: Junio C Hamano <>
2015-01-14Merge branch 'ak/show-branch-usage-string'Junio C Hamano
* ak/show-branch-usage-string: show-branch: line-wrap show-branch usage
2015-01-14standardize usage info string formatAlex Henrie
This patch puts the usage info strings that were not already in docopt- like format into docopt-like format, which will be a litle easier for end users and a lot easier for translators. Changes include: - Placing angle brackets around fill-in-the-blank parameters - Putting dashes in multiword parameter names - Adding spaces to [-f|--foobar] to make [-f | --foobar] - Replacing <foobar>* with [<foobar>...] Signed-off-by: Alex Henrie <> Reviewed-by: Matthieu Moy <> Signed-off-by: Junio C Hamano <>
2015-01-08show-branch: line-wrap show-branch usageAlexander Kuleshov
Signed-off-by: Alexander Kuleshov <> Signed-off-by: Junio C Hamano <>
2014-10-15refs.c: change resolve_ref_unsafe reading argument to be a flags fieldRonnie Sahlberg
resolve_ref_unsafe takes a boolean argument for reading (a nonexistent ref resolves successfully for writing but not for reading). Change this to be a flags field instead, and pass the new constant RESOLVE_REF_READING when we want this behaviour. While at it, swap two of the arguments in the function to put output arguments at the end. As a nice side effect, this ensures that we can catch callers that were unaware of the new API so they can be audited. Give the wrapper functions resolve_refdup and read_ref_full the same treatment for consistency. Signed-off-by: Ronnie Sahlberg <> Signed-off-by: Jonathan Nieder <> Signed-off-by: Junio C Hamano <>
2014-09-29Merge branch 'da/rev-parse-verify-quiet'Junio C Hamano
"rev-parse --verify --quiet $name" is meant to quietly exit with a non-zero status when $name is not a valid object name, but still gave error messages in some cases. * da/rev-parse-verify-quiet: stash: prefer --quiet over shell redirection of the standard error stream refs: make rev-parse --quiet actually quiet t1503: use test_must_be_empty Documentation: a note about stdout for git rev-parse --verify --quiet
2014-09-19refs: make rev-parse --quiet actually quietDavid Aguilar
When a reflog is deleted, e.g. when "git stash" clears its stashes, "git rev-parse --verify --quiet" dies: fatal: Log for refs/stash is empty. The reason is that the get_sha1() code path does not allow us to suppress this message. Pass the flags bitfield through get_sha1_with_context() so that read_ref_at() can suppress the message. Use get_sha1_with_context1() instead of get_sha1() in rev-parse so that the --quiet flag is honored. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2014-09-18use REALLOC_ARRAY for changing the allocation size of arraysRené Scharfe
Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2014-07-28Merge branch 'jk/misc-fixes-maint'Junio C Hamano
* jk/misc-fixes-maint: apply: avoid possible bogus pointer fix memory leak parsing core.commentchar transport: fix leaks in refs_from_alternate_cb free ref string returned by dwim_ref receive-pack: don't copy "dir" parameter
2014-07-24free ref string returned by dwim_refJeff King
A call to "dwim_ref(name, len, flags, &ref)" will allocate a new string in "ref" to return the exact ref we found. We do not consistently free it in all code paths, leading to small leaks. The worst is in get_sha1_basic, which may be called many times (e.g., by "cat-file --batch"), though it is relatively unlikely, as it only triggers on a bogus reflog specification. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2014-06-19use xstrfmt to replace xmalloc + sprintfJeff King
This is one line shorter, and makes sure the length in the malloc and sprintf steps match. These conversions are very straightforward; we can drop the malloc entirely, and replace the sprintf with xstrfmt. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>