From 2b11e059ee55ae7fb9913acf84fcc065e3e33287 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sun, 12 Oct 2008 00:02:32 +0200 Subject: [PATCH 001/138] gitweb: Better processing format string in custom links in navbar Make processing format string in custom links in action bar ('actions' feature) more robust. Now there would be no problems if one of expanded values (for example project name, of project filename) contains '%'; additionally format string supports '%' escaping by doubling, i.e. '%%' expands to '%'. Signed-off-by: Jakub Narebski Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.perl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 11168006cf..cc6edbede8 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -290,10 +290,10 @@ our %feature = ( # The 'default' value consists of a list of triplets in the form # (label, link, position) where position is the label after which - # to inster the link and link is a format string where %n expands + # to insert the link and link is a format string where %n expands # to the project name, %f to the project path within the filesystem, # %h to the current hash (h gitweb parameter) and %b to the current - # hash base (hb gitweb parameter). + # hash base (hb gitweb parameter); %% expands to %. # To enable system wide have in $GITWEB_CONFIG e.g. # $feature{'actions'}{'default'} = [('graphiclog', @@ -2866,14 +2866,19 @@ sub git_print_page_nav { $arg{'tree'}{'hash_base'} = $treebase if defined $treebase; my @actions = gitweb_check_feature('actions'); + my %repl = ( + '%' => '%', + 'n' => $project, # project name + 'f' => $git_dir, # project path within filesystem + 'h' => $treehead || '', # current hash ('h' parameter) + 'b' => $treebase || '', # hash base ('hb' parameter) + ); while (@actions) { - my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions)); + my ($label, $link, $pos) = splice(@actions,0,3); + # insert @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs; # munch munch - $link =~ s#%n#$project#g; - $link =~ s#%f#$git_dir#g; - $treehead ? $link =~ s#%h#$treehead#g : $link =~ s#%h##g; - $treebase ? $link =~ s#%b#$treebase#g : $link =~ s#%b##g; + $link =~ s/%([%nfhb])/$repl{$1}/g; $arg{$label}{'_href'} = $link; } From bee866fa6b5a77f65d9915f8778919ef76d9d6c1 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Wed, 8 Oct 2008 11:05:35 +0400 Subject: [PATCH 002/138] gitk: Allow forcing branch creation if it already exists If gitk knows that the branch the user tries to create exists, it should ask whether it should overwrite it. This way the user can either decide to choose a new name, or move the head while preserving the reflog. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/gitk b/gitk index bcebc87f7d..5830941b7a 100755 --- a/gitk +++ b/gitk @@ -7727,24 +7727,42 @@ proc mkbrgo {top} { set name [$top.name get] set id [$top.sha1 get] + set cmdargs {} + set old_id {} if {$name eq {}} { error_popup [mc "Please specify a name for the new branch"] return } + if {[info exists headids($name)]} { + if {![confirm_popup [mc \ + "Branch '%s' already exists. Overwrite?" $name]]} { + return + } + set old_id $headids($name) + lappend cmdargs -f + } catch {destroy $top} + lappend cmdargs $name $id nowbusy newbranch update if {[catch { - exec git branch $name $id + eval exec git branch $cmdargs } err]} { notbusy newbranch error_popup $err } else { - set headids($name) $id - lappend idheads($id) $name - addedhead $id $name notbusy newbranch - redrawtags $id + if {$old_id ne {}} { + movehead $id $name + movedhead $id $name + redrawtags $old_id + redrawtags $id + } else { + set headids($name) $id + lappend idheads($id) $name + addedhead $id $name + redrawtags $id + } dispneartags 0 run refill_reflist } From 2df6442f7dc0d6cd5636e6ac413d06f92eb04029 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Wed, 8 Oct 2008 11:05:37 +0400 Subject: [PATCH 003/138] gitk: Fix file list context menu for merge commits Currently it displays an ugly error box, because the treediffs array is not filled for such commits. This fixes it by making getmergediffline add the filenames it sees to the treediffs array like gettreediffline does. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gitk b/gitk index 5830941b7a..f6a3e10d8e 100755 --- a/gitk +++ b/gitk @@ -6418,7 +6418,7 @@ proc getblobline {bf id} { proc mergediff {id} { global diffmergeid mdifffd - global diffids + global diffids treediffs global parents global diffcontext global diffencoding @@ -6426,6 +6426,7 @@ proc mergediff {id} { set diffmergeid $id set diffids $id + set treediffs($id) {} # this doesn't seem to actually affect anything... set cmd [concat | git diff-tree --no-commit-id --cc -U$diffcontext $id] if {$limitdiffs && $vfilelimit($curview) ne {}} { @@ -6445,7 +6446,7 @@ proc mergediff {id} { proc getmergediffline {mdf id np} { global diffmergeid ctext cflist mergemax - global difffilestart mdifffd + global difffilestart mdifffd treediffs global diffencoding $ctext conf -state normal @@ -6462,6 +6463,7 @@ proc getmergediffline {mdf id np} { $ctext insert end "\n" set here [$ctext index "end - 1c"] lappend difffilestart $here + lappend treediffs($id) $fname add_flist [list $fname] set diffencoding [get_path_encoding $fname] set l [expr {(78 - [string length $fname]) / 2}] From 7c4ed8c83583517e7e6d851c8c01996ca6c803ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 25 Oct 2008 15:30:22 +0200 Subject: [PATCH 004/138] blame: inline get_patch() Inline get_patch() to its only call site as a preparation for getting rid of struct patch. Also we don't need to check the ptr members because fill_origin_blob() already did, and the caller didn't check for NULL anyway, so drop the test. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin-blame.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/builtin-blame.c b/builtin-blame.c index 48cc0c175d..593b539f1e 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -542,25 +542,6 @@ static struct patch *compare_buffer(mmfile_t *file_p, mmfile_t *file_o, return state.ret; } -/* - * Run diff between two origins and grab the patch output, so that - * we can pass blame for lines origin is currently suspected for - * to its parent. - */ -static struct patch *get_patch(struct origin *parent, struct origin *origin) -{ - mmfile_t file_p, file_o; - struct patch *patch; - - fill_origin_blob(parent, &file_p); - fill_origin_blob(origin, &file_o); - if (!file_p.ptr || !file_o.ptr) - return NULL; - patch = compare_buffer(&file_p, &file_o, 0); - num_get_patch++; - return patch; -} - static void free_patch(struct patch *p) { free(p->chunks); @@ -824,12 +805,22 @@ static int pass_blame_to_parent(struct scoreboard *sb, { int i, last_in_target, plno, tlno; struct patch *patch; + mmfile_t file_p, file_o; last_in_target = find_last_in_target(sb, target); if (last_in_target < 0) return 1; /* nothing remains for this target */ - patch = get_patch(parent, target); + /* + * Run diff between two origins and grab the patch output, so that + * we can pass blame for lines origin is currently suspected for + * to its parent. + */ + fill_origin_blob(parent, &file_p); + fill_origin_blob(target, &file_o); + patch = compare_buffer(&file_p, &file_o, 0); + num_get_patch++; + plno = tlno = 0; for (i = 0; i < patch->num; i++) { struct chunk *chunk = &patch->chunks[i]; From 9ccd0a88ac3ea13ac2df4630bfd01c02084f965e Mon Sep 17 00:00:00 2001 From: Brian Downing Date: Sat, 25 Oct 2008 15:30:37 +0200 Subject: [PATCH 005/138] Always initialize xpparam_t to 0 We're going to be adding some parameters to this, so we can't have any uninitialized data in it. Signed-off-by: Brian Downing Signed-off-by: Junio C Hamano --- builtin-blame.c | 1 + builtin-rerere.c | 1 + combine-diff.c | 1 + diff.c | 5 +++++ merge-file.c | 1 + 5 files changed, 9 insertions(+) diff --git a/builtin-blame.c b/builtin-blame.c index 593b539f1e..5ca7065171 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -523,6 +523,7 @@ static struct patch *compare_buffer(mmfile_t *file_p, mmfile_t *file_o, xdemitconf_t xecfg; xdemitcb_t ecb; + memset(&xpp, 0, sizeof(xpp)); xpp.flags = xdl_opts; memset(&xecfg, 0, sizeof(xecfg)); xecfg.ctxlen = context; diff --git a/builtin-rerere.c b/builtin-rerere.c index dd4573fe8d..d4dec6b715 100644 --- a/builtin-rerere.c +++ b/builtin-rerere.c @@ -98,6 +98,7 @@ static int diff_two(const char *file1, const char *label1, printf("--- a/%s\n+++ b/%s\n", label1, label2); fflush(stdout); + memset(&xpp, 0, sizeof(xpp)); xpp.flags = XDF_NEED_MINIMAL; memset(&xecfg, 0, sizeof(xecfg)); xecfg.ctxlen = 3; diff --git a/combine-diff.c b/combine-diff.c index 5aa1104d34..ec8df39bb0 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -213,6 +213,7 @@ static void combine_diff(const unsigned char *parent, mmfile_t *result_file, parent_file.ptr = grab_blob(parent, &sz); parent_file.size = sz; + memset(&xpp, 0, sizeof(xpp)); xpp.flags = XDF_NEED_MINIMAL; memset(&xecfg, 0, sizeof(xecfg)); memset(&state, 0, sizeof(state)); diff --git a/diff.c b/diff.c index 1c6be897b2..f141e7c8ff 100644 --- a/diff.c +++ b/diff.c @@ -470,6 +470,7 @@ static void diff_words_show(struct diff_words_data *diff_words) mmfile_t minus, plus; int i; + memset(&xpp, 0, sizeof(xpp)); memset(&xecfg, 0, sizeof(xecfg)); minus.size = diff_words->minus.text.size; minus.ptr = xmalloc(minus.size); @@ -1585,6 +1586,7 @@ static void builtin_diff(const char *name_a, if (!pe) pe = diff_funcname_pattern(two); + memset(&xpp, 0, sizeof(xpp)); memset(&xecfg, 0, sizeof(xecfg)); memset(&ecbdata, 0, sizeof(ecbdata)); ecbdata.label_path = lbl; @@ -1658,6 +1660,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b, xdemitconf_t xecfg; xdemitcb_t ecb; + memset(&xpp, 0, sizeof(xpp)); memset(&xecfg, 0, sizeof(xecfg)); xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts; xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat, @@ -1704,6 +1707,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b, xdemitconf_t xecfg; xdemitcb_t ecb; + memset(&xpp, 0, sizeof(xpp)); memset(&xecfg, 0, sizeof(xecfg)); xecfg.ctxlen = 1; /* at least one context line */ xpp.flags = XDF_NEED_MINIMAL; @@ -3149,6 +3153,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1) struct diff_filepair *p = q->queue[i]; int len1, len2; + memset(&xpp, 0, sizeof(xpp)); memset(&xecfg, 0, sizeof(xecfg)); if (p->status == 0) return error("internal diff status error"); diff --git a/merge-file.c b/merge-file.c index 2a939c9dd8..3120a95f78 100644 --- a/merge-file.c +++ b/merge-file.c @@ -61,6 +61,7 @@ static int generate_common_file(mmfile_t *res, mmfile_t *f1, mmfile_t *f2) xdemitconf_t xecfg; xdemitcb_t ecb; + memset(&xpp, 0, sizeof(xpp)); xpp.flags = XDF_NEED_MINIMAL; memset(&xecfg, 0, sizeof(xecfg)); xecfg.ctxlen = 3; From ef2e62fe23173586f49a00c6ae953ebbdb0d13ab Mon Sep 17 00:00:00 2001 From: Brian Downing Date: Sat, 25 Oct 2008 15:30:54 +0200 Subject: [PATCH 006/138] Allow alternate "low-level" emit function from xdl_diff For some users (e.g. git blame), getting textual patch output is just extra work, as they can get all the information they need from the low- level diff structures. Allow for an alternate low-level emit function to be defined to allow bypassing the textual patch generation; set xemitconf_t's emit_func member to enable this. The (void (*)()) type is pretty ugly, but the alternative would be to include most of the private xdiff headers in xdiff.h to get the types required for the "proper" function prototype. Also, a (void *) won't work, as ANSI C doesn't allow a function pointer to be cast to an object pointer. Signed-off-by: Brian Downing Signed-off-by: Junio C Hamano --- xdiff/xdiff.h | 1 + xdiff/xdiffi.c | 4 +++- xdiff/xemit.c | 3 +-- xdiff/xemit.h | 3 +++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h index deebe02cd3..84fff583e2 100644 --- a/xdiff/xdiff.h +++ b/xdiff/xdiff.h @@ -87,6 +87,7 @@ typedef struct s_xdemitconf { unsigned long flags; find_func_t find_func; void *find_func_priv; + void (*emit_func)(); } xdemitconf_t; typedef struct s_bdiffparam { diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index 1bad8462fb..9d0324a38c 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -538,6 +538,8 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb) { xdchange_t *xscr; xdfenv_t xe; + emit_func_t ef = xecfg->emit_func ? + (emit_func_t)xecfg->emit_func : xdl_emit_diff; if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) { @@ -551,7 +553,7 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, return -1; } if (xscr) { - if (xdl_emit_diff(&xe, xscr, ecb, xecfg) < 0) { + if (ef(&xe, xscr, ecb, xecfg) < 0) { xdl_free_script(xscr); xdl_free_env(&xe); diff --git a/xdiff/xemit.c b/xdiff/xemit.c index d3d9c845c6..4625c1b421 100644 --- a/xdiff/xemit.c +++ b/xdiff/xemit.c @@ -27,7 +27,6 @@ static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec); static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb); -static xdchange_t *xdl_get_hunk(xdchange_t *xscr, xdemitconf_t const *xecfg); @@ -58,7 +57,7 @@ static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t * * Starting at the passed change atom, find the latest change atom to be included * inside the differential hunk according to the specified configuration. */ -static xdchange_t *xdl_get_hunk(xdchange_t *xscr, xdemitconf_t const *xecfg) { +xdchange_t *xdl_get_hunk(xdchange_t *xscr, xdemitconf_t const *xecfg) { xdchange_t *xch, *xchp; for (xchp = xscr, xch = xscr->next; xch; xchp = xch, xch = xch->next) diff --git a/xdiff/xemit.h b/xdiff/xemit.h index 440a7390fa..c2e2e83027 100644 --- a/xdiff/xemit.h +++ b/xdiff/xemit.h @@ -24,7 +24,10 @@ #define XEMIT_H +typedef int (*emit_func_t)(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, + xdemitconf_t const *xecfg); +xdchange_t *xdl_get_hunk(xdchange_t *xscr, xdemitconf_t const *xecfg); int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, xdemitconf_t const *xecfg); From 86295bb6bac1482d29650d1f77f19d8e7a7cc2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 25 Oct 2008 15:31:15 +0200 Subject: [PATCH 007/138] add xdi_diff_hunks() for callers that only need hunk lengths Based on a patch by Brian Downing, this uses the xdiff emit_func feature to implement xdi_diff_hunks(). It's a function that calls a callback for each hunk of a diff, passing its lengths. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- xdiff-interface.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++- xdiff-interface.h | 4 ++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/xdiff-interface.c b/xdiff-interface.c index f3f6db3297..70794c71fc 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -1,6 +1,9 @@ #include "cache.h" #include "xdiff-interface.h" -#include "strbuf.h" +#include "xdiff/xtypes.h" +#include "xdiff/xdiffi.h" +#include "xdiff/xemit.h" +#include "xdiff/xmacros.h" struct xdiff_emit_state { xdiff_emit_consume_fn consume; @@ -153,6 +156,50 @@ int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2, return ret; } +struct xdiff_emit_hunk_state { + xdiff_emit_hunk_consume_fn consume; + void *consume_callback_data; +}; + +static int process_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, + xdemitconf_t const *xecfg) +{ + long s1, s2, same, p_next, t_next; + xdchange_t *xch, *xche; + struct xdiff_emit_hunk_state *state = ecb->priv; + xdiff_emit_hunk_consume_fn fn = state->consume; + void *consume_callback_data = state->consume_callback_data; + + for (xch = xscr; xch; xch = xche->next) { + xche = xdl_get_hunk(xch, xecfg); + + s1 = XDL_MAX(xch->i1 - xecfg->ctxlen, 0); + s2 = XDL_MAX(xch->i2 - xecfg->ctxlen, 0); + same = s2 + XDL_MAX(xch->i1 - s1, 0); + p_next = xche->i1 + xche->chg1; + t_next = xche->i2 + xche->chg2; + + fn(consume_callback_data, same, p_next, t_next); + } + return 0; +} + +int xdi_diff_hunks(mmfile_t *mf1, mmfile_t *mf2, + xdiff_emit_hunk_consume_fn fn, void *consume_callback_data, + xpparam_t const *xpp, xdemitconf_t *xecfg) +{ + struct xdiff_emit_hunk_state state; + xdemitcb_t ecb; + + memset(&state, 0, sizeof(state)); + memset(&ecb, 0, sizeof(ecb)); + state.consume = fn; + state.consume_callback_data = consume_callback_data; + xecfg->emit_func = (void (*)())process_diff; + ecb.priv = &state; + return xdi_diff(mf1, mf2, xpp, xecfg, &ecb); +} + int read_mmfile(mmfile_t *ptr, const char *filename) { struct stat st; diff --git a/xdiff-interface.h b/xdiff-interface.h index eaf9cd3498..7352b9a9c2 100644 --- a/xdiff-interface.h +++ b/xdiff-interface.h @@ -4,12 +4,16 @@ #include "xdiff/xdiff.h" typedef void (*xdiff_emit_consume_fn)(void *, char *, unsigned long); +typedef void (*xdiff_emit_hunk_consume_fn)(void *, long, long, long); int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb); int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2, xdiff_emit_consume_fn fn, void *consume_callback_data, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *xecb); +int xdi_diff_hunks(mmfile_t *mf1, mmfile_t *mf2, + xdiff_emit_hunk_consume_fn fn, void *consume_callback_data, + xpparam_t const *xpp, xdemitconf_t *xecfg); int parse_hunk_header(char *line, int len, int *ob, int *on, int *nb, int *nn); From cdcab133ea75e0bd5c2279ce6c5718f4af4d9a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 25 Oct 2008 15:31:36 +0200 Subject: [PATCH 008/138] blame: use xdi_diff_hunks(), get rid of struct patch Based on a patch by Brian Downing, this replaces the struct patch based code for blame passing with calls to xdi_diff_hunks(). This way we avoid generating and then parsing patches; we only let the interesting infos be passed to our callbacks instead. This makes blame a bit faster: $ blame="./git blame -M -C -C -p --incremental v1.6.0" # master $ /usr/bin/time $blame Makefile >/dev/null 1.38user 0.14system 0:01.52elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+12226minor)pagefaults 0swaps $ /usr/bin/time $blame cache.h >/dev/null 1.66user 0.13system 0:01.80elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+12262minor)pagefaults 0swaps # this patch series $ /usr/bin/time $blame Makefile >/dev/null 1.27user 0.12system 0:01.40elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+11836minor)pagefaults 0swaps $ /usr/bin/time $blame cache.h >/dev/null 1.52user 0.12system 0:01.70elapsed 97%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+12052minor)pagefaults 0swaps Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin-blame.c | 191 +++++++++++++----------------------------------- 1 file changed, 52 insertions(+), 139 deletions(-) diff --git a/builtin-blame.c b/builtin-blame.c index 5ca7065171..b6bc5cf6a9 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -442,113 +442,6 @@ static struct origin *find_rename(struct scoreboard *sb, return porigin; } -/* - * Parsing of patch chunks... - */ -struct chunk { - /* line number in postimage; up to but not including this - * line is the same as preimage - */ - int same; - - /* preimage line number after this chunk */ - int p_next; - - /* postimage line number after this chunk */ - int t_next; -}; - -struct patch { - struct chunk *chunks; - int num; -}; - -struct blame_diff_state { - struct patch *ret; - unsigned hunk_post_context; - unsigned hunk_in_pre_context : 1; -}; - -static void process_u_diff(void *state_, char *line, unsigned long len) -{ - struct blame_diff_state *state = state_; - struct chunk *chunk; - int off1, off2, len1, len2, num; - - num = state->ret->num; - if (len < 4 || line[0] != '@' || line[1] != '@') { - if (state->hunk_in_pre_context && line[0] == ' ') - state->ret->chunks[num - 1].same++; - else { - state->hunk_in_pre_context = 0; - if (line[0] == ' ') - state->hunk_post_context++; - else - state->hunk_post_context = 0; - } - return; - } - - if (num && state->hunk_post_context) { - chunk = &state->ret->chunks[num - 1]; - chunk->p_next -= state->hunk_post_context; - chunk->t_next -= state->hunk_post_context; - } - state->ret->num = ++num; - state->ret->chunks = xrealloc(state->ret->chunks, - sizeof(struct chunk) * num); - chunk = &state->ret->chunks[num - 1]; - if (parse_hunk_header(line, len, &off1, &len1, &off2, &len2)) { - state->ret->num--; - return; - } - - /* Line numbers in patch output are one based. */ - off1--; - off2--; - - chunk->same = len2 ? off2 : (off2 + 1); - - chunk->p_next = off1 + (len1 ? len1 : 1); - chunk->t_next = chunk->same + len2; - state->hunk_in_pre_context = 1; - state->hunk_post_context = 0; -} - -static struct patch *compare_buffer(mmfile_t *file_p, mmfile_t *file_o, - int context) -{ - struct blame_diff_state state; - xpparam_t xpp; - xdemitconf_t xecfg; - xdemitcb_t ecb; - - memset(&xpp, 0, sizeof(xpp)); - xpp.flags = xdl_opts; - memset(&xecfg, 0, sizeof(xecfg)); - xecfg.ctxlen = context; - memset(&state, 0, sizeof(state)); - state.ret = xmalloc(sizeof(struct patch)); - state.ret->chunks = NULL; - state.ret->num = 0; - - xdi_diff_outf(file_p, file_o, process_u_diff, &state, &xpp, &xecfg, &ecb); - - if (state.ret->num) { - struct chunk *chunk; - chunk = &state.ret->chunks[state.ret->num - 1]; - chunk->p_next -= state.hunk_post_context; - chunk->t_next -= state.hunk_post_context; - } - return state.ret; -} - -static void free_patch(struct patch *p) -{ - free(p->chunks); - free(p); -} - /* * Link in a new blame entry to the scoreboard. Entries that cover the * same line range have been removed from the scoreboard previously. @@ -795,6 +688,22 @@ static void blame_chunk(struct scoreboard *sb, } } +struct blame_chunk_cb_data { + struct scoreboard *sb; + struct origin *target; + struct origin *parent; + long plno; + long tlno; +}; + +static void blame_chunk_cb(void *data, long same, long p_next, long t_next) +{ + struct blame_chunk_cb_data *d = data; + blame_chunk(d->sb, d->tlno, d->plno, same, d->target, d->parent); + d->plno = p_next; + d->tlno = t_next; +} + /* * We are looking at the origin 'target' and aiming to pass blame * for the lines it is suspected to its parent. Run diff to find @@ -804,36 +713,28 @@ static int pass_blame_to_parent(struct scoreboard *sb, struct origin *target, struct origin *parent) { - int i, last_in_target, plno, tlno; - struct patch *patch; + int last_in_target; mmfile_t file_p, file_o; + struct blame_chunk_cb_data d = { sb, target, parent, 0, 0 }; + xpparam_t xpp; + xdemitconf_t xecfg; last_in_target = find_last_in_target(sb, target); if (last_in_target < 0) return 1; /* nothing remains for this target */ - /* - * Run diff between two origins and grab the patch output, so that - * we can pass blame for lines origin is currently suspected for - * to its parent. - */ fill_origin_blob(parent, &file_p); fill_origin_blob(target, &file_o); - patch = compare_buffer(&file_p, &file_o, 0); num_get_patch++; - plno = tlno = 0; - for (i = 0; i < patch->num; i++) { - struct chunk *chunk = &patch->chunks[i]; - - blame_chunk(sb, tlno, plno, chunk->same, target, parent); - plno = chunk->p_next; - tlno = chunk->t_next; - } + memset(&xpp, 0, sizeof(xpp)); + xpp.flags = xdl_opts; + memset(&xecfg, 0, sizeof(xecfg)); + xecfg.ctxlen = 0; + xdi_diff_hunks(&file_p, &file_o, blame_chunk_cb, &d, &xpp, &xecfg); /* The rest (i.e. anything after tlno) are the same as the parent */ - blame_chunk(sb, tlno, plno, last_in_target, target, parent); + blame_chunk(sb, d.tlno, d.plno, last_in_target, target, parent); - free_patch(patch); return 0; } @@ -925,6 +826,23 @@ static void handle_split(struct scoreboard *sb, } } +struct handle_split_cb_data { + struct scoreboard *sb; + struct blame_entry *ent; + struct origin *parent; + struct blame_entry *split; + long plno; + long tlno; +}; + +static void handle_split_cb(void *data, long same, long p_next, long t_next) +{ + struct handle_split_cb_data *d = data; + handle_split(d->sb, d->ent, d->tlno, d->plno, same, d->parent, d->split); + d->plno = p_next; + d->tlno = t_next; +} + /* * Find the lines from parent that are the same as ent so that * we can pass blames to it. file_p has the blob contents for @@ -939,8 +857,9 @@ static void find_copy_in_blob(struct scoreboard *sb, const char *cp; int cnt; mmfile_t file_o; - struct patch *patch; - int i, plno, tlno; + struct handle_split_cb_data d = { sb, ent, parent, split, 0, 0 }; + xpparam_t xpp; + xdemitconf_t xecfg; /* * Prepare mmfile that contains only the lines in ent. @@ -955,24 +874,18 @@ static void find_copy_in_blob(struct scoreboard *sb, } file_o.size = cp - file_o.ptr; - patch = compare_buffer(file_p, &file_o, 1); - /* * file_o is a part of final image we are annotating. * file_p partially may match that image. */ + memset(&xpp, 0, sizeof(xpp)); + xpp.flags = xdl_opts; + memset(&xecfg, 0, sizeof(xecfg)); + xecfg.ctxlen = 1; memset(split, 0, sizeof(struct blame_entry [3])); - plno = tlno = 0; - for (i = 0; i < patch->num; i++) { - struct chunk *chunk = &patch->chunks[i]; - - handle_split(sb, ent, tlno, plno, chunk->same, parent, split); - plno = chunk->p_next; - tlno = chunk->t_next; - } + xdi_diff_hunks(file_p, &file_o, handle_split_cb, &d, &xpp, &xecfg); /* remainder, if any, all match the preimage */ - handle_split(sb, ent, tlno, plno, ent->num_lines, parent, split); - free_patch(patch); + handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split); } /* From 7cdc3556d1cec11582ae2a018d4052767c02e1ef Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 24 Oct 2008 12:13:01 +0400 Subject: [PATCH 009/138] gitk: Allow starting gui blame for a specific line This adds a context menu item to the diff viewer pane that calls git gui blame, focusing it on the clicked line. In case of combined diffs, it also automatically deduces which parent is to be blamed. Lines added by the diff are blamed on the current commit itself. The context menu itself is added by this patch. It would be possible to add the commands from the flist menu to it. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 146 insertions(+), 2 deletions(-) diff --git a/gitk b/gitk index f6a3e10d8e..0003797697 100755 --- a/gitk +++ b/gitk @@ -2249,6 +2249,7 @@ proc makewindow {} { bind $cflist {treeclick %W %x %y} global ctxbut bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y} + bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y} set maincursor [. cget -cursor] set textcursor [$ctext cget -cursor] @@ -2291,6 +2292,13 @@ proc makewindow {} { {mc "Blame parent commit" command {external_blame 1}} } $flist_menu configure -tearoff 0 + + global diff_menu + set diff_menu .diffctxmenu + makemenu $diff_menu { + {mc "Run git gui blame on this line" command {external_blame_diff}} + } + $diff_menu configure -tearoff 0 } # Windows sends all mouse wheel events to the current focused window, not @@ -2993,6 +3001,34 @@ proc pop_flist_menu {w X Y x y} { tk_popup $flist_menu $X $Y } +proc find_ctext_fileinfo {line} { + global ctext_file_names ctext_file_lines + + set ok [bsearch $ctext_file_lines $line] + set tline [lindex $ctext_file_lines $ok] + + if {$ok >= [llength $ctext_file_lines] || $line < $tline} { + return {} + } else { + return [list [lindex $ctext_file_names $ok] $tline] + } +} + +proc pop_diff_menu {w X Y x y} { + global ctext diff_menu flist_menu_file + global diff_menu_txtpos diff_menu_line + global diff_menu_filebase + + stopfinding + set diff_menu_txtpos [split [$w index "@$x,$y"] "."] + set diff_menu_line [lindex $diff_menu_txtpos 0] + set f [find_ctext_fileinfo $diff_menu_line] + if {$f eq {}} return + set flist_menu_file [lindex $f 0] + set diff_menu_filebase [lindex $f 1] + tk_popup $diff_menu $X $Y +} + proc flist_hl {only} { global flist_menu_file findstring gdttype @@ -3099,7 +3135,96 @@ proc external_diff {} { } } -proc external_blame {parent_idx} { +proc find_hunk_blamespec {base line} { + global ctext + + # Find and parse the hunk header + set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0] + if {$s_lix eq {}} return + + set s_line [$ctext get $s_lix "$s_lix + 1 lines"] + if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \ + s_line old_specs osz osz1 new_line nsz]} { + return + } + + # base lines for the parents + set base_lines [list $new_line] + foreach old_spec [lrange [split $old_specs " "] 1 end] { + if {![regexp -- {-(\d+)(,\d+)?} $old_spec \ + old_spec old_line osz]} { + return + } + lappend base_lines $old_line + } + + # Now scan the lines to determine offset within the hunk + set parent {} + set max_parent [expr {[llength $base_lines]-2}] + set dline 0 + set s_lno [lindex [split $s_lix "."] 0] + + for {set i $line} {$i > $s_lno} {incr i -1} { + set c_line [$ctext get $i.0 "$i.0 + 1 lines"] + # Determine if the line is removed + set chunk [string range $c_line 0 $max_parent] + set removed_idx [string first "-" $chunk] + # Choose a parent index + if {$parent eq {}} { + if {$removed_idx >= 0} { + set parent $removed_idx + } else { + set unchanged_idx [string first " " $chunk] + if {$unchanged_idx >= 0} { + set parent $unchanged_idx + } else { + # blame the current commit + set parent -1 + } + } + } + # then count other lines that belong to it + if {$parent >= 0} { + set code [string index $c_line $parent] + if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} { + incr dline + } + } else { + if {$removed_idx < 0} { + incr dline + } + } + } + + if {$parent eq {}} { set parent -1 } + incr parent + incr dline [lindex $base_lines $parent] + return [list $parent $dline] +} + +proc external_blame_diff {} { + global currentid diffmergeid cmitmode + global diff_menu_txtpos diff_menu_line + global diff_menu_filebase flist_menu_file + + if {$cmitmode eq "tree"} { + set parent_idx 0 + set line [expr {$diff_menu_line - $diff_menu_filebase - 1}] + } else { + set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line] + if {$hinfo ne {}} { + set parent_idx [lindex $hinfo 0] + set line [lindex $hinfo 1] + } else { + set parent_idx 0 + set line 0 + } + } + + external_blame $parent_idx $line +} + +proc external_blame {parent_idx {line {}}} { global flist_menu_file global nullid nullid2 global parentlist selectedline currentid @@ -3115,7 +3240,12 @@ proc external_blame {parent_idx} { return } - if {[catch {exec git gui blame $base_commit $flist_menu_file &} err]} { + set cmdline [list git gui blame] + if {$line ne {} && $line > 1} { + lappend cmdline "--line=$line" + } + lappend cmdline $base_commit $flist_menu_file + if {[catch {eval exec $cmdline &} err]} { error_popup "[mc "git gui blame: command failed:"] $err" } } @@ -6364,6 +6494,7 @@ proc gettreeline {gtf id} { proc showfile {f} { global treefilelist treeidlist diffids nullid nullid2 + global ctext_file_names ctext_file_lines global ctext commentend set i [lsearch -exact $treefilelist($diffids) $f] @@ -6387,6 +6518,8 @@ proc showfile {f} { filerun $bf [list getblobline $bf $diffids] $ctext config -state normal clear_ctext $commentend + lappend ctext_file_names $f + lappend ctext_file_lines [lindex [split $commentend "."] 0] $ctext insert end "\n" $ctext insert end "$f\n" filesep $ctext config -state disabled @@ -6447,6 +6580,7 @@ proc mergediff {id} { proc getmergediffline {mdf id np} { global diffmergeid ctext cflist mergemax global difffilestart mdifffd treediffs + global ctext_file_names ctext_file_lines global diffencoding $ctext conf -state normal @@ -6465,6 +6599,8 @@ proc getmergediffline {mdf id np} { lappend difffilestart $here lappend treediffs($id) $fname add_flist [list $fname] + lappend ctext_file_names $fname + lappend ctext_file_lines [lindex [split $here "."] 0] set diffencoding [get_path_encoding $fname] set l [expr {(78 - [string length $fname]) / 2}] set pad [string range "----------------------------------------" 1 $l] @@ -6733,11 +6869,13 @@ proc setinlist {var i val} { proc makediffhdr {fname ids} { global ctext curdiffstart treediffs + global ctext_file_names set i [lsearch -exact $treediffs($ids) $fname] if {$i >= 0} { setinlist difffilestart $i $curdiffstart } + set ctext_file_names [lreplace $ctext_file_names end end $fname] set l [expr {(78 - [string length $fname]) / 2}] set pad [string range "----------------------------------------" 1 $l] $ctext insert $curdiffstart "$pad $fname $pad" filesep @@ -6746,6 +6884,7 @@ proc makediffhdr {fname ids} { proc getblobdiffline {bdf ids} { global diffids blobdifffd ctext curdiffstart global diffnexthead diffnextnote difffilestart + global ctext_file_names ctext_file_lines global diffinhdr treediffs global diffencoding @@ -6763,6 +6902,8 @@ proc getblobdiffline {bdf ids} { # start of a new file $ctext insert end "\n" set curdiffstart [$ctext index "end - 1c"] + lappend ctext_file_names "" + lappend ctext_file_lines [lindex [split $curdiffstart "."] 0] $ctext insert end "\n" filesep # If the name hasn't changed the length will be odd, # the middle char will be a space, and the two bits either @@ -6899,6 +7040,7 @@ proc nextfile {} { proc clear_ctext {{first 1.0}} { global ctext smarktop smarkbot + global ctext_file_names ctext_file_lines global pendinglinks set l [lindex [split $first .] 0] @@ -6912,6 +7054,8 @@ proc clear_ctext {{first 1.0}} { if {$first eq "1.0"} { catch {unset pendinglinks} } + set ctext_file_names {} + set ctext_file_lines {} } proc settabs {{firstab {}}} { From 72cf48414071636546eddfbfc828eda81649cb48 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Oct 2008 00:41:28 -0400 Subject: [PATCH 010/138] diff: add missing static declaration This function isn't used outside of diff.c; the 'static' was simply overlooked in the original writing. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff.c b/diff.c index e368fef14f..d1fd594ba3 100644 --- a/diff.c +++ b/diff.c @@ -1282,7 +1282,7 @@ static void emit_binary_diff(FILE *file, mmfile_t *one, mmfile_t *two) emit_binary_diff_body(file, two, one); } -void diff_filespec_load_driver(struct diff_filespec *one) +static void diff_filespec_load_driver(struct diff_filespec *one) { if (!one->driver) one->driver = userdiff_find_by_path(one->path); From 678852d918e874c99590ba6e857efeef974a3fb9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Oct 2008 00:41:52 -0400 Subject: [PATCH 011/138] document the diff driver textconv feature This patch also changes the term "custom diff driver" to "external diff driver"; now that there are more facets of a "custom driver" than just external diffing, it makes sense to refer to the configuration of "diff.foo.*" as the "foo diff driver", with "diff.foo.command" as the "external driver for foo". Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/gitattributes.txt | 66 ++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index 26945593cb..314e2d32e5 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -213,10 +213,12 @@ with `crlf`, and then `ident` and fed to `filter`. Generating diff text ~~~~~~~~~~~~~~~~~~~~ -The attribute `diff` affects if 'git-diff' generates textual -patch for the path or just says `Binary files differ`. It also -can affect what line is shown on the hunk header `@@ -k,l +n,m @@` -line. +The attribute `diff` affects how 'git' generates diffs for particular +files. It can tell git whether to generate a textual patch for the path +or to treat the path as a binary file. It can also affect what line is +shown on the hunk header `@@ -k,l +n,m @@` line, tell git to use an +external command to generate the diff, or ask git to convert binary +files to a text format before generating the diff. Set:: @@ -227,7 +229,8 @@ Set:: Unset:: A path to which the `diff` attribute is unset will - generate `Binary files differ`. + generate `Binary files differ` (or a binary patch, if + binary patches are enabled). Unspecified:: @@ -238,21 +241,21 @@ Unspecified:: String:: - Diff is shown using the specified custom diff driver. - The driver program is given its input using the same - calling convention as used for GIT_EXTERNAL_DIFF - program. This name is also used for custom hunk header - selection. + Diff is shown using the specified diff driver. Each driver may + specify one or more options, as described in the following + section. The options for the diff driver "foo" are defined + by the configuration variables in the "diff.foo" section of the + git config file. -Defining a custom diff driver -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Defining an external diff driver +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The definition of a diff driver is done in `gitconfig`, not `gitattributes` file, so strictly speaking this manual page is a wrong place to talk about it. However... -To define a custom diff driver `jcdiff`, add a section to your +To define an external diff driver `jcdiff`, add a section to your `$GIT_DIR/config` file (or `$HOME/.gitconfig` file) like this: ---------------------------------------------------------------- @@ -328,6 +331,43 @@ patterns are available: - `tex` suitable for source code for LaTeX documents. +Performing text diffs of binary files +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Sometimes it is desirable to see the diff of a text-converted +version of some binary files. For example, a word processor +document can be converted to an ASCII text representation, and +the diff of the text shown. Even though this conversion loses +some information, the resulting diff is useful for human +viewing (but cannot be applied directly). + +The `textconv` config option is used to define a program for +performing such a conversion. The program should take a single +argument, the name of a file to convert, and produce the +resulting text on stdout. + +For example, to show the diff of the exif information of a +file instead of the binary information (assuming you have the +exif tool installed): + +------------------------ +[diff "jpg"] + textconv = exif +------------------------ + +NOTE: The text conversion is generally a one-way conversion; +in this example, we lose the actual image contents and focus +just on the text data. This means that diffs generated by +textconv are _not_ suitable for applying. For this reason, +only `git diff` and the `git log` family of commands (i.e., +log, whatchanged, show) will perform text conversion. `git +format-patch` will never generate this output. If you want to +send somebody a text-converted diff of a binary file (e.g., +because it quickly conveys the changes you have made), you +should generate it separately and send it as a comment _in +addition to_ the usual binary diff that you might send. + + Performing a three-way merge ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 04427ac8483f61dcb01a48c78a821f5042c88195 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Oct 2008 00:44:53 -0400 Subject: [PATCH 012/138] refactor userdiff textconv code The original implementation of textconv put the conversion into fill_mmfile. This was a bad idea for a number of reasons: - it made the semantics of fill_mmfile unclear. In some cases, it was allocating data (if a text conversion occurred), and in some cases not (if we could use the data directly from the filespec). But the caller had no idea which had happened, and so didn't know whether the memory should be freed - similarly, the caller had no idea if a text conversion had occurred, and so didn't know whether the contents should be treated as binary or not. This meant that we incorrectly guessed that text-converted content was binary and didn't actually show it (unless the user overrode us with "diff.foo.binary = false", which then created problems in plumbing where the text conversion did _not_ occur) - not all callers of fill_mmfile want the text contents. In particular, we don't really want diffstat, whitespace checks, patch id generation, etc, to look at the converted contents. This patch pulls the conversion code directly into builtin_diff, so that we only see the conversion when generating an actual patch. We also then know whether we are doing a conversion, so we can check the binary-ness and free the data from the mmfile appropriately (the previous version leaked quite badly when text conversion was used) Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 48 +++++++++++++++++++++++++++++----------- t/t4030-diff-textconv.sh | 6 ++--- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/diff.c b/diff.c index d1fd594ba3..6f01595ece 100644 --- a/diff.c +++ b/diff.c @@ -294,18 +294,8 @@ static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one) else if (diff_populate_filespec(one, 0)) return -1; - diff_filespec_load_driver(one); - if (one->driver->textconv) { - size_t size; - mf->ptr = run_textconv(one->driver->textconv, one, &size); - if (!mf->ptr) - return -1; - mf->size = size; - } - else { - mf->ptr = one->data; - mf->size = one->size; - } + mf->ptr = one->data; + mf->size = one->size; return 0; } @@ -1323,6 +1313,14 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const options->b_prefix = b; } +static const char *get_textconv(struct diff_filespec *one) +{ + if (!DIFF_FILE_VALID(one)) + return NULL; + diff_filespec_load_driver(one); + return one->driver->textconv; +} + static void builtin_diff(const char *name_a, const char *name_b, struct diff_filespec *one, @@ -1337,6 +1335,7 @@ static void builtin_diff(const char *name_a, const char *set = diff_get_color_opt(o, DIFF_METAINFO); const char *reset = diff_get_color_opt(o, DIFF_RESET); const char *a_prefix, *b_prefix; + const char *textconv_one, *textconv_two; diff_set_mnemonic_prefix(o, "a/", "b/"); if (DIFF_OPT_TST(o, REVERSE_DIFF)) { @@ -1390,8 +1389,12 @@ static void builtin_diff(const char *name_a, if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0) die("unable to read files to diff"); + textconv_one = get_textconv(one); + textconv_two = get_textconv(two); + if (!DIFF_OPT_TST(o, TEXT) && - (diff_filespec_is_binary(one) || diff_filespec_is_binary(two))) { + ( (diff_filespec_is_binary(one) && !textconv_one) || + (diff_filespec_is_binary(two) && !textconv_two) )) { /* Quite common confusing case */ if (mf1.size == mf2.size && !memcmp(mf1.ptr, mf2.ptr, mf1.size)) @@ -1412,6 +1415,21 @@ static void builtin_diff(const char *name_a, struct emit_callback ecbdata; const struct userdiff_funcname *pe; + if (textconv_one) { + size_t size; + mf1.ptr = run_textconv(textconv_one, one, &size); + if (!mf1.ptr) + die("unable to read files to diff"); + mf1.size = size; + } + if (textconv_two) { + size_t size; + mf2.ptr = run_textconv(textconv_two, two, &size); + if (!mf2.ptr) + die("unable to read files to diff"); + mf2.size = size; + } + pe = diff_funcname_pattern(one); if (!pe) pe = diff_funcname_pattern(two); @@ -1443,6 +1461,10 @@ static void builtin_diff(const char *name_a, &xpp, &xecfg, &ecb); if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS)) free_diff_words_data(&ecbdata); + if (textconv_one) + free(mf1.ptr); + if (textconv_two) + free(mf2.ptr); } free_ab_and_return: diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index 1b0964843e..090a21d0b5 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -52,7 +52,7 @@ test_expect_success 'setup textconv filters' ' git config diff.fail.textconv false ' -test_expect_failure 'diff produces text' ' +test_expect_success 'diff produces text' ' git diff HEAD^ HEAD >diff && find_diff actual && test_cmp expect.text actual @@ -64,7 +64,7 @@ test_expect_success 'diff-tree produces binary' ' test_cmp expect.binary actual ' -test_expect_failure 'log produces text' ' +test_expect_success 'log produces text' ' git log -1 -p >log && find_diff actual && test_cmp expect.text actual @@ -80,7 +80,7 @@ cat >expect.stat <<'EOF' file | Bin 2 -> 4 bytes 1 files changed, 0 insertions(+), 0 deletions(-) EOF -test_expect_failure 'diffstat does not run textconv' ' +test_expect_success 'diffstat does not run textconv' ' echo file diff=fail >.gitattributes && git diff --stat HEAD^ HEAD >actual && test_cmp expect.stat actual From c7534ef4a12bb44806d522fc8e3961e390f9169b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Oct 2008 00:45:55 -0400 Subject: [PATCH 013/138] userdiff: require explicitly allowing textconv Diffs that have been produced with textconv almost certainly cannot be applied, so we want to be careful not to generate them in things like format-patch. This introduces a new diff options, ALLOW_TEXTCONV, which controls this behavior. It is off by default, but is explicitly turned on for the "log" family of commands, as well as the "diff" porcelain (but not diff-* plumbing). Because both text conversion and external diffing are controlled by these diff options, we can get rid of the "plumbing versus porcelain" distinction when reading the config. This was an attempt to control the same thing, but suffered from being too coarse-grained. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-diff.c | 1 + builtin-log.c | 1 + diff.c | 26 +++++++++++--------------- diff.h | 1 + t/t4030-diff-textconv.sh | 2 +- userdiff.c | 10 +--------- userdiff.h | 3 +-- 7 files changed, 17 insertions(+), 27 deletions(-) diff --git a/builtin-diff.c b/builtin-diff.c index 9c8c295732..2de5834c11 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -300,6 +300,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) } DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL); DIFF_OPT_SET(&rev.diffopt, RECURSIVE); + DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV); /* * If the user asked for our exit code then don't start a diff --git a/builtin-log.c b/builtin-log.c index a0944f70a4..75d698f0ce 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -59,6 +59,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, } else die("unrecognized argument: %s", arg); } + DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV); } /* diff --git a/diff.c b/diff.c index 6f01595ece..608223ab56 100644 --- a/diff.c +++ b/diff.c @@ -93,12 +93,6 @@ int git_diff_ui_config(const char *var, const char *value, void *cb) if (!strcmp(var, "diff.external")) return git_config_string(&external_diff_cmd_cfg, var, value); - switch (userdiff_config_porcelain(var, value)) { - case 0: break; - case -1: return -1; - default: return 0; - } - return git_diff_basic_config(var, value, cb); } @@ -109,6 +103,12 @@ int git_diff_basic_config(const char *var, const char *value, void *cb) return 0; } + switch (userdiff_config(var, value)) { + case 0: break; + case -1: return -1; + default: return 0; + } + if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) { int slot = parse_diff_color_slot(var, 11); if (!value) @@ -123,12 +123,6 @@ int git_diff_basic_config(const char *var, const char *value, void *cb) return 0; } - switch (userdiff_config_basic(var, value)) { - case 0: break; - case -1: return -1; - default: return 0; - } - return git_color_default_config(var, value, cb); } @@ -1335,7 +1329,7 @@ static void builtin_diff(const char *name_a, const char *set = diff_get_color_opt(o, DIFF_METAINFO); const char *reset = diff_get_color_opt(o, DIFF_RESET); const char *a_prefix, *b_prefix; - const char *textconv_one, *textconv_two; + const char *textconv_one = NULL, *textconv_two = NULL; diff_set_mnemonic_prefix(o, "a/", "b/"); if (DIFF_OPT_TST(o, REVERSE_DIFF)) { @@ -1389,8 +1383,10 @@ static void builtin_diff(const char *name_a, if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0) die("unable to read files to diff"); - textconv_one = get_textconv(one); - textconv_two = get_textconv(two); + if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) { + textconv_one = get_textconv(one); + textconv_two = get_textconv(two); + } if (!DIFF_OPT_TST(o, TEXT) && ( (diff_filespec_is_binary(one) && !textconv_one) || diff --git a/diff.h b/diff.h index a49d865bd9..42582edee6 100644 --- a/diff.h +++ b/diff.h @@ -65,6 +65,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, #define DIFF_OPT_IGNORE_SUBMODULES (1 << 18) #define DIFF_OPT_DIRSTAT_CUMULATIVE (1 << 19) #define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20) +#define DIFF_OPT_ALLOW_TEXTCONV (1 << 21) #define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag) #define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag) #define DIFF_OPT_CLR(opts, flag) ((opts)->flags &= ~DIFF_OPT_##flag) diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index 090a21d0b5..1df48ae12a 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -70,7 +70,7 @@ test_expect_success 'log produces text' ' test_cmp expect.text actual ' -test_expect_failure 'format-patch produces binary' ' +test_expect_success 'format-patch produces binary' ' git format-patch --no-binary --stdout HEAD^ >patch && find_diff actual && test_cmp expect.binary actual diff --git a/userdiff.c b/userdiff.c index d95257ab3b..3681062ebf 100644 --- a/userdiff.c +++ b/userdiff.c @@ -120,7 +120,7 @@ static int parse_tristate(int *b, const char *k, const char *v) return 1; } -int userdiff_config_basic(const char *k, const char *v) +int userdiff_config(const char *k, const char *v) { struct userdiff_driver *drv; @@ -130,14 +130,6 @@ int userdiff_config_basic(const char *k, const char *v) return parse_funcname(&drv->funcname, k, v, REG_EXTENDED); if ((drv = parse_driver(k, v, "binary"))) return parse_tristate(&drv->binary, k, v); - - return 0; -} - -int userdiff_config_porcelain(const char *k, const char *v) -{ - struct userdiff_driver *drv; - if ((drv = parse_driver(k, v, "command"))) return parse_string(&drv->external, k, v); if ((drv = parse_driver(k, v, "textconv"))) diff --git a/userdiff.h b/userdiff.h index f29c18ffb3..ba2945770b 100644 --- a/userdiff.h +++ b/userdiff.h @@ -14,8 +14,7 @@ struct userdiff_driver { const char *textconv; }; -int userdiff_config_basic(const char *k, const char *v); -int userdiff_config_porcelain(const char *k, const char *v); +int userdiff_config(const char *k, const char *v); struct userdiff_driver *userdiff_find_by_name(const char *name); struct userdiff_driver *userdiff_find_by_path(const char *path); From 2675773af893ae81f9b09f18c1f2ec86ca2158e7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Oct 2008 00:46:21 -0400 Subject: [PATCH 014/138] only textconv regular files We treat symlinks as text containing the results of the symlink, so it doesn't make much sense to text-convert them. Similarly gitlink components just end up as the text "Subproject commit $sha1", which we should leave intact. Note that a typechange may be broken into two parts: the removal of the old part and the addition of the new. In that case, we _do_ show the textconv for any part which is the addition or removal of a file we would ordinarily textconv, since it is purely acting on the file contents. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 2 ++ t/t4030-diff-textconv.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/diff.c b/diff.c index 608223ab56..23d454e71d 100644 --- a/diff.c +++ b/diff.c @@ -1311,6 +1311,8 @@ static const char *get_textconv(struct diff_filespec *one) { if (!DIFF_FILE_VALID(one)) return NULL; + if (!S_ISREG(one->mode)) + return NULL; diff_filespec_load_driver(one); return one->driver->textconv; } diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index 1df48ae12a..3945731e9a 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -104,7 +104,7 @@ index ad8b3d2..67be421 \ No newline at end of file EOF # make a symlink the hard way that works on symlink-challenged file systems -test_expect_failure 'textconv does not act on symlinks' ' +test_expect_success 'textconv does not act on symlinks' ' echo -n frotz > file && git add file && git ls-files -s | sed -e s/100644/120000/ | From 4f672ad6c77bfe73cc5dd4b240fd42303d101d2a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Oct 2008 00:49:35 -0400 Subject: [PATCH 015/138] wt-status: load diff ui config When "git status -v" shows a diff, we did not respect the user's usual diff preferences at all. Loading just git_diff_basic_config would give us things like rename limits and diff drivers. But it makes even more sense to load git_diff_ui_config, which gives us colorization if the user has requested it. Note that we need to take special care to cancel colorization when writing to the commit template file, as described in the code comments. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t7502-commit.sh | 8 ++++++++ wt-status.c | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 3eb9faedcf..ad42c78d7c 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -89,6 +89,14 @@ test_expect_success 'verbose' ' ' +test_expect_success 'verbose respects diff config' ' + + git config color.diff always && + git status -v >actual && + grep "\[1mdiff --git" actual && + git config --unset color.diff +' + test_expect_success 'cleanup commit messages (verbatim,-t)' ' echo >>negative && diff --git a/wt-status.c b/wt-status.c index c3a9cab898..54d2f58693 100644 --- a/wt-status.c +++ b/wt-status.c @@ -303,6 +303,14 @@ static void wt_status_print_verbose(struct wt_status *s) rev.diffopt.detect_rename = 1; rev.diffopt.file = s->fp; rev.diffopt.close_file = 0; + /* + * If we're not going to stdout, then we definitely don't + * want color, since we are going to the commit message + * file (and even the "auto" setting won't work, since it + * will have checked isatty on stdout). + */ + if (s->fp != stdout) + DIFF_OPT_CLR(&rev.diffopt, COLOR_DIFF); run_diff_index(&rev, 1); } @@ -422,5 +430,5 @@ int git_status_config(const char *k, const char *v, void *cb) return error("Invalid untracked files mode '%s'", v); return 0; } - return git_color_default_config(k, v, cb); + return git_diff_ui_config(k, v, cb); } From df5e91fc2c95e051744ec9b9de66869d2b323037 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Oct 2008 00:42:25 -0400 Subject: [PATCH 016/138] add userdiff textconv tests These tests provide a basic sanity check that textconv'd files work. The tests try to describe how this configuration _should_ work; thus some of the tests are marked to expect failure. In particular, we fail to actually textconv anything because the 'diff.foo.binary' config option is not set, which will be fixed in the next patch. This also means that some "expect_failure" tests actually seem to be fixed; in reality, this is just because textconv is broken and its failure mode happens to make these tests work. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t4030-diff-textconv.sh | 118 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100755 t/t4030-diff-textconv.sh diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh new file mode 100755 index 0000000000..1b0964843e --- /dev/null +++ b/t/t4030-diff-textconv.sh @@ -0,0 +1,118 @@ +#!/bin/sh + +test_description='diff.*.textconv tests' +. ./test-lib.sh + +find_diff() { + sed '1,/^index /d' | sed '/^-- $/,$d' +} + +cat >expect.binary <<'EOF' +Binary files a/file and b/file differ +EOF + +cat >expect.text <<'EOF' +--- a/file ++++ b/file +@@ -1 +1,2 @@ + 0 ++1 +EOF + +cat >hexdump <<'EOF' +#!/bin/sh +perl -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' "$1" +EOF +chmod +x hexdump + +test_expect_success 'setup binary file with history' ' + printf "\\0\\n" >file && + git add file && + git commit -m one && + printf "\\1\\n" >>file && + git add file && + git commit -m two +' + +test_expect_success 'file is considered binary by porcelain' ' + git diff HEAD^ HEAD >diff && + find_diff actual && + test_cmp expect.binary actual +' + +test_expect_success 'file is considered binary by plumbing' ' + git diff-tree -p HEAD^ HEAD >diff && + find_diff actual && + test_cmp expect.binary actual +' + +test_expect_success 'setup textconv filters' ' + echo file diff=foo >.gitattributes && + git config diff.foo.textconv "$PWD"/hexdump && + git config diff.fail.textconv false +' + +test_expect_failure 'diff produces text' ' + git diff HEAD^ HEAD >diff && + find_diff actual && + test_cmp expect.text actual +' + +test_expect_success 'diff-tree produces binary' ' + git diff-tree -p HEAD^ HEAD >diff && + find_diff actual && + test_cmp expect.binary actual +' + +test_expect_failure 'log produces text' ' + git log -1 -p >log && + find_diff actual && + test_cmp expect.text actual +' + +test_expect_failure 'format-patch produces binary' ' + git format-patch --no-binary --stdout HEAD^ >patch && + find_diff actual && + test_cmp expect.binary actual +' + +cat >expect.stat <<'EOF' + file | Bin 2 -> 4 bytes + 1 files changed, 0 insertions(+), 0 deletions(-) +EOF +test_expect_failure 'diffstat does not run textconv' ' + echo file diff=fail >.gitattributes && + git diff --stat HEAD^ HEAD >actual && + test_cmp expect.stat actual +' +# restore working setup +echo file diff=foo >.gitattributes + +cat >expect.typechange <<'EOF' +--- a/file ++++ /dev/null +@@ -1,2 +0,0 @@ +-0 +-1 +diff --git a/file b/file +new file mode 120000 +index ad8b3d2..67be421 +--- /dev/null ++++ b/file +@@ -0,0 +1 @@ ++frotz +\ No newline at end of file +EOF +# make a symlink the hard way that works on symlink-challenged file systems +test_expect_failure 'textconv does not act on symlinks' ' + echo -n frotz > file && + git add file && + git ls-files -s | sed -e s/100644/120000/ | + git update-index --index-info && + git commit -m typechange && + git show >diff && + find_diff actual && + test_cmp expect.typechange actual +' + +test_done From a79b8b6623288f7d5409ad749cc6553976a4f0e8 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Oct 2008 00:50:02 -0400 Subject: [PATCH 017/138] enable textconv for diff in verbose status/commit This diff is meant for human consumption, so it makes sense to apply text conversion here, as we would for the regular diff porcelain. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t4030-diff-textconv.sh | 8 ++++++++ wt-status.c | 1 + 2 files changed, 9 insertions(+) diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index 3945731e9a..09967f5663 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -76,6 +76,14 @@ test_expect_success 'format-patch produces binary' ' test_cmp expect.binary actual ' +test_expect_success 'status -v produces text' ' + git reset --soft HEAD^ && + git status -v >diff && + find_diff actual && + test_cmp expect.text actual && + git reset --soft HEAD@{1} +' + cat >expect.stat <<'EOF' file | Bin 2 -> 4 bytes 1 files changed, 0 insertions(+), 0 deletions(-) diff --git a/wt-status.c b/wt-status.c index 54d2f58693..6a7645ed86 100644 --- a/wt-status.c +++ b/wt-status.c @@ -301,6 +301,7 @@ static void wt_status_print_verbose(struct wt_status *s) setup_revisions(0, NULL, &rev, s->reference); rev.diffopt.output_format |= DIFF_FORMAT_PATCH; rev.diffopt.detect_rename = 1; + DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV); rev.diffopt.file = s->fp; rev.diffopt.close_file = 0; /* From 190ec52c901b1e003f73ad97e88f4626d20a9e4e Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 27 Oct 2008 21:13:37 +1100 Subject: [PATCH 018/138] gitk: Fix some off-by-one errors in computing which line to blame When walking back from the line where a right-click happened to the previous hunk separator line to calculate the line number to work on, we were counting every line including the one clicked on. That isn't right; if the user clicked on the line immediately after the hunk separator then the correct line number would be the one from the hunk separator. Therefore this looks at the clicked-on line to work out which parent to blame (or whether to blame the current commit), and then looks only at the preceding lines to work out the offset from the line number in the hunk separator. This also fixes an off-by-one error when we are showing files rather than diffs. In this case diff_menu_filebase is the line number of the banner showing the file name, so the first line of the file is at line $diff_menu_filebase + 1. This also simplifies the code in find_hunk_blamespec a bit and arranges that we don't pop up the context menu if the user clicks on a file separator line or a hunk separator line. Signed-off-by: Paul Mackerras --- gitk | 60 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/gitk b/gitk index 0003797697..477590eed6 100755 --- a/gitk +++ b/gitk @@ -3019,9 +3019,13 @@ proc pop_diff_menu {w X Y x y} { global diff_menu_txtpos diff_menu_line global diff_menu_filebase - stopfinding set diff_menu_txtpos [split [$w index "@$x,$y"] "."] set diff_menu_line [lindex $diff_menu_txtpos 0] + # don't pop up the menu on hunk-separator or file-separator lines + if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} { + return + } + stopfinding set f [find_ctext_fileinfo $diff_menu_line] if {$f eq {}} return set flist_menu_file [lindex $f 0] @@ -3159,45 +3163,47 @@ proc find_hunk_blamespec {base line} { } # Now scan the lines to determine offset within the hunk - set parent {} set max_parent [expr {[llength $base_lines]-2}] set dline 0 set s_lno [lindex [split $s_lix "."] 0] - for {set i $line} {$i > $s_lno} {incr i -1} { - set c_line [$ctext get $i.0 "$i.0 + 1 lines"] - # Determine if the line is removed - set chunk [string range $c_line 0 $max_parent] + # Determine if the line is removed + set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"] + if {[string match {[-+ ]*} $chunk]} { set removed_idx [string first "-" $chunk] # Choose a parent index - if {$parent eq {}} { - if {$removed_idx >= 0} { - set parent $removed_idx + if {$removed_idx >= 0} { + set parent $removed_idx + } else { + set unchanged_idx [string first " " $chunk] + if {$unchanged_idx >= 0} { + set parent $unchanged_idx } else { - set unchanged_idx [string first " " $chunk] - if {$unchanged_idx >= 0} { - set parent $unchanged_idx - } else { - # blame the current commit - set parent -1 - } + # blame the current commit + set parent -1 } } # then count other lines that belong to it - if {$parent >= 0} { - set code [string index $c_line $parent] - if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} { - incr dline - } - } else { - if {$removed_idx < 0} { - incr dline + for {set i $line} {[incr i -1] > $s_lno} {} { + set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"] + # Determine if the line is removed + set removed_idx [string first "-" $chunk] + if {$parent >= 0} { + set code [string index $chunk $parent] + if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} { + incr dline + } + } else { + if {$removed_idx < 0} { + incr dline + } } } + incr parent + } else { + set parent 0 } - if {$parent eq {}} { set parent -1 } - incr parent incr dline [lindex $base_lines $parent] return [list $parent $dline] } @@ -3209,7 +3215,7 @@ proc external_blame_diff {} { if {$cmitmode eq "tree"} { set parent_idx 0 - set line [expr {$diff_menu_line - $diff_menu_filebase - 1}] + set line [expr {$diff_menu_line - $diff_menu_filebase}] } else { set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line] if {$hinfo ne {}} { From 8a8977425e2697029414c3bcf4b627b074934bbc Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 27 Oct 2008 21:36:25 +1100 Subject: [PATCH 019/138] gitk: Add a menu item to show where a given line comes from This adds a menu item to the pop-up menu for the diff display window which makes gitk find which commit added the line (via git blame) and show that commit, with the line highlighted with a light-blue background. Signed-off-by: Paul Mackerras --- gitk | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 153 insertions(+), 7 deletions(-) diff --git a/gitk b/gitk index 477590eed6..7b02efb4fa 100755 --- a/gitk +++ b/gitk @@ -2296,6 +2296,7 @@ proc makewindow {} { global diff_menu set diff_menu .diffctxmenu makemenu $diff_menu { + {mc "Show origin of this line" command show_line_source} {mc "Run git gui blame on this line" command {external_blame_diff}} } $diff_menu configure -tearoff 0 @@ -2830,9 +2831,15 @@ proc treeclick {w x y} { } proc setfilelist {id} { - global treefilelist cflist + global treefilelist cflist jump_to_here treeview $cflist $treefilelist($id) 0 + if {$jump_to_here ne {}} { + set f [lindex $jump_to_here 0] + if {[lsearch -exact $treefilelist($id) $f] >= 0} { + showfile $f + } + } } image create bitmap tri-rt -background black -foreground blue -data { @@ -3256,6 +3263,91 @@ proc external_blame {parent_idx {line {}}} { } } +proc show_line_source {} { + global cmitmode currentid parents curview blamestuff blameinst + global diff_menu_line diff_menu_filebase flist_menu_file + + if {$cmitmode eq "tree"} { + set id $currentid + set line [expr {$diff_menu_line - $diff_menu_filebase}] + } else { + set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line] + if {$h eq {}} return + set pi [lindex $h 0] + if {$pi == 0} { + mark_ctext_line $diff_menu_line + return + } + set id [lindex $parents($curview,$currentid) [expr {$pi - 1}]] + set line [lindex $h 1] + } + if {[catch { + set f [open [list | git blame -p -L$line,+1 $id -- $flist_menu_file] r] + } err]} { + error_popup [mc "Couldn't start git blame: %s" $err] + return + } + fconfigure $f -blocking 0 + set i [reg_instance $f] + set blamestuff($i) {} + set blameinst $i + filerun $f [list read_line_source $f $i] +} + +proc stopblaming {} { + global blameinst + + if {[info exists blameinst]} { + stop_instance $blameinst + unset blameinst + } +} + +proc read_line_source {fd inst} { + global blamestuff curview commfd blameinst + + while {[gets $fd line] >= 0} { + lappend blamestuff($inst) $line + } + if {![eof $fd]} { + return 1 + } + unset commfd($inst) + unset blameinst + fconfigure $fd -blocking 1 + if {[catch {close $fd} err]} { + error_popup [mc "Error running git blame: %s" $err] + return 0 + } + + set fname {} + set line [split [lindex $blamestuff($inst) 0] " "] + set id [lindex $line 0] + set lnum [lindex $line 1] + if {[string length $id] == 40 && [string is xdigit $id] && + [string is digit -strict $lnum]} { + # look for "filename" line + foreach l $blamestuff($inst) { + if {[string match "filename *" $l]} { + set fname [string range $l 9 end] + break + } + } + } + if {$fname ne {}} { + # all looks good, select it + if {[commitinview $id $curview]} { + selectline [rowofcommit $id] 1 [list $fname $lnum] + } else { + error_popup [mc "That line comes from commit %s, \ + which is not in this view" [shortids $id]] + } + } else { + puts "oops couldn't parse git blame output" + } + return 0 +} + # delete $dir when we see eof on $f (presumably because the child has exited) proc delete_at_eof {f dir} { while {[gets $f line] >= 0} {} @@ -5748,6 +5840,7 @@ proc stopfinding {} { set fprogcoord 0 adjustprogress } + stopblaming } proc findmore {} { @@ -6152,7 +6245,7 @@ proc make_secsel {l} { $canv3 lower $t } -proc selectline {l isnew} { +proc selectline {l isnew {desired_loc {}}} { global canv ctext commitinfo selectedline global canvy0 linespc parents children curview global currentid sha1entry @@ -6160,7 +6253,7 @@ proc selectline {l isnew} { global mergemax numcommits pending_select global cmitmode showneartags allcommits global targetrow targetid lastscrollrows - global autoselect + global autoselect jump_to_here catch {unset pending_select} $canv delete hover @@ -6299,6 +6392,7 @@ proc selectline {l isnew} { $ctext conf -state disabled set commentend [$ctext index "end - 1c"] + set jump_to_here $desired_loc init_flist [mc "Comments"] if {$cmitmode eq "tree"} { gettree $id @@ -6546,15 +6640,32 @@ proc getblobline {bf id} { $ctext insert end "$line\n" } if {[eof $bf]} { + global jump_to_here ctext_file_names commentend + # delete last newline $ctext delete "end - 2c" "end - 1c" close $bf + if {$jump_to_here ne {} && + [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} { + set lnum [expr {[lindex $jump_to_here 1] + + [lindex [split $commentend .] 0]}] + mark_ctext_line $lnum + } return 0 } $ctext config -state disabled return [expr {$nl >= 1000? 2: 1}] } +proc mark_ctext_line {lnum} { + global ctext + + $ctext tag delete omark + $ctext tag add omark $lnum.0 "$lnum.0 + 1 line" + $ctext tag conf omark -background "#e0e0ff" + $ctext see $lnum.0 +} + proc mergediff {id} { global diffmergeid mdifffd global diffids treediffs @@ -6562,10 +6673,12 @@ proc mergediff {id} { global diffcontext global diffencoding global limitdiffs vfilelimit curview + global targetline set diffmergeid $id set diffids $id set treediffs($id) {} + set targetline {} # this doesn't seem to actually affect anything... set cmd [concat | git diff-tree --no-commit-id --cc -U$diffcontext $id] if {$limitdiffs && $vfilelimit($curview) ne {}} { @@ -6587,7 +6700,7 @@ proc getmergediffline {mdf id np} { global diffmergeid ctext cflist mergemax global difffilestart mdifffd treediffs global ctext_file_names ctext_file_lines - global diffencoding + global diffencoding jump_to_here targetline diffline $ctext conf -state normal set nr 0 @@ -6611,9 +6724,17 @@ proc getmergediffline {mdf id np} { set l [expr {(78 - [string length $fname]) / 2}] set pad [string range "----------------------------------------" 1 $l] $ctext insert end "$pad $fname $pad\n" filesep + set targetline {} + if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} { + set targetline [lindex $jump_to_here 1] + } + set diffline 0 } elseif {[regexp {^@@} $line]} { set line [encoding convertfrom $diffencoding $line] $ctext insert end "$line\n" hunksep + if {[regexp { \+(\d+),\d+ @@} $line m nl]} { + set diffline $nl + } } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} { # do nothing } else { @@ -6653,6 +6774,15 @@ proc getmergediffline {mdf id np} { lappend tags m$num } $ctext insert end "$line\n" $tags + if {$targetline ne {} && $minuses eq {}} { + if {$diffline == $targetline} { + set here [$ctext index "end - 1 line"] + mark_ctext_line [lindex [split $here .] 0] + set targetline {} + } else { + incr diffline + } + } } } $ctext conf -state disabled @@ -6840,7 +6970,7 @@ proc getblobdiffs {ids} { global diffcontext global ignorespace global limitdiffs vfilelimit curview - global diffencoding + global diffencoding targetline set cmd [diffcmd $ids "-p -C --no-commit-id -U$diffcontext"] if {$ignorespace} { @@ -6853,6 +6983,7 @@ proc getblobdiffs {ids} { puts "error getting diffs: $err" return } + set targetline {} set diffinhdr 0 set diffencoding [get_path_encoding {}] fconfigure $bdf -blocking 0 -encoding binary @@ -6875,7 +7006,7 @@ proc setinlist {var i val} { proc makediffhdr {fname ids} { global ctext curdiffstart treediffs - global ctext_file_names + global ctext_file_names jump_to_here targetline diffline set i [lsearch -exact $treediffs($ids) $fname] if {$i >= 0} { @@ -6885,6 +7016,11 @@ proc makediffhdr {fname ids} { set l [expr {(78 - [string length $fname]) / 2}] set pad [string range "----------------------------------------" 1 $l] $ctext insert $curdiffstart "$pad $fname $pad" filesep + set targetline {} + if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} { + set targetline [lindex $jump_to_here 1] + } + set diffline 0 } proc getblobdiffline {bdf ids} { @@ -6892,7 +7028,7 @@ proc getblobdiffline {bdf ids} { global diffnexthead diffnextnote difffilestart global ctext_file_names ctext_file_lines global diffinhdr treediffs - global diffencoding + global diffencoding jump_to_here targetline diffline set nr 0 $ctext conf -state normal @@ -6941,6 +7077,7 @@ proc getblobdiffline {bdf ids} { set line [encoding convertfrom $diffencoding $line] $ctext insert end "$line\n" hunksep set diffinhdr 0 + set diffline $f2l } elseif {$diffinhdr} { if {![string compare -length 12 "rename from " $line]} { @@ -6974,6 +7111,7 @@ proc getblobdiffline {bdf ids} { } else { set line [encoding convertfrom $diffencoding $line] set x [string range $line 0 0] + set here [$ctext index "end - 1 chars"] if {$x == "-" || $x == "+"} { set tag [expr {$x == "+"}] $ctext insert end "$line\n" d$tag @@ -6984,6 +7122,14 @@ proc getblobdiffline {bdf ids} { # or something else we don't recognize $ctext insert end "$line\n" hunksep } + if {$targetline ne {} && ($x eq " " || $x eq "+")} { + if {$diffline == $targetline} { + mark_ctext_line [lindex [split $here .] 0] + set targetline {} + } else { + incr diffline + } + } } } $ctext conf -state disabled From e3e901bece93417392faa3dd7833d69271cf74f6 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 27 Oct 2008 22:37:21 +1100 Subject: [PATCH 020/138] gitk: Make the background color of marked lines configurable This makes it possible for the user to configure the background color of lines that are "marked". At the moment only the "show the origin of this line" function marks lines. This also makes the user's choice persistent by saving it in ~/.gitk. Signed-off-by: Paul Mackerras --- gitk | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gitk b/gitk index 7b02efb4fa..3fe1b479b2 100755 --- a/gitk +++ b/gitk @@ -2415,7 +2415,7 @@ proc savestuff {w} { global viewname viewfiles viewargs viewargscmd viewperm nextviewnum global cmitmode wrapcomment datetimeformat limitdiffs global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor - global autoselect extdifftool perfile_attrs + global autoselect extdifftool perfile_attrs markbgcolor if {$stuffsaved} return if {![winfo viewable .]} return @@ -2439,6 +2439,7 @@ proc savestuff {w} { puts $f [list set fgcolor $fgcolor] puts $f [list set colors $colors] puts $f [list set diffcolors $diffcolors] + puts $f [list set markbgcolor $markbgcolor] puts $f [list set diffcontext $diffcontext] puts $f [list set selectbgcolor $selectbgcolor] puts $f [list set extdifftool $extdifftool] @@ -6658,11 +6659,11 @@ proc getblobline {bf id} { } proc mark_ctext_line {lnum} { - global ctext + global ctext markbgcolor $ctext tag delete omark $ctext tag add omark $lnum.0 "$lnum.0 + 1 line" - $ctext tag conf omark -background "#e0e0ff" + $ctext tag conf omark -background $markbgcolor $ctext see $lnum.0 } @@ -9731,7 +9732,7 @@ proc chg_fontparam {v sub op} { proc doprefs {} { global maxwidth maxgraphpct global oldprefs prefstop showneartags showlocalchanges - global bgcolor fgcolor ctext diffcolors selectbgcolor + global bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor global tabstop limitdiffs autoselect extdifftool perfile_attrs set top .gitkprefs @@ -9824,6 +9825,12 @@ proc doprefs {} { "diff hunk header" \ [list $ctext tag conf hunksep -foreground]] grid x $top.hunksepbut $top.hunksep -sticky w + label $top.markbgsep -padx 40 -relief sunk -background $markbgcolor + button $top.markbgbut -text [mc "Marked line bg"] -font optionfont \ + -command [list choosecolor markbgcolor {} $top.markbgsep \ + [mc "marked line background"] \ + [list $ctext tag conf omark -background]] + grid x $top.markbgbut $top.markbgsep -sticky w label $top.selbgsep -padx 40 -relief sunk -background $selectbgcolor button $top.selbgbut -text [mc "Select bg"] -font optionfont \ -command [list choosecolor selectbgcolor {} $top.selbgsep background setselbg] @@ -10369,6 +10376,7 @@ set diffcolors {red "#00a000" blue} set diffcontext 3 set ignorespace 0 set selectbgcolor gray85 +set markbgcolor "#e0e0ff" set circlecolors {white blue gray blue blue} From 6ecfd91df5ec462aeded967c9ad21912c249f96e Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Fri, 31 Oct 2008 01:09:13 -0400 Subject: [PATCH 021/138] Avoid using non-portable `echo -n` in tests. Expecting echo to recognise -n is a BSDism. Using printf is far more portable. Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all the test scripts. Signed-off-by: Brian Gernhardt Signed-off-by: Junio C Hamano --- t/t2005-checkout-index-symlinks.sh | 2 +- t/t2102-update-index-symlinks.sh | 4 ++-- t/t4030-diff-textconv.sh | 2 +- t/t6025-merge-symlinks.sh | 4 ++-- t/t9400-git-cvsserver-server.sh | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/t/t2005-checkout-index-symlinks.sh b/t/t2005-checkout-index-symlinks.sh index ed12c4d782..9fa5610474 100755 --- a/t/t2005-checkout-index-symlinks.sh +++ b/t/t2005-checkout-index-symlinks.sh @@ -13,7 +13,7 @@ file if core.symlinks is false.' test_expect_success \ 'preparation' ' git config core.symlinks false && -l=$(echo -n file | git hash-object -t blob -w --stdin) && +l=$(printf file | git hash-object -t blob -w --stdin) && echo "120000 $l symlink" | git update-index --index-info' test_expect_success \ diff --git a/t/t2102-update-index-symlinks.sh b/t/t2102-update-index-symlinks.sh index f195aefe3a..1ed44ee503 100755 --- a/t/t2102-update-index-symlinks.sh +++ b/t/t2102-update-index-symlinks.sh @@ -13,12 +13,12 @@ even if a plain file is in the working tree if core.symlinks is false.' test_expect_success \ 'preparation' ' git config core.symlinks false && -l=$(echo -n file | git hash-object -t blob -w --stdin) && +l=$(printf file | git hash-object -t blob -w --stdin) && echo "120000 $l symlink" | git update-index --index-info' test_expect_success \ 'modify the symbolic link' ' -echo -n new-file > symlink && +printf new-file > symlink && git update-index symlink' test_expect_success \ diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index 1b0964843e..3aed1bbdfe 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -105,7 +105,7 @@ index ad8b3d2..67be421 EOF # make a symlink the hard way that works on symlink-challenged file systems test_expect_failure 'textconv does not act on symlinks' ' - echo -n frotz > file && + printf frotz > file && git add file && git ls-files -s | sed -e s/100644/120000/ | git update-index --index-info && diff --git a/t/t6025-merge-symlinks.sh b/t/t6025-merge-symlinks.sh index 53892a555c..433c4de08f 100755 --- a/t/t6025-merge-symlinks.sh +++ b/t/t6025-merge-symlinks.sh @@ -18,11 +18,11 @@ git add file && git commit -m initial && git branch b-symlink && git branch b-file && -l=$(echo -n file | git hash-object -t blob -w --stdin) && +l=$(printf file | git hash-object -t blob -w --stdin) && echo "120000 $l symlink" | git update-index --index-info && git commit -m master && git checkout b-symlink && -l=$(echo -n file-different | git hash-object -t blob -w --stdin) && +l=$(printf file-different | git hash-object -t blob -w --stdin) && echo "120000 $l symlink" | git update-index --index-info && git commit -m b-symlink && git checkout b-file && diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index c1850d2923..6a37f71d11 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -424,7 +424,7 @@ cd "$WORKDIR" test_expect_success 'cvs update (-p)' ' touch really-empty && echo Line 1 > no-lf && - echo -n Line 2 >> no-lf && + printf "Line 2" >> no-lf && git add really-empty no-lf && git commit -q -m "Update -p test" && git push gitcvs.git >/dev/null && From 0bc3e781deb543ac2042cbd862c035403404c93d Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Sun, 26 Oct 2008 03:52:37 -0800 Subject: [PATCH 022/138] Build: add NO_UINTMAX_T to support ancient systems This adds NO_UINTMAX_T for ancient systems, such as FreeBSD 4.9-SECURITY. If NO_UINTMAX_T is defined, then uintmax_t is defined as uint32_t. Signed-off-by: David M. Syzdek Signed-off-by: Junio C Hamano --- Makefile | 3 +++ config.mak.in | 1 + configure.ac | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/Makefile b/Makefile index d6f3695c97..0698365078 100644 --- a/Makefile +++ b/Makefile @@ -955,6 +955,9 @@ endif ifdef NO_IPV6 BASIC_CFLAGS += -DNO_IPV6 endif +ifdef NO_UINTMAX_T + BASIC_CFLAGS += -Duintmax_t=uint32_t +endif ifdef NO_SOCKADDR_STORAGE ifdef NO_IPV6 BASIC_CFLAGS += -Dsockaddr_storage=sockaddr_in diff --git a/config.mak.in b/config.mak.in index 17e9861c06..717072943f 100644 --- a/config.mak.in +++ b/config.mak.in @@ -41,6 +41,7 @@ NO_C99_FORMAT=@NO_C99_FORMAT@ NO_STRCASESTR=@NO_STRCASESTR@ NO_MEMMEM=@NO_MEMMEM@ NO_STRLCPY=@NO_STRLCPY@ +NO_UINTMAX_T=@NO_UINTMAX_T@ NO_STRTOUMAX=@NO_STRTOUMAX@ NO_SETENV=@NO_SETENV@ NO_UNSETENV=@NO_UNSETENV@ diff --git a/configure.ac b/configure.ac index 27bab00a45..a0d53f3124 100644 --- a/configure.ac +++ b/configure.ac @@ -436,6 +436,14 @@ AC_CHECK_FUNC(strlcpy, [NO_STRLCPY=YesPlease]) AC_SUBST(NO_STRLCPY) # +# Define NO_UINTMAX_T if your platform does not have uintmax_t +AC_CHECK_TYPE(uintmax_t, +[NO_UINTMAX_T=], +[NO_UINTMAX_T=YesPlease],[ +#include +]) +AC_SUBST(NO_UINTMAX_T) +# # Define NO_STRTOUMAX if you don't have strtoumax in the C library. AC_CHECK_FUNC(strtoumax, [NO_STRTOUMAX=], From 069bb5765c04645313d79a1eb345a4fb8fe7f06c Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Sun, 26 Oct 2008 03:52:47 -0800 Subject: [PATCH 023/138] Add Makefile check for FreeBSD 4.9-SECURITY If the system is FreeBSD 4.9, then NO_UINTMAX_T and NO_STRTOUMAX is defined. Signed-off-by: David M. Syzdek Signed-off-by: Junio C Hamano --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 0698365078..426e1a652f 100644 --- a/Makefile +++ b/Makefile @@ -694,6 +694,10 @@ ifeq ($(uname_S),FreeBSD) THREADED_DELTA_SEARCH = YesPlease COMPAT_CFLAGS += -Icompat/regex COMPAT_OBJS += compat/regex/regex.o + ifeq ($(shell expr "$(uname_R)" : '4\.'),2) + NO_UINTMAX_T = YesPlease + NO_STRTOUMAX = YesPlease + endif endif ifeq ($(uname_S),OpenBSD) NO_STRCASESTR = YesPlease From 8b07dca18a498c5900edc717d216e841d6c15dc9 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Sun, 2 Nov 2008 22:34:47 +1100 Subject: [PATCH 024/138] gitk: Unify handling of merge diffs with normal 2-way diffs This adds code to getblobdiffline to make it able to recognize and display merge diffs (i.e. N-way diffs for N >= 3) as well as normal two-way diffs. This means that it can also correctly display the 3-way diff of the local changes when the git repository is in the middle of a merge with conflicts. This also removes getmergediffline and changes mergediff to invoke getblobdiffline rather than getmergediffline. Signed-off-by: Paul Mackerras --- gitk | 270 ++++++++++++++++++++++------------------------------------- 1 file changed, 99 insertions(+), 171 deletions(-) diff --git a/gitk b/gitk index 3fe1b479b2..e6e49fc5cc 100755 --- a/gitk +++ b/gitk @@ -2098,7 +2098,7 @@ proc makewindow {} { $ctext tag conf filesep -font textfontbold -back "#aaaaaa" $ctext tag conf hunksep -fore [lindex $diffcolors 2] $ctext tag conf d0 -fore [lindex $diffcolors 0] - $ctext tag conf d1 -fore [lindex $diffcolors 1] + $ctext tag conf dresult -fore [lindex $diffcolors 1] $ctext tag conf m0 -fore red $ctext tag conf m1 -fore blue $ctext tag conf m2 -fore green @@ -3217,7 +3217,7 @@ proc find_hunk_blamespec {base line} { } proc external_blame_diff {} { - global currentid diffmergeid cmitmode + global currentid cmitmode global diff_menu_txtpos diff_menu_line global diff_menu_filebase flist_menu_file @@ -6668,130 +6668,16 @@ proc mark_ctext_line {lnum} { } proc mergediff {id} { - global diffmergeid mdifffd + global diffmergeid global diffids treediffs - global parents - global diffcontext - global diffencoding - global limitdiffs vfilelimit curview - global targetline + global parents curview set diffmergeid $id set diffids $id set treediffs($id) {} - set targetline {} - # this doesn't seem to actually affect anything... - set cmd [concat | git diff-tree --no-commit-id --cc -U$diffcontext $id] - if {$limitdiffs && $vfilelimit($curview) ne {}} { - set cmd [concat $cmd -- $vfilelimit($curview)] - } - if {[catch {set mdf [open $cmd r]} err]} { - error_popup "[mc "Error getting merge diffs:"] $err" - return - } - fconfigure $mdf -blocking 0 -encoding binary - set mdifffd($id) $mdf set np [llength $parents($curview,$id)] - set diffencoding [get_path_encoding {}] settabs $np - filerun $mdf [list getmergediffline $mdf $id $np] -} - -proc getmergediffline {mdf id np} { - global diffmergeid ctext cflist mergemax - global difffilestart mdifffd treediffs - global ctext_file_names ctext_file_lines - global diffencoding jump_to_here targetline diffline - - $ctext conf -state normal - set nr 0 - while {[incr nr] <= 1000 && [gets $mdf line] >= 0} { - if {![info exists diffmergeid] || $id != $diffmergeid - || $mdf != $mdifffd($id)} { - close $mdf - return 0 - } - if {[regexp {^diff --cc (.*)} $line match fname]} { - # start of a new file - set fname [encoding convertfrom $fname] - $ctext insert end "\n" - set here [$ctext index "end - 1c"] - lappend difffilestart $here - lappend treediffs($id) $fname - add_flist [list $fname] - lappend ctext_file_names $fname - lappend ctext_file_lines [lindex [split $here "."] 0] - set diffencoding [get_path_encoding $fname] - set l [expr {(78 - [string length $fname]) / 2}] - set pad [string range "----------------------------------------" 1 $l] - $ctext insert end "$pad $fname $pad\n" filesep - set targetline {} - if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} { - set targetline [lindex $jump_to_here 1] - } - set diffline 0 - } elseif {[regexp {^@@} $line]} { - set line [encoding convertfrom $diffencoding $line] - $ctext insert end "$line\n" hunksep - if {[regexp { \+(\d+),\d+ @@} $line m nl]} { - set diffline $nl - } - } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} { - # do nothing - } else { - set line [encoding convertfrom $diffencoding $line] - # parse the prefix - one ' ', '-' or '+' for each parent - set spaces {} - set minuses {} - set pluses {} - set isbad 0 - for {set j 0} {$j < $np} {incr j} { - set c [string range $line $j $j] - if {$c == " "} { - lappend spaces $j - } elseif {$c == "-"} { - lappend minuses $j - } elseif {$c == "+"} { - lappend pluses $j - } else { - set isbad 1 - break - } - } - set tags {} - set num {} - if {!$isbad && $minuses ne {} && $pluses eq {}} { - # line doesn't appear in result, parents in $minuses have the line - set num [lindex $minuses 0] - } elseif {!$isbad && $pluses ne {} && $minuses eq {}} { - # line appears in result, parents in $pluses don't have the line - lappend tags mresult - set num [lindex $spaces 0] - } - if {$num ne {}} { - if {$num >= $mergemax} { - set num "max" - } - lappend tags m$num - } - $ctext insert end "$line\n" $tags - if {$targetline ne {} && $minuses eq {}} { - if {$diffline == $targetline} { - set here [$ctext index "end - 1 line"] - mark_ctext_line [lindex [split $here .] 0] - set targetline {} - } else { - incr diffline - } - } - } - } - $ctext conf -state disabled - if {[eof $mdf]} { - close $mdf - return 0 - } - return [expr {$nr >= 1000? 2: 1}] + getblobdiffs $id } proc startdiff {ids} { @@ -6971,9 +6857,9 @@ proc getblobdiffs {ids} { global diffcontext global ignorespace global limitdiffs vfilelimit curview - global diffencoding targetline + global diffencoding targetline diffnparents - set cmd [diffcmd $ids "-p -C --no-commit-id -U$diffcontext"] + set cmd [diffcmd $ids "-p -C --cc --no-commit-id -U$diffcontext"] if {$ignorespace} { append cmd " -w" } @@ -6981,10 +6867,11 @@ proc getblobdiffs {ids} { set cmd [concat $cmd -- $vfilelimit($curview)] } if {[catch {set bdf [open $cmd r]} err]} { - puts "error getting diffs: $err" + error_popup [mc "Error getting diffs: %s" $err] return } set targetline {} + set diffnparents 0 set diffinhdr 0 set diffencoding [get_path_encoding {}] fconfigure $bdf -blocking 0 -encoding binary @@ -7006,9 +6893,11 @@ proc setinlist {var i val} { } proc makediffhdr {fname ids} { - global ctext curdiffstart treediffs + global ctext curdiffstart treediffs diffencoding global ctext_file_names jump_to_here targetline diffline + set fname [encoding convertfrom $fname] + set diffencoding [get_path_encoding $fname] set i [lsearch -exact $treediffs($ids) $fname] if {$i >= 0} { setinlist difffilestart $i $curdiffstart @@ -7028,7 +6917,7 @@ proc getblobdiffline {bdf ids} { global diffids blobdifffd ctext curdiffstart global diffnexthead diffnextnote difffilestart global ctext_file_names ctext_file_lines - global diffinhdr treediffs + global diffinhdr treediffs mergemax diffnparents global diffencoding jump_to_here targetline diffline set nr 0 @@ -7038,47 +6927,63 @@ proc getblobdiffline {bdf ids} { close $bdf return 0 } - if {![string compare -length 11 "diff --git " $line]} { - # trim off "diff --git " - set line [string range $line 11 end] - set diffinhdr 1 + if {![string compare -length 5 "diff " $line]} { + if {![regexp {^diff (--cc|--git) } $line m type]} { + set line [encoding convertfrom $line] + $ctext insert end "$line\n" hunksep + continue + } # start of a new file + set diffinhdr 1 $ctext insert end "\n" set curdiffstart [$ctext index "end - 1c"] lappend ctext_file_names "" lappend ctext_file_lines [lindex [split $curdiffstart "."] 0] $ctext insert end "\n" filesep - # If the name hasn't changed the length will be odd, - # the middle char will be a space, and the two bits either - # side will be a/name and b/name, or "a/name" and "b/name". - # If the name has changed we'll get "rename from" and - # "rename to" or "copy from" and "copy to" lines following this, - # and we'll use them to get the filenames. - # This complexity is necessary because spaces in the filename(s) - # don't get escaped. - set l [string length $line] - set i [expr {$l / 2}] - if {!(($l & 1) && [string index $line $i] eq " " && - [string range $line 2 [expr {$i - 1}]] eq \ - [string range $line [expr {$i + 3}] end])} { - continue - } - # unescape if quoted and chop off the a/ from the front - if {[string index $line 0] eq "\""} { - set fname [string range [lindex $line 0] 2 end] + + if {$type eq "--cc"} { + # start of a new file in a merge diff + set fname [string range $line 10 end] + if {[lsearch -exact $treediffs($ids) $fname] < 0} { + lappend treediffs($ids) $fname + add_flist [list $fname] + } + } else { - set fname [string range $line 2 [expr {$i - 1}]] + set line [string range $line 11 end] + # If the name hasn't changed the length will be odd, + # the middle char will be a space, and the two bits either + # side will be a/name and b/name, or "a/name" and "b/name". + # If the name has changed we'll get "rename from" and + # "rename to" or "copy from" and "copy to" lines following + # this, and we'll use them to get the filenames. + # This complexity is necessary because spaces in the + # filename(s) don't get escaped. + set l [string length $line] + set i [expr {$l / 2}] + if {!(($l & 1) && [string index $line $i] eq " " && + [string range $line 2 [expr {$i - 1}]] eq \ + [string range $line [expr {$i + 3}] end])} { + continue + } + # unescape if quoted and chop off the a/ from the front + if {[string index $line 0] eq "\""} { + set fname [string range [lindex $line 0] 2 end] + } else { + set fname [string range $line 2 [expr {$i - 1}]] + } } - set fname [encoding convertfrom $fname] - set diffencoding [get_path_encoding $fname] makediffhdr $fname $ids - } elseif {[regexp {^@@ -([0-9]+)(,[0-9]+)? \+([0-9]+)(,[0-9]+)? @@(.*)} \ - $line match f1l f1c f2l f2c rest]} { + } elseif {![string compare -length 2 "@@" $line]} { + regexp {^@@+} $line ats set line [encoding convertfrom $diffencoding $line] $ctext insert end "$line\n" hunksep + if {[regexp { \+(\d+),\d+ @@} $line m nl]} { + set diffline $nl + } + set diffnparents [expr {[string length $ats] - 1}] set diffinhdr 0 - set diffline $f2l } elseif {$diffinhdr} { if {![string compare -length 12 "rename from " $line]} { @@ -7097,8 +7002,6 @@ proc getblobdiffline {bdf ids} { if {[string index $fname 0] eq "\""} { set fname [lindex $fname 0] } - set fname [encoding convertfrom $fname] - set diffencoding [get_path_encoding $fname] makediffhdr $fname $ids } elseif {[string compare -length 3 $line "---"] == 0} { # do nothing @@ -7111,28 +7014,53 @@ proc getblobdiffline {bdf ids} { } else { set line [encoding convertfrom $diffencoding $line] - set x [string range $line 0 0] - set here [$ctext index "end - 1 chars"] - if {$x == "-" || $x == "+"} { - set tag [expr {$x == "+"}] - $ctext insert end "$line\n" d$tag - } elseif {$x == " "} { - $ctext insert end "$line\n" + # parse the prefix - one ' ', '-' or '+' for each parent + set prefix [string range $line 0 [expr {$diffnparents - 1}]] + set tag [expr {$diffnparents > 1? "m": "d"}] + if {[string trim $prefix " -+"] eq {}} { + # prefix only has " ", "-" and "+" in it: normal diff line + set num [string first "-" $prefix] + if {$num >= 0} { + # removed line, first parent with line is $num + if {$num >= $mergemax} { + set num "max" + } + $ctext insert end "$line\n" $tag$num + } else { + set tags {} + if {[string first "+" $prefix] >= 0} { + # added line + lappend tags ${tag}result + if {$diffnparents > 1} { + set num [string first " " $prefix] + if {$num >= 0} { + if {$num >= $mergemax} { + set num "max" + } + lappend tags m$num + } + } + } + if {$targetline ne {}} { + if {$diffline == $targetline} { + set seehere [$ctext index "end - 1 chars"] + set targetline {} + } else { + incr diffline + } + } + $ctext insert end "$line\n" $tags + } } else { # "\ No newline at end of file", # or something else we don't recognize $ctext insert end "$line\n" hunksep } - if {$targetline ne {} && ($x eq " " || $x eq "+")} { - if {$diffline == $targetline} { - mark_ctext_line [lindex [split $here .] 0] - set targetline {} - } else { - incr diffline - } - } } } + if {[info exists seehere]} { + mark_ctext_line [lindex [split $seehere .] 0] + } $ctext conf -state disabled if {[eof $bdf]} { close $bdf @@ -7145,7 +7073,7 @@ proc changediffdisp {} { global ctext diffelide $ctext tag conf d0 -elide [lindex $diffelide 0] - $ctext tag conf d1 -elide [lindex $diffelide 1] + $ctext tag conf dresult -elide [lindex $diffelide 1] } proc highlightfile {loc cline} { @@ -9817,7 +9745,7 @@ proc doprefs {} { label $top.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1] button $top.diffnewbut -text [mc "Diff: new lines"] -font optionfont \ -command [list choosecolor diffcolors 1 $top.diffnew "diff new lines" \ - [list $ctext tag conf d1 -foreground]] + [list $ctext tag conf dresult -foreground]] grid x $top.diffnewbut $top.diffnew -sticky w label $top.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2] button $top.hunksepbut -text [mc "Diff: hunk header"] -font optionfont \ From 0e8189e2708bc1da08c77c7e1d960f420b6890a5 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Fri, 31 Oct 2008 11:31:08 -0400 Subject: [PATCH 025/138] close another possibility for propagating pack corruption Abstract -------- With index v2 we have a per object CRC to allow quick and safe reuse of pack data when repacking. This, however, doesn't currently prevent a stealth corruption from being propagated into a new pack when _not_ reusing pack data as demonstrated by the modification to t5302 included here. The Context ----------- The Git database is all checksummed with SHA1 hashes. Any kind of corruption can be confirmed by verifying this per object hash against corresponding data. However this can be costly to perform systematically and therefore this check is often not performed at run time when accessing the object database. First, the loose object format is entirely compressed with zlib which already provide a CRC verification of its own when inflating data. Any disk corruption would be caught already in this case. Then, packed objects are also compressed with zlib but only for their actual payload. The object headers and delta base references are not deflated for obvious performance reasons, however this leave them vulnerable to potentially undetected disk corruptions. Object types are often validated against the expected type when they're requested, and deflated size must always match the size recorded in the object header, so those cases are pretty much covered as well. Where corruptions could go unnoticed is in the delta base reference. Of course, in the OBJ_REF_DELTA case, the odds for a SHA1 reference to get corrupted so it actually matches the SHA1 of another object with the same size (the delta header stores the expected size of the base object to apply against) are virtually zero. In the OBJ_OFS_DELTA case, the reference is a pack offset which would have to match the start boundary of a different base object but still with the same size, and although this is relatively much more "probable" than in the OBJ_REF_DELTA case, the probability is also about zero in absolute terms. Still, the possibility exists as demonstrated in t5302 and is certainly greater than a SHA1 collision, especially in the OBJ_OFS_DELTA case which is now the default when repacking. Again, repacking by reusing existing pack data is OK since the per object CRC provided by index v2 guards against any such corruptions. What t5302 failed to test is a full repack in such case. The Solution ------------ As unlikely as this kind of stealth corruption can be in practice, it certainly isn't acceptable to propagate it into a freshly created pack. But, because this is so unlikely, we don't want to pay the run time cost associated with extra validation checks all the time either. Furthermore, consequences of such corruption in anything but repacking should be rather visible, and even if it could be quite unpleasant, it still has far less severe consequences than actively creating bad packs. So the best compromize is to check packed object CRC when unpacking objects, and only during the compression/writing phase of a repack, and only when not streaming the result. The cost of this is minimal (less than 1% CPU time), and visible only with a full repack. Someone with a stats background could provide an objective evaluation of this, but I suspect that it's bad RAM that has more potential for data corruptions at this point, even in those cases where this extra check is not performed. Still, it is best to prevent a known hole for corruption when recreating object data into a new pack. What about the streamed pack case? Well, any client receiving a pack must always consider that pack as untrusty and perform full validation anyway, hence no such stealth corruption could be propagated to remote repositoryes already. It is therefore worthless doing local validation in that case. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 10 ++++++++++ cache.h | 3 +++ sha1_file.c | 15 +++++++++++++++ t/t5302-pack-index.sh | 3 ++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 15b80db5a1..1591417962 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1698,6 +1698,16 @@ static void prepare_pack(int window, int depth) get_object_details(); + /* + * If we're locally repacking then we need to be doubly careful + * from now on in order to make sure no stealth corruption gets + * propagated to the new pack. Clients receiving streamed packs + * should validate everything they get anyway so no need to incur + * the additional cost here in that case. + */ + if (!pack_to_stdout) + do_check_packed_object_crc = 1; + if (!nr_objects || !window || !depth) return; diff --git a/cache.h b/cache.h index b0edbf9b9f..6b18fab3c1 100644 --- a/cache.h +++ b/cache.h @@ -565,6 +565,9 @@ extern int force_object_loose(const unsigned char *sha1, time_t mtime); /* just like read_sha1_file(), but non fatal in presence of bad objects */ extern void *read_object(const unsigned char *sha1, enum object_type *type, unsigned long *size); +/* global flag to enable extra checks when accessing packed objects */ +extern int do_check_packed_object_crc; + extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type); extern int move_temp_to_file(const char *tmpfile, const char *filename); diff --git a/sha1_file.c b/sha1_file.c index ab2b520f03..88d9cf357f 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1694,6 +1694,8 @@ static void *unpack_delta_entry(struct packed_git *p, return result; } +int do_check_packed_object_crc; + void *unpack_entry(struct packed_git *p, off_t obj_offset, enum object_type *type, unsigned long *sizep) { @@ -1701,6 +1703,19 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset, off_t curpos = obj_offset; void *data; + if (do_check_packed_object_crc && p->index_version > 1) { + struct revindex_entry *revidx = find_pack_revindex(p, obj_offset); + unsigned long len = revidx[1].offset - obj_offset; + if (check_pack_crc(p, &w_curs, obj_offset, len, revidx->nr)) { + const unsigned char *sha1 = + nth_packed_object_sha1(p, revidx->nr); + error("bad packed object CRC for %s", + sha1_to_hex(sha1)); + mark_bad_packed_object(p, sha1); + return NULL; + } + } + *type = unpack_object_header(p, &w_curs, &curpos, sizep); switch (*type) { case OBJ_OFS_DELTA: diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index 344ab25b8b..29896141b9 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -160,7 +160,8 @@ test_expect_success \ test_expect_success \ '[index v2] 5) pack-objects refuses to reuse corrupted data' \ - 'test_must_fail git pack-objects test-5 Date: Wed, 29 Oct 2008 19:02:45 -0400 Subject: [PATCH 026/138] better validation on delta base object offsets In one case, it was possible to have a bad offset equal to 0 effectively pointing a delta onto itself and crashing git after too many recursions. In the other cases, a negative offset could result due to off_t being signed. Catch those. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 4 ++-- builtin-unpack-objects.c | 2 ++ index-pack.c | 2 +- sha1_file.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 1591417962..cc1e47f41a 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1038,10 +1038,10 @@ static void check_object(struct object_entry *entry) c = buf[used_0++]; ofs = (ofs << 7) + (c & 127); } - if (ofs >= entry->in_pack_offset) + ofs = entry->in_pack_offset - ofs; + if (ofs <= 0 || ofs >= entry->in_pack_offset) die("delta base offset out of bound for %s", sha1_to_hex(entry->idx.sha1)); - ofs = entry->in_pack_offset - ofs; if (reuse_delta && !entry->preferred_base) { struct revindex_entry *revidx; revidx = find_pack_revindex(p, ofs); diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c index 9f4bdd3296..47ed610677 100644 --- a/builtin-unpack-objects.c +++ b/builtin-unpack-objects.c @@ -370,6 +370,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size, base_offset = (base_offset << 7) + (c & 127); } base_offset = obj_list[nr].offset - base_offset; + if (base_offset <= 0 || base_offset >= obj_list[nr].offset) + die("offset value out of bound for delta base object"); delta_data = get_data(delta_size); if (dry_run || !delta_data) { diff --git a/index-pack.c b/index-pack.c index 6f89bb9ac7..da03eeeca1 100644 --- a/index-pack.c +++ b/index-pack.c @@ -334,7 +334,7 @@ static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_ base_offset = (base_offset << 7) + (c & 127); } delta_base->offset = obj->idx.offset - base_offset; - if (delta_base->offset >= obj->idx.offset) + if (delta_base->offset <= 0 || delta_base->offset >= obj->idx.offset) bad_object(obj->idx.offset, "delta base offset is out of bound"); break; case OBJ_COMMIT: diff --git a/sha1_file.c b/sha1_file.c index 88d9cf357f..e57949b415 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1355,7 +1355,7 @@ static off_t get_delta_base(struct packed_git *p, base_offset = (base_offset << 7) + (c & 127); } base_offset = delta_obj_offset - base_offset; - if (base_offset >= delta_obj_offset) + if (base_offset <= 0 || base_offset >= delta_obj_offset) return 0; /* out of bound */ *curpos += used; } else if (type == OBJ_REF_DELTA) { From 09ded04b7e1f0096bb2fe356b2f5a298296151dd Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 29 Oct 2008 19:02:46 -0400 Subject: [PATCH 027/138] make unpack_object_header() non fatal It is possible to have pack corruption in the object header. Currently unpack_object_header() simply die() on them instead of letting the caller deal with that gracefully. So let's have unpack_object_header() return an error instead, and find a better name for unpack_object_header_gently() in that context. All callers of unpack_object_header() are ready for it. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 2 +- cache.h | 2 +- sha1_file.c | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index cc1e47f41a..64aefdf23b 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1002,7 +1002,7 @@ static void check_object(struct object_entry *entry) * We want in_pack_type even if we do not reuse delta * since non-delta representations could still be reused. */ - used = unpack_object_header_gently(buf, avail, + used = unpack_object_header_buffer(buf, avail, &entry->in_pack_type, &entry->size); diff --git a/cache.h b/cache.h index 6b18fab3c1..c440598e27 100644 --- a/cache.h +++ b/cache.h @@ -754,7 +754,7 @@ extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t); extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *); extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *); -extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); +extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *); extern int matches_pack_name(struct packed_git *p, const char *name); diff --git a/sha1_file.c b/sha1_file.c index e57949b415..7698177488 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1110,7 +1110,8 @@ static int legacy_loose_object(unsigned char *map) return 0; } -unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep) +unsigned long unpack_object_header_buffer(const unsigned char *buf, + unsigned long len, enum object_type *type, unsigned long *sizep) { unsigned shift; unsigned char c; @@ -1122,10 +1123,10 @@ unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned lon size = c & 15; shift = 4; while (c & 0x80) { - if (len <= used) - return 0; - if (sizeof(long) * 8 <= shift) + if (len <= used || sizeof(long) * 8 <= shift) { + error("bad object header"); return 0; + } c = buf[used++]; size += (c & 0x7f) << shift; shift += 7; @@ -1164,7 +1165,7 @@ static int unpack_sha1_header(z_stream *stream, unsigned char *map, unsigned lon * really worth it and we don't write it any longer. But we * can still read it. */ - used = unpack_object_header_gently(map, mapsize, &type, &size); + used = unpack_object_header_buffer(map, mapsize, &type, &size); if (!used || !valid_loose_object_type[type]) return -1; map += used; @@ -1411,10 +1412,11 @@ static int unpack_object_header(struct packed_git *p, * insane, so we know won't exceed what we have been given. */ base = use_pack(p, w_curs, *curpos, &left); - used = unpack_object_header_gently(base, left, &type, sizep); - if (!used) - die("object offset outside of pack file"); - *curpos += used; + used = unpack_object_header_buffer(base, left, &type, sizep); + if (!used) { + type = OBJ_BAD; + } else + *curpos += used; return type; } From 3d77d8774fc18216f18efa5c5907f73b22d61604 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 29 Oct 2008 19:02:47 -0400 Subject: [PATCH 028/138] make packed_object_info() resilient to pack corruptions In the same spirit as commit 8eca0b47ff, let's try to survive a pack corruption by making packed_object_info() able to fall back to alternate packs or loose objects. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- sha1_file.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 7698177488..384a43044e 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1314,8 +1314,10 @@ unsigned long get_size_from_delta(struct packed_git *p, } while ((st == Z_OK || st == Z_BUF_ERROR) && stream.total_out < sizeof(delta_head)); inflateEnd(&stream); - if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) - die("delta data unpack-initial failed"); + if ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head)) { + error("delta data unpack-initial failed"); + return 0; + } /* Examine the initial part of the delta to figure out * the result size. @@ -1382,15 +1384,29 @@ static int packed_delta_info(struct packed_git *p, off_t base_offset; base_offset = get_delta_base(p, w_curs, &curpos, type, obj_offset); + if (!base_offset) + return OBJ_BAD; type = packed_object_info(p, base_offset, NULL); + if (type <= OBJ_NONE) { + struct revindex_entry *revidx = find_pack_revindex(p, base_offset); + const unsigned char *base_sha1 = + nth_packed_object_sha1(p, revidx->nr); + mark_bad_packed_object(p, base_sha1); + type = sha1_object_info(base_sha1, NULL); + if (type <= OBJ_NONE) + return OBJ_BAD; + } /* We choose to only get the type of the base object and * ignore potentially corrupt pack file that expects the delta * based on a base with a wrong size. This saves tons of * inflate() calls. */ - if (sizep) + if (sizep) { *sizep = get_size_from_delta(p, w_curs, curpos); + if (*sizep == 0) + type = OBJ_BAD; + } return type; } @@ -1500,8 +1516,9 @@ static int packed_object_info(struct packed_git *p, off_t obj_offset, *sizep = size; break; default: - die("pack %s contains unknown object type %d", - p->pack_name, type); + error("unknown object type %i at offset %"PRIuMAX" in %s", + type, (uintmax_t)obj_offset, p->pack_name); + type = OBJ_BAD; } unuse_pack(&w_curs); return type; @@ -1971,7 +1988,14 @@ int sha1_object_info(const unsigned char *sha1, unsigned long *sizep) if (!find_pack_entry(sha1, &e, NULL)) return status; } - return packed_object_info(e.p, e.offset, sizep); + + status = packed_object_info(e.p, e.offset, sizep); + if (status < 0) { + mark_bad_packed_object(e.p, sha1); + status = sha1_object_info(sha1, sizep); + } + + return status; } static void *read_packed_sha1(const unsigned char *sha1, From 03d660150cbc80cd7d2ec90c3c4e6ce563295e3a Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 29 Oct 2008 19:02:48 -0400 Subject: [PATCH 029/138] make check_object() resilient to pack corruptions The check_object() function tries to get away with the least amount of pack access possible when it already has partial information on given object rather than calling the more costly packed_object_info(). When things don't look right, it should just give up and fall back to packed_object_info() directly instead of die()'ing. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 64aefdf23b..c05fb944b0 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1005,6 +1005,8 @@ static void check_object(struct object_entry *entry) used = unpack_object_header_buffer(buf, avail, &entry->in_pack_type, &entry->size); + if (used == 0) + goto give_up; /* * Determine if this is a delta and if so whether we can @@ -1016,6 +1018,8 @@ static void check_object(struct object_entry *entry) /* Not a delta hence we've already got all we need. */ entry->type = entry->in_pack_type; entry->in_pack_header_size = used; + if (entry->type < OBJ_COMMIT || entry->type > OBJ_BLOB) + goto give_up; unuse_pack(&w_curs); return; case OBJ_REF_DELTA: @@ -1032,16 +1036,20 @@ static void check_object(struct object_entry *entry) ofs = c & 127; while (c & 128) { ofs += 1; - if (!ofs || MSB(ofs, 7)) - die("delta base offset overflow in pack for %s", - sha1_to_hex(entry->idx.sha1)); + if (!ofs || MSB(ofs, 7)) { + error("delta base offset overflow in pack for %s", + sha1_to_hex(entry->idx.sha1)); + goto give_up; + } c = buf[used_0++]; ofs = (ofs << 7) + (c & 127); } ofs = entry->in_pack_offset - ofs; - if (ofs <= 0 || ofs >= entry->in_pack_offset) - die("delta base offset out of bound for %s", - sha1_to_hex(entry->idx.sha1)); + if (ofs <= 0 || ofs >= entry->in_pack_offset) { + error("delta base offset out of bound for %s", + sha1_to_hex(entry->idx.sha1)); + goto give_up; + } if (reuse_delta && !entry->preferred_base) { struct revindex_entry *revidx; revidx = find_pack_revindex(p, ofs); @@ -1078,6 +1086,8 @@ static void check_object(struct object_entry *entry) */ entry->size = get_size_from_delta(p, &w_curs, entry->in_pack_offset + entry->in_pack_header_size); + if (entry->size == 0) + goto give_up; unuse_pack(&w_curs); return; } @@ -1087,6 +1097,7 @@ static void check_object(struct object_entry *entry) * with sha1_object_info() to find about the object type * at this point... */ + give_up: unuse_pack(&w_curs); } From 08698b1e32bc414f214b7300b40c30a30d9ecd1c Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 29 Oct 2008 19:02:49 -0400 Subject: [PATCH 030/138] make find_pack_revindex() aware of the nasty world It currently calls die() whenever given offset is not found thinking that such thing should never happen. But this offset may come from a corrupted pack whych _could_ happen and not be found. Callers should deal with this possibility gracefully instead. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 2 ++ pack-revindex.c | 3 ++- sha1_file.c | 18 ++++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index c05fb944b0..04a5a55ef9 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1053,6 +1053,8 @@ static void check_object(struct object_entry *entry) if (reuse_delta && !entry->preferred_base) { struct revindex_entry *revidx; revidx = find_pack_revindex(p, ofs); + if (!revidx) + goto give_up; base_ref = nth_packed_object_sha1(p, revidx->nr); } entry->in_pack_header_size = used + used_0; diff --git a/pack-revindex.c b/pack-revindex.c index 6096b6224a..1de53c8934 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -140,7 +140,8 @@ struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs) else lo = mi + 1; } while (lo < hi); - die("internal error: pack revindex corrupt"); + error("bad offset for revindex"); + return NULL; } void discard_revindex(void) diff --git a/sha1_file.c b/sha1_file.c index 384a43044e..9ce1df0cff 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1388,9 +1388,12 @@ static int packed_delta_info(struct packed_git *p, return OBJ_BAD; type = packed_object_info(p, base_offset, NULL); if (type <= OBJ_NONE) { - struct revindex_entry *revidx = find_pack_revindex(p, base_offset); - const unsigned char *base_sha1 = - nth_packed_object_sha1(p, revidx->nr); + struct revindex_entry *revidx; + const unsigned char *base_sha1; + revidx = find_pack_revindex(p, base_offset); + if (!revidx) + return OBJ_BAD; + base_sha1 = nth_packed_object_sha1(p, revidx->nr); mark_bad_packed_object(p, base_sha1); type = sha1_object_info(base_sha1, NULL); if (type <= OBJ_NONE) @@ -1682,9 +1685,12 @@ static void *unpack_delta_entry(struct packed_git *p, * This is costly but should happen only in the presence * of a corrupted pack, and is better than failing outright. */ - struct revindex_entry *revidx = find_pack_revindex(p, base_offset); - const unsigned char *base_sha1 = - nth_packed_object_sha1(p, revidx->nr); + struct revindex_entry *revidx; + const unsigned char *base_sha1; + revidx = find_pack_revindex(p, base_offset); + if (!revidx) + return NULL; + base_sha1 = nth_packed_object_sha1(p, revidx->nr); error("failed to read delta base object %s" " at offset %"PRIuMAX" from %s", sha1_to_hex(base_sha1), (uintmax_t)base_offset, From 64bd76b1de75483dea646c39c390113ffc821299 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 29 Oct 2008 19:02:50 -0400 Subject: [PATCH 031/138] pack-objects: allow "fixing" a corrupted pack without a full repack When the pack data to be reused is found to be bad, let's fall back to full object access through the generic path which has its own strategies to find alternate object sources in that case. This allows for "fixing" a corrupted pack simply by copying either another pack containing the object(s) found to be bad, or the loose object itself, into the object store and launch a repack without the need for -f. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 04a5a55ef9..5be6664c72 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -277,6 +277,7 @@ static unsigned long write_object(struct sha1file *f, */ if (!to_reuse) { + no_reuse: if (!usable_delta) { buf = read_sha1_file(entry->idx.sha1, &type, &size); if (!buf) @@ -358,20 +359,30 @@ static unsigned long write_object(struct sha1file *f, struct revindex_entry *revidx; off_t offset; - if (entry->delta) { + if (entry->delta) type = (allow_ofs_delta && entry->delta->idx.offset) ? OBJ_OFS_DELTA : OBJ_REF_DELTA; - reused_delta++; - } hdrlen = encode_header(type, entry->size, header); + offset = entry->in_pack_offset; revidx = find_pack_revindex(p, offset); datalen = revidx[1].offset - offset; if (!pack_to_stdout && p->index_version > 1 && - check_pack_crc(p, &w_curs, offset, datalen, revidx->nr)) - die("bad packed object CRC for %s", sha1_to_hex(entry->idx.sha1)); + check_pack_crc(p, &w_curs, offset, datalen, revidx->nr)) { + error("bad packed object CRC for %s", sha1_to_hex(entry->idx.sha1)); + unuse_pack(&w_curs); + goto no_reuse; + } + offset += entry->in_pack_header_size; datalen -= entry->in_pack_header_size; + if (!pack_to_stdout && p->index_version == 1 && + check_pack_inflate(p, &w_curs, offset, datalen, entry->size)) { + error("corrupt packed object for %s", sha1_to_hex(entry->idx.sha1)); + unuse_pack(&w_curs); + goto no_reuse; + } + if (type == OBJ_OFS_DELTA) { off_t ofs = entry->idx.offset - entry->delta->idx.offset; unsigned pos = sizeof(dheader) - 1; @@ -383,21 +394,19 @@ static unsigned long write_object(struct sha1file *f, sha1write(f, header, hdrlen); sha1write(f, dheader + pos, sizeof(dheader) - pos); hdrlen += sizeof(dheader) - pos; + reused_delta++; } else if (type == OBJ_REF_DELTA) { if (limit && hdrlen + 20 + datalen + 20 >= limit) return 0; sha1write(f, header, hdrlen); sha1write(f, entry->delta->idx.sha1, 20); hdrlen += 20; + reused_delta++; } else { if (limit && hdrlen + datalen + 20 >= limit) return 0; sha1write(f, header, hdrlen); } - - if (!pack_to_stdout && p->index_version == 1 && - check_pack_inflate(p, &w_curs, offset, datalen, entry->size)) - die("corrupt packed object for %s", sha1_to_hex(entry->idx.sha1)); copy_pack_data(f, p, &w_curs, offset, datalen); unuse_pack(&w_curs); reused++; @@ -1074,6 +1083,7 @@ static void check_object(struct object_entry *entry) */ entry->type = entry->in_pack_type; entry->delta = base_entry; + entry->delta_size = entry->size; entry->delta_sibling = base_entry->delta_child; base_entry->delta_child = entry; unuse_pack(&w_curs); From 538cf6b6e5f663eea9b777ef12ae58eb0c919480 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 29 Oct 2008 19:02:51 -0400 Subject: [PATCH 032/138] extend test coverage for latest pack corruption resilience improvements Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- t/t5303-pack-corruption-resilience.sh | 96 +++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 7 deletions(-) diff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh index 31b20b21d2..ac181ea38a 100755 --- a/t/t5303-pack-corruption-resilience.sh +++ b/t/t5303-pack-corruption-resilience.sh @@ -41,11 +41,17 @@ create_new_pack() { git verify-pack -v ${pack}.pack } +do_repack() { + pack=`printf "$blob_1\n$blob_2\n$blob_3\n" | + git pack-objects $@ .git/objects/pack/pack` && + pack=".git/objects/pack/pack-${pack}" +} + do_corrupt_object() { ofs=`git show-index < ${pack}.idx | grep $1 | cut -f1 -d" "` && ofs=$(($ofs + $2)) && chmod +w ${pack}.pack && - dd if=/dev/zero of=${pack}.pack count=1 bs=1 conv=notrunc seek=$ofs && + dd of=${pack}.pack count=1 bs=1 conv=notrunc seek=$ofs && test_must_fail git verify-pack ${pack}.pack } @@ -60,7 +66,7 @@ test_expect_success \ test_expect_success \ 'create corruption in header of first object' \ - 'do_corrupt_object $blob_1 0 && + 'do_corrupt_object $blob_1 0 < /dev/zero && test_must_fail git cat-file blob $blob_1 > /dev/null && test_must_fail git cat-file blob $blob_2 > /dev/null && test_must_fail git cat-file blob $blob_3 > /dev/null' @@ -119,7 +125,7 @@ test_expect_success \ 'create corruption in header of first delta' \ 'create_new_pack && git prune-packed && - do_corrupt_object $blob_2 0 && + do_corrupt_object $blob_2 0 < /dev/zero && git cat-file blob $blob_1 > /dev/null && test_must_fail git cat-file blob $blob_2 > /dev/null && test_must_fail git cat-file blob $blob_3 > /dev/null' @@ -133,6 +139,15 @@ test_expect_success \ git cat-file blob $blob_2 > /dev/null && git cat-file blob $blob_3 > /dev/null' +test_expect_success \ + '... and then a repack "clears" the corruption' \ + 'do_repack && + git prune-packed && + git verify-pack ${pack}.pack && + git cat-file blob $blob_1 > /dev/null && + git cat-file blob $blob_2 > /dev/null && + git cat-file blob $blob_3 > /dev/null' + test_expect_success \ 'create corruption in data of first delta' \ 'create_new_pack && @@ -152,11 +167,20 @@ test_expect_success \ git cat-file blob $blob_2 > /dev/null && git cat-file blob $blob_3 > /dev/null' +test_expect_success \ + '... and then a repack "clears" the corruption' \ + 'do_repack && + git prune-packed && + git verify-pack ${pack}.pack && + git cat-file blob $blob_1 > /dev/null && + git cat-file blob $blob_2 > /dev/null && + git cat-file blob $blob_3 > /dev/null' + test_expect_success \ 'corruption in delta base reference of first delta (OBJ_REF_DELTA)' \ 'create_new_pack && git prune-packed && - do_corrupt_object $blob_2 2 && + do_corrupt_object $blob_2 2 < /dev/zero && git cat-file blob $blob_1 > /dev/null && test_must_fail git cat-file blob $blob_2 > /dev/null && test_must_fail git cat-file blob $blob_3 > /dev/null' @@ -171,17 +195,75 @@ test_expect_success \ git cat-file blob $blob_3 > /dev/null' test_expect_success \ - 'corruption in delta base reference of first delta (OBJ_OFS_DELTA)' \ + '... and then a repack "clears" the corruption' \ + 'do_repack && + git prune-packed && + git verify-pack ${pack}.pack && + git cat-file blob $blob_1 > /dev/null && + git cat-file blob $blob_2 > /dev/null && + git cat-file blob $blob_3 > /dev/null' + +test_expect_success \ + 'corruption #0 in delta base reference of first delta (OBJ_OFS_DELTA)' \ 'create_new_pack --delta-base-offset && git prune-packed && - do_corrupt_object $blob_2 2 && + do_corrupt_object $blob_2 2 < /dev/zero && git cat-file blob $blob_1 > /dev/null && test_must_fail git cat-file blob $blob_2 > /dev/null && test_must_fail git cat-file blob $blob_3 > /dev/null' test_expect_success \ - '... and a redundant pack allows for full recovery too' \ + '... but having a loose copy allows for full recovery' \ 'mv ${pack}.idx tmp && + git hash-object -t blob -w file_2 && + mv tmp ${pack}.idx && + git cat-file blob $blob_1 > /dev/null && + git cat-file blob $blob_2 > /dev/null && + git cat-file blob $blob_3 > /dev/null' + +test_expect_success \ + '... and then a repack "clears" the corruption' \ + 'do_repack --delta-base-offset && + git prune-packed && + git verify-pack ${pack}.pack && + git cat-file blob $blob_1 > /dev/null && + git cat-file blob $blob_2 > /dev/null && + git cat-file blob $blob_3 > /dev/null' + +test_expect_success \ + 'corruption #1 in delta base reference of first delta (OBJ_OFS_DELTA)' \ + 'create_new_pack --delta-base-offset && + git prune-packed && + printf "\x01" | do_corrupt_object $blob_2 2 && + git cat-file blob $blob_1 > /dev/null && + test_must_fail git cat-file blob $blob_2 > /dev/null && + test_must_fail git cat-file blob $blob_3 > /dev/null' + +test_expect_success \ + '... but having a loose copy allows for full recovery' \ + 'mv ${pack}.idx tmp && + git hash-object -t blob -w file_2 && + mv tmp ${pack}.idx && + git cat-file blob $blob_1 > /dev/null && + git cat-file blob $blob_2 > /dev/null && + git cat-file blob $blob_3 > /dev/null' + +test_expect_success \ + '... and then a repack "clears" the corruption' \ + 'do_repack --delta-base-offset && + git prune-packed && + git verify-pack ${pack}.pack && + git cat-file blob $blob_1 > /dev/null && + git cat-file blob $blob_2 > /dev/null && + git cat-file blob $blob_3 > /dev/null' + +test_expect_success \ + '... and a redundant pack allows for full recovery too' \ + 'do_corrupt_object $blob_2 2 < /dev/zero && + git cat-file blob $blob_1 > /dev/null && + test_must_fail git cat-file blob $blob_2 > /dev/null && + test_must_fail git cat-file blob $blob_3 > /dev/null && + mv ${pack}.idx tmp && git hash-object -t blob -w file_1 && git hash-object -t blob -w file_2 && printf "$blob_1\n$blob_2\n" | git pack-objects .git/objects/pack/pack && From 59dd9ed18398d96922e345f7987f1245870fb3e5 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 29 Oct 2008 19:02:52 -0400 Subject: [PATCH 033/138] pack-objects: don't leak pack window reference when splitting packs Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 5be6664c72..1b6eff314e 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -389,22 +389,28 @@ static unsigned long write_object(struct sha1file *f, dheader[pos] = ofs & 127; while (ofs >>= 7) dheader[--pos] = 128 | (--ofs & 127); - if (limit && hdrlen + sizeof(dheader) - pos + datalen + 20 >= limit) + if (limit && hdrlen + sizeof(dheader) - pos + datalen + 20 >= limit) { + unuse_pack(&w_curs); return 0; + } sha1write(f, header, hdrlen); sha1write(f, dheader + pos, sizeof(dheader) - pos); hdrlen += sizeof(dheader) - pos; reused_delta++; } else if (type == OBJ_REF_DELTA) { - if (limit && hdrlen + 20 + datalen + 20 >= limit) + if (limit && hdrlen + 20 + datalen + 20 >= limit) { + unuse_pack(&w_curs); return 0; + } sha1write(f, header, hdrlen); sha1write(f, entry->delta->idx.sha1, 20); hdrlen += 20; reused_delta++; } else { - if (limit && hdrlen + datalen + 20 >= limit) + if (limit && hdrlen + datalen + 20 >= limit) { + unuse_pack(&w_curs); return 0; + } sha1write(f, header, hdrlen); } copy_pack_data(f, p, &w_curs, offset, datalen); From 5e166843f502536df7e940486721057acf37ec23 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 2 Nov 2008 10:21:37 +0100 Subject: [PATCH 034/138] gitweb: make the supported snapshot formats array global The array of supported snapshot format is used and defined (with two different names) in two routines, one of which (format_snapshot_links) is often called multiple times per page. Simplify code and speed up page generation by making the array global. Signed-off-by: Giuseppe Bilotta Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 63c793ec39..b4cd2620ff 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -721,6 +721,10 @@ if (defined $searchtext) { our $git_dir; $git_dir = "$projectroot/$project" if $project; +# list of supported snapshot formats +our @snapshot_fmts = gitweb_check_feature('snapshot'); +@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); + # dispatch if (!defined $action) { if (defined $hash) { @@ -1647,8 +1651,6 @@ sub format_diff_line { # linked. Pass the hash of the tree/commit to snapshot. sub format_snapshot_links { my ($hash) = @_; - my @snapshot_fmts = gitweb_check_feature('snapshot'); - @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); my $num_fmts = @snapshot_fmts; if ($num_fmts > 1) { # A parenthesized list of links bearing format names. @@ -4846,20 +4848,17 @@ sub git_tree { } sub git_snapshot { - my @supported_fmts = gitweb_check_feature('snapshot'); - @supported_fmts = filter_snapshot_fmts(@supported_fmts); - my $format = $input_params{'snapshot_format'}; - if (!@supported_fmts) { + if (!@snapshot_fmts) { die_error(403, "Snapshots not allowed"); } # default to first supported snapshot format - $format ||= $supported_fmts[0]; + $format ||= $snapshot_fmts[0]; if ($format !~ m/^[a-z0-9]+$/) { die_error(400, "Invalid snapshot format parameter"); } elsif (!exists($known_snapshot_formats{$format})) { die_error(400, "Unknown snapshot format"); - } elsif (!grep($_ eq $format, @supported_fmts)) { + } elsif (!grep($_ eq $format, @snapshot_fmts)) { die_error(403, "Unsupported snapshot format"); } From 1689c5de8730ea334535337a341db3c7a21ad002 Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Sun, 26 Oct 2008 03:52:19 -0800 Subject: [PATCH 035/138] autoconf: Add link tests to each AC_CHECK_FUNC() test Update configure.ac to test libraries for getaddrinfo, strcasestr, memmem, strlcpy, strtoumax, setenv, unsetenv, and mkdtemp. The default compilers on FreeBSD 4.9-SECURITY and FreeBSD 6.2-RELEASE-p4 do not generate warnings for missing prototypes unless `-Wall' is used. This behavior renders the results of AC_CHECK_FUNC() void on these platforms. The test AC_SEARCH_LIBS() verifies a function is valid by linking to symbol within the system libraries. Since this pattern needs to be repeated for many functions that are checked with AC_CHECK_FUNC(), we add GIT_CHECK_FUNC() to drive the two autoconf macros together. Signed-off-by: David M. Syzdek Signed-off-by: Junio C Hamano --- configure.ac | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 27bab00a45..ef544e8778 100644 --- a/configure.ac +++ b/configure.ac @@ -65,7 +65,17 @@ else \ fi \ ])# GIT_PARSE_WITH - +dnl +dnl GIT_CHECK_FUNC(FUNCTION, IFTRUE, IFFALSE) +dnl ----------------------------------------- +dnl Similar to AC_CHECK_FUNC, but on systems that do not generate +dnl warnings for missing prototypes (e.g. FreeBSD when compiling without +dnl -Wall), it does not work. By looking for function definition in +dnl libraries, this problem can be worked around. +AC_DEFUN([GIT_CHECK_FUNC],[AC_CHECK_FUNC([$1],[ + AC_SEARCH_LIBS([$1],, + [$2],[$3]) +],[$3])]) ## Site configuration related to programs (before tests) ## --with-PACKAGE[=ARG] and --without-PACKAGE # @@ -325,7 +335,7 @@ AC_SUBST(NO_SOCKADDR_STORAGE) # # Define NO_IPV6 if you lack IPv6 support and getaddrinfo(). AC_CHECK_TYPE([struct addrinfo],[ - AC_CHECK_FUNC([getaddrinfo], + GIT_CHECK_FUNC([getaddrinfo], [NO_IPV6=], [NO_IPV6=YesPlease]) ],[NO_IPV6=YesPlease],[ @@ -419,43 +429,43 @@ AC_SUBST(SNPRINTF_RETURNS_BOGUS) AC_MSG_NOTICE([CHECKS for library functions]) # # Define NO_STRCASESTR if you don't have strcasestr. -AC_CHECK_FUNC(strcasestr, +GIT_CHECK_FUNC(strcasestr, [NO_STRCASESTR=], [NO_STRCASESTR=YesPlease]) AC_SUBST(NO_STRCASESTR) # # Define NO_MEMMEM if you don't have memmem. -AC_CHECK_FUNC(memmem, +GIT_CHECK_FUNC(memmem, [NO_MEMMEM=], [NO_MEMMEM=YesPlease]) AC_SUBST(NO_MEMMEM) # # Define NO_STRLCPY if you don't have strlcpy. -AC_CHECK_FUNC(strlcpy, +GIT_CHECK_FUNC(strlcpy, [NO_STRLCPY=], [NO_STRLCPY=YesPlease]) AC_SUBST(NO_STRLCPY) # # Define NO_STRTOUMAX if you don't have strtoumax in the C library. -AC_CHECK_FUNC(strtoumax, +GIT_CHECK_FUNC(strtoumax, [NO_STRTOUMAX=], [NO_STRTOUMAX=YesPlease]) AC_SUBST(NO_STRTOUMAX) # # Define NO_SETENV if you don't have setenv in the C library. -AC_CHECK_FUNC(setenv, +GIT_CHECK_FUNC(setenv, [NO_SETENV=], [NO_SETENV=YesPlease]) AC_SUBST(NO_SETENV) # # Define NO_UNSETENV if you don't have unsetenv in the C library. -AC_CHECK_FUNC(unsetenv, +GIT_CHECK_FUNC(unsetenv, [NO_UNSETENV=], [NO_UNSETENV=YesPlease]) AC_SUBST(NO_UNSETENV) # # Define NO_MKDTEMP if you don't have mkdtemp in the C library. -AC_CHECK_FUNC(mkdtemp, +GIT_CHECK_FUNC(mkdtemp, [NO_MKDTEMP=], [NO_MKDTEMP=YesPlease]) AC_SUBST(NO_MKDTEMP) From 158629b2c9baffd0352306bd8dfa0784c981955d Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Sun, 2 Nov 2008 14:43:20 -0900 Subject: [PATCH 036/138] Make Pthread link flags configurable FreeBSD 4.x systems use the linker flags `-pthread' instead of the linker flags `-lpthread' when linking against the pthread library. Signed-off-by: David M. Syzdek Signed-off-by: Junio C Hamano --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 426e1a652f..02f68e05f5 100644 --- a/Makefile +++ b/Makefile @@ -229,6 +229,7 @@ INSTALL = install RPMBUILD = rpmbuild TCL_PATH = tclsh TCLTK_PATH = wish +PTHREAD_LIBS = -lpthread export TCL_PATH TCLTK_PATH @@ -695,6 +696,7 @@ ifeq ($(uname_S),FreeBSD) COMPAT_CFLAGS += -Icompat/regex COMPAT_OBJS += compat/regex/regex.o ifeq ($(shell expr "$(uname_R)" : '4\.'),2) + PTHREAD_LIBS = -pthread NO_UINTMAX_T = YesPlease NO_STRTOUMAX = YesPlease endif @@ -1023,7 +1025,7 @@ endif ifdef THREADED_DELTA_SEARCH BASIC_CFLAGS += -DTHREADED_DELTA_SEARCH - EXTLIBS += -lpthread + EXTLIBS += $(PTHREAD_LIBS) LIB_OBJS += thread-utils.o endif ifdef DIR_HAS_BSD_GROUP_SEMANTICS From 1ec2fb5fa37d823d02517263f8e2a78930abd1dd Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 2 Nov 2008 10:21:38 +0100 Subject: [PATCH 037/138] gitweb: retrieve snapshot format from PATH_INFO We parse requests for $project/snapshot/$head.$sfx as equivalent to $project/snapshot/$head?sf=$sfx, where $sfx is any of the known (although not necessarily supported) snapshot formats (or its default suffix). The filename for the resulting package preserves the requested extensions (so asking for a .tgz gives a .tgz, and asking for a .tar.gz gives a .tar.gz), although for obvious reasons it doesn't preserve the basename (git/snapshot/next.tgz returns a file names git-next.tgz). This introduces a potential case for ambiguity if a project has a head that ends with a snapshot-like suffix (.zip, .tgz, .tar.gz, etc) and the sf CGI parameter is not present; however, gitweb only produces URLs with the sf parameter currently, so this is only a potential issue for hand-coded URLs for extremely unusual project. Signed-off-by: Giuseppe Bilotta Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index b4cd2620ff..a7f35ccc87 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -616,6 +616,45 @@ sub evaluate_path_info { $input_params{'hash_parent'} ||= $parentrefname; } } + + # for the snapshot action, we allow URLs in the form + # $project/snapshot/$hash.ext + # where .ext determines the snapshot and gets removed from the + # passed $refname to provide the $hash. + # + # To be able to tell that $refname includes the format extension, we + # require the following two conditions to be satisfied: + # - the hash input parameter MUST have been set from the $refname part + # of the URL (i.e. they must be equal) + # - the snapshot format MUST NOT have been defined already (e.g. from + # CGI parameter sf) + # It's also useless to try any matching unless $refname has a dot, + # so we check for that too + if (defined $input_params{'action'} && + $input_params{'action'} eq 'snapshot' && + defined $refname && index($refname, '.') != -1 && + $refname eq $input_params{'hash'} && + !defined $input_params{'snapshot_format'}) { + # We loop over the known snapshot formats, checking for + # extensions. Allowed extensions are both the defined suffix + # (which includes the initial dot already) and the snapshot + # format key itself, with a prepended dot + while (my ($fmt, %opt) = each %known_snapshot_formats) { + my $hash = $refname; + my $sfx; + $hash =~ s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//; + next unless $sfx = $1; + # a valid suffix was found, so set the snapshot format + # and reset the hash parameter + $input_params{'snapshot_format'} = $fmt; + $input_params{'hash'} = $hash; + # we also set the format suffix to the one requested + # in the URL: this way a request for e.g. .tgz returns + # a .tgz instead of a .tar.gz + $known_snapshot_formats{$fmt}{'suffix'} = $sfx; + last; + } + } } evaluate_path_info(); From c752a0e00c7f122dbca72552b1bf193e5850a1b1 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 2 Nov 2008 10:21:39 +0100 Subject: [PATCH 038/138] gitweb: embed snapshot format parameter in PATH_INFO When PATH_INFO is active, get rid of the sf CGI parameter by embedding the snapshot format information in the PATH_INFO URL, in the form of an appropriate extension. Signed-off-by: Giuseppe Bilotta Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index a7f35ccc87..e2ed1ccab3 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -811,6 +811,7 @@ sub href (%) { # - action # - hash_parent or hash_parent_base:/file_parent # - hash or hash_base:/filename + # - the snapshot_format as an appropriate suffix # When the script is the root DirectoryIndex for the domain, # $href here would be something like http://gitweb.example.com/ @@ -822,6 +823,10 @@ sub href (%) { $href .= "/".esc_url($params{'project'}) if defined $params{'project'}; delete $params{'project'}; + # since we destructively absorb parameters, we keep this + # boolean that remembers if we're handling a snapshot + my $is_snapshot = $params{'action'} eq 'snapshot'; + # Summary just uses the project path URL, any other action is # added to the URL if (defined $params{'action'}) { @@ -861,6 +866,18 @@ sub href (%) { $href .= esc_url($params{'hash'}); delete $params{'hash'}; } + + # If the action was a snapshot, we can absorb the + # snapshot_format parameter too + if ($is_snapshot) { + my $fmt = $params{'snapshot_format'}; + # snapshot_format should always be defined when href() + # is called, but just in case some code forgets, we + # fall back to the default + $fmt ||= $snapshot_fmts[0]; + $href .= $known_snapshot_formats{$fmt}{'suffix'}; + delete $params{'snapshot_format'}; + } } # now encode the parameters explicitly From fc4977e1b989503c6dcfbc527cda2458d63d0400 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Tue, 4 Nov 2008 12:57:44 +1100 Subject: [PATCH 039/138] gitk: Make "show origin of this line" work on fake commits This makes the "Show origin of this line" menu item work correctly on the fake commits that gitk shows for local uncommitted changes. With the fake commit for changes that aren't checked in to the index, we can actually get a 3-way diff shown, which means we might have to blame either the parent or the commit being merged in (which we get from .git/MERGE_HEAD). If the parent is the fake commit which shows the changes that have been checked in to the index, then we need to get the SHA1 of the blob for the version of the file that is in the index, then use git cat-file blob to get the contents of the blob, and give that to git blame with --contents - so that git blame will do the blame on the index version of the file. In that case, we might get the all-zeroes SHA1 back from git blame, meaning that the line is new in the index version of the file, so then we have to use $nullid2 (the pseudo-SHA1 of the fake commit for the checked-in changes). Signed-off-by: Paul Mackerras --- gitk | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/gitk b/gitk index e6e49fc5cc..f386981cc9 100755 --- a/gitk +++ b/gitk @@ -3238,6 +3238,22 @@ proc external_blame_diff {} { external_blame $parent_idx $line } +# Find the SHA1 ID of the blob for file $fname in the index +# at stage 0 or 2 +proc index_sha1 {fname} { + set f [open [list | git ls-files -s $fname] r] + while {[gets $f line] >= 0} { + set info [lindex [split $line "\t"] 0] + set stage [lindex $info 2] + if {$stage eq "0" || $stage eq "2"} { + close $f + return [lindex $info 1] + } + } + close $f + return {} +} + proc external_blame {parent_idx {line {}}} { global flist_menu_file global nullid nullid2 @@ -3267,7 +3283,9 @@ proc external_blame {parent_idx {line {}}} { proc show_line_source {} { global cmitmode currentid parents curview blamestuff blameinst global diff_menu_line diff_menu_filebase flist_menu_file + global nullid nullid2 gitdir + set from_index {} if {$cmitmode eq "tree"} { set id $currentid set line [expr {$diff_menu_line - $diff_menu_filebase}] @@ -3279,11 +3297,46 @@ proc show_line_source {} { mark_ctext_line $diff_menu_line return } - set id [lindex $parents($curview,$currentid) [expr {$pi - 1}]] + incr pi -1 + if {$currentid eq $nullid} { + if {$pi > 0} { + # must be a merge in progress... + if {[catch { + # get the last line from .git/MERGE_HEAD + set f [open [file join $gitdir MERGE_HEAD] r] + set id [lindex [split [read $f] "\n"] end-1] + close $f + } err]} { + error_popup [mc "Couldn't read merge head: %s" $err] + return + } + } elseif {$parents($curview,$currentid) eq $nullid2} { + # need to do the blame from the index + if {[catch { + set from_index [index_sha1 $flist_menu_file] + } err]} { + error_popup [mc "Error reading index: %s" $err] + return + } + } + } else { + set id [lindex $parents($curview,$currentid) $pi] + } set line [lindex $h 1] } + set blameargs {} + if {$from_index ne {}} { + lappend blameargs | git cat-file blob $from_index + } + lappend blameargs | git blame -p -L$line,+1 + if {$from_index ne {}} { + lappend blameargs --contents - + } else { + lappend blameargs $id + } + lappend blameargs -- $flist_menu_file if {[catch { - set f [open [list | git blame -p -L$line,+1 $id -- $flist_menu_file] r] + set f [open $blameargs r] } err]} { error_popup [mc "Couldn't start git blame: %s" $err] return @@ -3305,7 +3358,7 @@ proc stopblaming {} { } proc read_line_source {fd inst} { - global blamestuff curview commfd blameinst + global blamestuff curview commfd blameinst nullid nullid2 while {[gets $fd line] >= 0} { lappend blamestuff($inst) $line @@ -3337,6 +3390,11 @@ proc read_line_source {fd inst} { } if {$fname ne {}} { # all looks good, select it + if {$id eq $nullid} { + # blame uses all-zeroes to mean not committed, + # which would mean a change in the index + set id $nullid2 + } if {[commitinview $id $curview]} { selectline [rowofcommit $id] 1 [list $fname $lnum] } else { From 0f3a290b89b89bb5375cf5019b067e4a99f02620 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 27 Oct 2008 12:51:59 -0700 Subject: [PATCH 040/138] Add a 'source' decorator for commits We already support decorating commits by tags or branches that point to them, but especially when we are looking at multiple branches together, we sometimes want to see _how_ we reached a particular commit. We can abuse the '->util' field in the commit to keep track of that as we walk the commit lists, and get a reasonably useful view into which branch or tag first reaches that commit. Of course, if the commit is reachable through multiple sources (which is common), our particular choice of "first" reachable is entirely random and depends on the particular path we happened to follow. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- builtin-log.c | 2 ++ builtin-rev-list.c | 2 +- log-tree.c | 8 +++++--- log-tree.h | 2 +- revision.c | 4 ++++ revision.h | 1 + 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/builtin-log.c b/builtin-log.c index a0944f70a4..176cbce308 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -56,6 +56,8 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, if (!strcmp(arg, "--decorate")) { load_ref_decorations(); decorate = 1; + } else if (!strcmp(arg, "--source")) { + rev->show_source = 1; } else die("unrecognized argument: %s", arg); } diff --git a/builtin-rev-list.c b/builtin-rev-list.c index 06cdeb7ebe..857742a14f 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -100,7 +100,7 @@ static void show_commit(struct commit *commit) children = children->next; } } - show_decorations(commit); + show_decorations(&revs, commit); if (revs.commit_format == CMIT_FMT_ONELINE) putchar(' '); else diff --git a/log-tree.c b/log-tree.c index cec3c06136..cf7947b9c9 100644 --- a/log-tree.c +++ b/log-tree.c @@ -52,11 +52,13 @@ static void show_parents(struct commit *commit, int abbrev) } } -void show_decorations(struct commit *commit) +void show_decorations(struct rev_info *opt, struct commit *commit) { const char *prefix; struct name_decoration *decoration; + if (opt->show_source && commit->util) + printf(" %s", (char *) commit->util); decoration = lookup_decoration(&name_decoration, &commit->object); if (!decoration) return; @@ -279,7 +281,7 @@ void show_log(struct rev_info *opt) fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) show_parents(commit, abbrev_commit); - show_decorations(commit); + show_decorations(opt, commit); if (opt->graph && !graph_is_commit_finished(opt->graph)) { putchar('\n'); graph_show_remainder(opt->graph); @@ -352,7 +354,7 @@ void show_log(struct rev_info *opt) printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); - show_decorations(commit); + show_decorations(opt, commit); printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET)); if (opt->commit_format == CMIT_FMT_ONELINE) { putchar(' '); diff --git a/log-tree.h b/log-tree.h index 3c8127bb7c..f2a90084ae 100644 --- a/log-tree.h +++ b/log-tree.h @@ -12,7 +12,7 @@ int log_tree_diff_flush(struct rev_info *); int log_tree_commit(struct rev_info *, struct commit *); int log_tree_opt_parse(struct rev_info *, const char **, int); void show_log(struct rev_info *opt); -void show_decorations(struct commit *commit); +void show_decorations(struct rev_info *opt, struct commit *commit); void log_write_email_headers(struct rev_info *opt, const char *name, const char **subject_p, const char **extra_headers_p, diff --git a/revision.c b/revision.c index 2f646deab0..d45f05a00c 100644 --- a/revision.c +++ b/revision.c @@ -199,6 +199,8 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object mark_parents_uninteresting(commit); revs->limited = 1; } + if (revs->show_source && !commit->util) + commit->util = (void *) name; return commit; } @@ -484,6 +486,8 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, if (parse_commit(p) < 0) return -1; + if (revs->show_source && !p->util) + p->util = commit->util; p->object.flags |= left_flag; if (!(p->object.flags & SEEN)) { p->object.flags |= SEEN; diff --git a/revision.h b/revision.h index 2fdb2dd0ff..51a48630e8 100644 --- a/revision.h +++ b/revision.h @@ -53,6 +53,7 @@ struct rev_info { left_right:1, rewrite_parents:1, print_parents:1, + show_source:1, reverse:1, reverse_output_stage:1, cherry_pick:1, From 3a5e860815010e362c746aedf7981e9b3b9a69e8 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 3 Nov 2008 10:45:41 -0800 Subject: [PATCH 041/138] revision: make tree comparison functions take commits rather than trees This will make it easier to do various clever things that don't depend on the pure tree contents. It also makes the parameter passing much simpler - the callers doesn't really look at trees anywhere else, and it's really the function that should look at the low-level details. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- revision.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/revision.c b/revision.c index d45f05a00c..56b09eb315 100644 --- a/revision.c +++ b/revision.c @@ -294,8 +294,11 @@ static void file_change(struct diff_options *options, DIFF_OPT_SET(options, HAS_CHANGES); } -static int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree *t2) +static int rev_compare_tree(struct rev_info *revs, struct commit *parent, struct commit *commit) { + struct tree *t1 = parent->tree; + struct tree *t2 = commit->tree; + if (!t1) return REV_TREE_NEW; if (!t2) @@ -308,12 +311,13 @@ static int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree return tree_difference; } -static int rev_same_tree_as_empty(struct rev_info *revs, struct tree *t1) +static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit) { int retval; void *tree; unsigned long size; struct tree_desc empty, real; + struct tree *t1 = commit->tree; if (!t1) return 0; @@ -347,7 +351,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) return; if (!commit->parents) { - if (rev_same_tree_as_empty(revs, commit->tree)) + if (rev_same_tree_as_empty(revs, commit)) commit->object.flags |= TREESAME; return; } @@ -367,7 +371,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) die("cannot simplify commit %s (because of %s)", sha1_to_hex(commit->object.sha1), sha1_to_hex(p->object.sha1)); - switch (rev_compare_tree(revs, p->tree, commit->tree)) { + switch (rev_compare_tree(revs, p, commit)) { case REV_TREE_SAME: tree_same = 1; if (!revs->simplify_history || (p->object.flags & UNINTERESTING)) { @@ -387,7 +391,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) case REV_TREE_NEW: if (revs->remove_empty_trees && - rev_same_tree_as_empty(revs, p->tree)) { + rev_same_tree_as_empty(revs, p)) { /* We are adding all the specified * paths from this parent, so the * history beyond this parent is not From d467a525da28b28a0d8e16a42e121ab638fa7347 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 3 Nov 2008 11:23:57 -0800 Subject: [PATCH 042/138] Make '--decorate' set an explicit 'show_decorations' flag We will want to add decorations without necessarily showing them, so add an explicit revisions info flag as to whether we're showing decorations or not. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- builtin-log.c | 3 +-- log-tree.c | 2 ++ revision.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin-log.c b/builtin-log.c index 176cbce308..82ea07b1bd 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -28,7 +28,6 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, struct rev_info *rev) { int i; - int decorate = 0; rev->abbrev = DEFAULT_ABBREV; rev->commit_format = CMIT_FMT_DEFAULT; @@ -55,7 +54,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, const char *arg = argv[i]; if (!strcmp(arg, "--decorate")) { load_ref_decorations(); - decorate = 1; + rev->show_decorations = 1; } else if (!strcmp(arg, "--source")) { rev->show_source = 1; } else diff --git a/log-tree.c b/log-tree.c index cf7947b9c9..5444f0860b 100644 --- a/log-tree.c +++ b/log-tree.c @@ -59,6 +59,8 @@ void show_decorations(struct rev_info *opt, struct commit *commit) if (opt->show_source && commit->util) printf(" %s", (char *) commit->util); + if (!opt->show_decorations) + return; decoration = lookup_decoration(&name_decoration, &commit->object); if (!decoration) return; diff --git a/revision.h b/revision.h index 51a48630e8..0a1806a9e1 100644 --- a/revision.h +++ b/revision.h @@ -54,6 +54,7 @@ struct rev_info { rewrite_parents:1, print_parents:1, show_source:1, + show_decorations:1, reverse:1, reverse_output_stage:1, cherry_pick:1, From 78892e32616f00bf173496ca0502aff2e523db31 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 3 Nov 2008 11:25:46 -0800 Subject: [PATCH 043/138] revision traversal: '--simplify-by-decoration' With this, you can simplify history not by the contents of the tree, but whether a commit has been named (ie it's referred to by some branch or tag) or not. This makes it possible to see the relationship between different named commits, without actually seeing any of the details. When used with pathspec, you would get the usual view that is limited to the commits that change the contents of the tree plus commits that are named. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- revision.c | 27 +++++++++++++++++++++++++++ revision.h | 1 + 2 files changed, 28 insertions(+) diff --git a/revision.c b/revision.c index 56b09eb315..9dc55d4003 100644 --- a/revision.c +++ b/revision.c @@ -11,6 +11,7 @@ #include "reflog-walk.h" #include "patch-ids.h" #include "decorate.h" +#include "log-tree.h" volatile show_early_output_fn_t show_early_output; @@ -301,6 +302,24 @@ static int rev_compare_tree(struct rev_info *revs, struct commit *parent, struct if (!t1) return REV_TREE_NEW; + + if (revs->simplify_by_decoration) { + /* + * If we are simplifying by decoration, then the commit + * is worth showing if it has a tag pointing at it. + */ + if (lookup_decoration(&name_decoration, &commit->object)) + return REV_TREE_DIFFERENT; + /* + * A commit that is not pointed by a tag is uninteresting + * if we are not limited by path. This means that you will + * see the usual "commits that touch the paths" plus any + * tagged commit by specifying both --simplify-by-decoration + * and pathspec. + */ + if (!revs->prune_data) + return REV_TREE_SAME; + } if (!t2) return REV_TREE_DIFFERENT; tree_difference = REV_TREE_SAME; @@ -1041,6 +1060,14 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->rewrite_parents = 1; revs->simplify_history = 0; revs->limited = 1; + } else if (!strcmp(arg, "--simplify-by-decoration")) { + revs->simplify_merges = 1; + revs->rewrite_parents = 1; + revs->simplify_history = 0; + revs->simplify_by_decoration = 1; + revs->limited = 1; + revs->prune = 1; + load_ref_decorations(); } else if (!strcmp(arg, "--date-order")) { revs->lifo = 0; revs->topo_order = 1; diff --git a/revision.h b/revision.h index 0a1806a9e1..7cf848771b 100644 --- a/revision.h +++ b/revision.h @@ -43,6 +43,7 @@ struct rev_info { lifo:1, topo_order:1, simplify_merges:1, + simplify_by_decoration:1, tag_objects:1, tree_objects:1, blob_objects:1, From 48a81b7cda1e58d8cc4d9bcadce76bbf1680ab7d Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Tue, 4 Nov 2008 21:09:00 +1100 Subject: [PATCH 044/138] gitk: Cope with unmerged files in local changes This modifies gettreediffline so that it when we get both a "U" line and an "M" line for the same file in the output from git diff-files or git diff-index --cached (used when the user clicks on a fake commit) we don't add the same filename to the treediff list twice. This also makes getblobdiffline recognize the "* Unmerged path ..." lines we get when we ask for the actual diffs, and makes a tiny optimization in makediffhdr. Signed-off-by: Paul Mackerras --- gitk | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gitk b/gitk index f386981cc9..bea5026f62 100755 --- a/gitk +++ b/gitk @@ -6854,8 +6854,10 @@ proc gettreediffline {gdtf ids} { set file [lindex $file 0] } set file [encoding convertfrom $file] - lappend treediff $file - lappend sublist $file + if {$file ne [lindex $treediff end]} { + lappend treediff $file + lappend sublist $file + } } } if {$perfile_attrs} { @@ -6960,7 +6962,7 @@ proc makediffhdr {fname ids} { if {$i >= 0} { setinlist difffilestart $i $curdiffstart } - set ctext_file_names [lreplace $ctext_file_names end end $fname] + lset ctext_file_names end $fname set l [expr {(78 - [string length $fname]) / 2}] set pad [string range "----------------------------------------" 1 $l] $ctext insert $curdiffstart "$pad $fname $pad" filesep @@ -7033,6 +7035,18 @@ proc getblobdiffline {bdf ids} { } makediffhdr $fname $ids + } elseif {![string compare -length 16 "* Unmerged path " $line]} { + set fname [encoding convertfrom [string range $line 16 end]] + $ctext insert end "\n" + set curdiffstart [$ctext index "end - 1c"] + lappend ctext_file_names $fname + lappend ctext_file_lines [lindex [split $curdiffstart "."] 0] + $ctext insert end "$line\n" filesep + set i [lsearch -exact $treediffs($ids) $fname] + if {$i >= 0} { + setinlist difffilestart $i $curdiffstart + } + } elseif {![string compare -length 2 "@@" $line]} { regexp {^@@+} $line ats set line [encoding convertfrom $diffencoding $line] From 6fa8342b12aeb3e3895d3b3d8d34d45fa872ac45 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 5 Nov 2008 00:20:31 +0100 Subject: [PATCH 045/138] tag: Check that options are only allowed in the appropriate mode If "git tag -d -l -v ..." is called, only "-l" is honored, which is arbitrary and wrong. Also, unrecognized options are accepted in the wrong modes, causing for example "git tag -n 100" to create a tag named "100" while the user may have wanted to type "git tag -n100". This patch checks that "git tag" knows in what mode it operates before performing any operation and accepts only the related options. Signed-off-by: Samuel Tardieu Signed-off-by: Junio C Hamano --- builtin-tag.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/builtin-tag.c b/builtin-tag.c index f2853d08c7..50cafc814d 100644 --- a/builtin-tag.c +++ b/builtin-tag.c @@ -344,7 +344,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) const char *object_ref, *tag; struct ref_lock *lock; - int annotate = 0, sign = 0, force = 0, lines = 0, + int annotate = 0, sign = 0, force = 0, lines = -1, list = 0, delete = 0, verify = 0; const char *msgfile = NULL, *keyid = NULL; struct msg_arg msg = { 0, STRBUF_INIT }; @@ -380,9 +380,19 @@ int cmd_tag(int argc, const char **argv, const char *prefix) } if (sign) annotate = 1; + if (argc == 0 && !(delete || verify)) + list = 1; + if ((annotate || msg.given || msgfile || force) && + (list || delete || verify)) + usage_with_options(git_tag_usage, options); + + if (list + delete + verify > 1) + usage_with_options(git_tag_usage, options); if (list) - return list_tags(argv[0], lines); + return list_tags(argv[0], lines == -1 ? 0 : lines); + if (lines != -1) + die("-n option is only allowed with -l."); if (delete) return for_each_tag_name(argv, delete_tag); if (verify) @@ -407,11 +417,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix) } } - if (argc == 0) { - if (annotate) - usage_with_options(git_tag_usage, options); - return list_tags(NULL, lines); - } tag = argv[0]; object_ref = argc == 2 ? argv[1] : "HEAD"; From e0e03a731b2d06f42e79a2ff156ef9bd0e5c6c02 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 5 Nov 2008 00:20:36 +0100 Subject: [PATCH 046/138] tag: Add more tests about mixing incompatible modes and options Signed-off-by: Samuel Tardieu Signed-off-by: Junio C Hamano --- t/t7004-tag.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index 33cde70595..c616deb0d0 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -1090,4 +1090,15 @@ test_expect_success 'filename for the message is relative to cwd' ' git cat-file tag tag-from-subdir-2 | grep "in sub directory" ' +# mixing modes and options: + +test_expect_success 'mixing incompatibles modes and options is forbidden' ' + test_must_fail git tag -a + test_must_fail git tag -l -v + test_must_fail git tag -n 100 + test_must_fail git tag -l -m msg + test_must_fail git tag -l -F some file + test_must_fail git tag -v -s +' + test_done From bf98421a3363696f3b4c8aedc242bfaadc1ce6f6 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 3 Nov 2008 19:26:18 +0100 Subject: [PATCH 047/138] Implement git remote rename The new rename subcommand does the followings: 1) Renames the remote.foo configuration section to remote.bar 2) Updates the remote.bar.fetch refspecs 3) Updates the branch.*.remote settings 4) Renames the tracking branches: renames the normal refs and rewrites the symrefs to point to the new refs. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- Documentation/git-remote.txt | 6 ++ builtin-remote.c | 153 +++++++++++++++++++++++++++++++++++ t/t5505-remote.sh | 15 ++++ 3 files changed, 174 insertions(+) diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt index bb99810ec7..7b227b307f 100644 --- a/Documentation/git-remote.txt +++ b/Documentation/git-remote.txt @@ -11,6 +11,7 @@ SYNOPSIS [verse] 'git remote' [-v | --verbose] 'git remote add' [-t ] [-m ] [-f] [--mirror] +'git remote rename' 'git remote rm' 'git remote show' [-n] 'git remote prune' [-n | --dry-run] @@ -61,6 +62,11 @@ only makes sense in bare repositories. If a remote uses mirror mode, furthermore, `git push` will always behave as if `\--mirror` was passed. +'rename':: + +Rename the remote named to . All remote tracking branches and +configuration settings for the remote are updated. + 'rm':: Remove the remote named . All remote tracking branches and diff --git a/builtin-remote.c b/builtin-remote.c index e396a3ac90..1ca6cdbe2a 100644 --- a/builtin-remote.c +++ b/builtin-remote.c @@ -10,6 +10,7 @@ static const char * const builtin_remote_usage[] = { "git remote", "git remote add ", + "git remote rename ", "git remote rm ", "git remote show ", "git remote prune ", @@ -329,6 +330,156 @@ static int add_branch_for_removal(const char *refname, return 0; } +struct rename_info { + const char *old; + const char *new; + struct string_list *remote_branches; +}; + +static int read_remote_branches(const char *refname, + const unsigned char *sha1, int flags, void *cb_data) +{ + struct rename_info *rename = cb_data; + struct strbuf buf = STRBUF_INIT; + struct string_list_item *item; + int flag; + unsigned char orig_sha1[20]; + const char *symref; + + strbuf_addf(&buf, "refs/remotes/%s", rename->old); + if(!prefixcmp(refname, buf.buf)) { + item = string_list_append(xstrdup(refname), rename->remote_branches); + symref = resolve_ref(refname, orig_sha1, 1, &flag); + if (flag & REF_ISSYMREF) + item->util = xstrdup(symref); + else + item->util = NULL; + } + + return 0; +} + +static int mv(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + struct remote *oldremote, *newremote; + struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT; + struct string_list remote_branches = { NULL, 0, 0, 0 }; + struct rename_info rename; + int i; + + if (argc != 3) + usage_with_options(builtin_remote_usage, options); + + rename.old = argv[1]; + rename.new = argv[2]; + rename.remote_branches = &remote_branches; + + oldremote = remote_get(rename.old); + if (!oldremote) + die("No such remote: %s", rename.old); + + newremote = remote_get(rename.new); + if (newremote && (newremote->url_nr > 1 || newremote->fetch_refspec_nr)) + die("remote %s already exists.", rename.new); + + strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new); + if (!valid_fetch_refspec(buf.buf)) + die("'%s' is not a valid remote name", rename.new); + + strbuf_reset(&buf); + strbuf_addf(&buf, "remote.%s", rename.old); + strbuf_addf(&buf2, "remote.%s", rename.new); + if (git_config_rename_section(buf.buf, buf2.buf) < 1) + return error("Could not rename config section '%s' to '%s'", + buf.buf, buf2.buf); + + strbuf_reset(&buf); + strbuf_addf(&buf, "remote.%s.fetch", rename.new); + if (git_config_set_multivar(buf.buf, NULL, NULL, 1)) + return error("Could not remove config section '%s'", buf.buf); + for (i = 0; i < oldremote->fetch_refspec_nr; i++) { + char *ptr; + + strbuf_reset(&buf2); + strbuf_addstr(&buf2, oldremote->fetch_refspec[i]); + ptr = strstr(buf2.buf, rename.old); + if (ptr) + strbuf_splice(&buf2, ptr-buf2.buf, strlen(rename.old), + rename.new, strlen(rename.new)); + if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0)) + return error("Could not append '%s'", buf.buf); + } + + read_branches(); + for (i = 0; i < branch_list.nr; i++) { + struct string_list_item *item = branch_list.items + i; + struct branch_info *info = item->util; + if (info->remote && !strcmp(info->remote, rename.old)) { + strbuf_reset(&buf); + strbuf_addf(&buf, "branch.%s.remote", item->string); + if (git_config_set(buf.buf, rename.new)) { + return error("Could not set '%s'", buf.buf); + } + } + } + + /* + * First remove symrefs, then rename the rest, finally create + * the new symrefs. + */ + for_each_ref(read_remote_branches, &rename); + for (i = 0; i < remote_branches.nr; i++) { + struct string_list_item *item = remote_branches.items + i; + int flag = 0; + unsigned char sha1[20]; + const char *symref; + + symref = resolve_ref(item->string, sha1, 1, &flag); + if (!(flag & REF_ISSYMREF)) + continue; + if (delete_ref(item->string, NULL, REF_NODEREF)) + die("deleting '%s' failed", item->string); + } + for (i = 0; i < remote_branches.nr; i++) { + struct string_list_item *item = remote_branches.items + i; + + if (item->util) + continue; + strbuf_reset(&buf); + strbuf_addstr(&buf, item->string); + strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old), + rename.new, strlen(rename.new)); + strbuf_reset(&buf2); + strbuf_addf(&buf2, "remote: renamed %s to %s", + item->string, buf.buf); + if (rename_ref(item->string, buf.buf, buf2.buf)) + die("renaming '%s' failed", item->string); + } + for (i = 0; i < remote_branches.nr; i++) { + struct string_list_item *item = remote_branches.items + i; + + if (!item->util) + continue; + strbuf_reset(&buf); + strbuf_addstr(&buf, item->string); + strbuf_splice(&buf, strlen("refs/remotes/"), strlen(rename.old), + rename.new, strlen(rename.new)); + strbuf_reset(&buf2); + strbuf_addstr(&buf2, item->util); + strbuf_splice(&buf2, strlen("refs/remotes/"), strlen(rename.old), + rename.new, strlen(rename.new)); + strbuf_reset(&buf3); + strbuf_addf(&buf3, "remote: renamed %s to %s", + item->string, buf.buf); + if (create_symref(buf.buf, buf2.buf, buf3.buf)) + die("creating '%s' failed", buf.buf); + } + return 0; +} + static int remove_branches(struct string_list *branches) { int i, result = 0; @@ -695,6 +846,8 @@ int cmd_remote(int argc, const char **argv, const char *prefix) result = show_all(); else if (!strcmp(argv[0], "add")) result = add(argc, argv); + else if (!strcmp(argv[0], "rename")) + result = mv(argc, argv); else if (!strcmp(argv[0], "rm")) result = rm(argc, argv); else if (!strcmp(argv[0], "show")) diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index c4380c7e32..0c956bad69 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -328,4 +328,19 @@ test_expect_success 'reject adding remote with an invalid name' ' ' +# The first three test if the tracking branches are properly renamed, +# the last two ones check if the config is updated. + +test_expect_success 'rename a remote' ' + + git clone one four && + (cd four && + git remote rename origin upstream && + rmdir .git/refs/remotes/origin && + test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/master" && + test "$(git rev-parse upstream/master)" = "$(git rev-parse master)" && + test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" && + test "$(git config branch.master.remote)" = "upstream") + +' test_done From 5bdd8d4a3062ac8f29ec511fecb85049f6ff3ecc Mon Sep 17 00:00:00 2001 From: Clemens Buchacher Date: Wed, 5 Nov 2008 21:55:53 +0100 Subject: [PATCH 048/138] do not force write of packed refs We force writing a ref if it does not exist. Originally, we only had to look for the ref file to check if it existed. Now we have to look for a packed ref as well. Luckily, resolve_ref already does all the work for us. Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- refs.c | 7 ++++--- t/t3210-pack-refs.sh | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/refs.c b/refs.c index 9e422dcccb..7d91b670c5 100644 --- a/refs.c +++ b/refs.c @@ -788,10 +788,10 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char char *ref_file; const char *orig_ref = ref; struct ref_lock *lock; - struct stat st; int last_errno = 0; int type, lflags; int mustexist = (old_sha1 && !is_null_sha1(old_sha1)); + int missing = 0; lock = xcalloc(1, sizeof(struct ref_lock)); lock->lock_fd = -1; @@ -819,12 +819,13 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char orig_ref, strerror(errno)); goto error_return; } + missing = is_null_sha1(lock->old_sha1); /* When the ref did not exist and we are creating it, * make sure there is no existing ref that is packed * whose name begins with our refname, nor a ref whose * name is a proper prefix of our refname. */ - if (is_null_sha1(lock->old_sha1) && + if (missing && !is_refname_available(ref, NULL, get_packed_refs(), 0)) goto error_return; @@ -838,7 +839,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char lock->ref_name = xstrdup(ref); lock->orig_ref_name = xstrdup(orig_ref); ref_file = git_path("%s", ref); - if (lstat(ref_file, &st) && errno == ENOENT) + if (missing) lock->force_write = 1; if ((flags & REF_NODEREF) && (type & REF_ISSYMREF)) lock->force_write = 1; diff --git a/t/t3210-pack-refs.sh b/t/t3210-pack-refs.sh index 087ef75061..413019acaf 100755 --- a/t/t3210-pack-refs.sh +++ b/t/t3210-pack-refs.sh @@ -96,6 +96,13 @@ test_expect_success \ git branch -d n/o/p && git branch n' +test_expect_success \ + 'see if up-to-date packed refs are preserved' \ + 'git branch q && + git pack-refs --all --prune && + git update-ref refs/heads/q refs/heads/q && + ! test -f .git/refs/heads/q' + test_expect_success 'pack, prune and repack' ' git tag foo && git pack-refs --all --prune && From 16ed2f48be228918af3d1a6c5a6a4fe9b832cb84 Mon Sep 17 00:00:00 2001 From: Clemens Buchacher Date: Wed, 5 Nov 2008 21:55:54 +0100 Subject: [PATCH 049/138] push: fix local refs update if already up-to-date git push normally updates local refs only after a successful push. If the remote already has the updates -- pushed indirectly through another repository, for example -- we forget to update local tracking refs. Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- builtin-send-pack.c | 22 ++++++++-------------- t/t5516-fetch-push.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/builtin-send-pack.c b/builtin-send-pack.c index 301f230432..8fdeaa3989 100644 --- a/builtin-send-pack.c +++ b/builtin-send-pack.c @@ -222,7 +222,7 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref) { struct refspec rs; - if (ref->status != REF_STATUS_OK) + if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE) return; rs.src = ref->name; @@ -424,24 +424,19 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest */ new_refs = 0; for (ref = remote_refs; ref; ref = ref->next) { - const unsigned char *new_sha1; - if (!ref->peer_ref) { - if (!args.send_mirror) - continue; - new_sha1 = null_sha1; - } - else - new_sha1 = ref->peer_ref->new_sha1; + if (ref->peer_ref) + hashcpy(ref->new_sha1, ref->peer_ref->new_sha1); + else if (!args.send_mirror) + continue; - - ref->deletion = is_null_sha1(new_sha1); + ref->deletion = is_null_sha1(ref->new_sha1); if (ref->deletion && !allow_deleting_refs) { ref->status = REF_STATUS_REJECT_NODELETE; continue; } if (!ref->deletion && - !hashcmp(ref->old_sha1, new_sha1)) { + !hashcmp(ref->old_sha1, ref->new_sha1)) { ref->status = REF_STATUS_UPTODATE; continue; } @@ -469,14 +464,13 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest !ref->deletion && !is_null_sha1(ref->old_sha1) && (!has_sha1_file(ref->old_sha1) - || !ref_newer(new_sha1, ref->old_sha1)); + || !ref_newer(ref->new_sha1, ref->old_sha1)); if (ref->nonfastforward && !ref->force && !args.force_update) { ref->status = REF_STATUS_REJECT_NONFASTFORWARD; continue; } - hashcpy(ref->new_sha1, new_sha1); if (!ref->deletion) new_refs++; diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index f0030ad00e..598664ce7f 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -437,6 +437,37 @@ test_expect_success 'push updates local refs' ' ' +test_expect_success 'push updates up-to-date local refs' ' + + rm -rf parent child && + mkdir parent && + (cd parent && git init && + echo one >foo && git add foo && git commit -m one) && + git clone parent child1 && + git clone parent child2 && + (cd child1 && + echo two >foo && git commit -a -m two && + git push) && + (cd child2 && + git pull ../child1 master && + git push && + test $(git rev-parse master) = $(git rev-parse remotes/origin/master)) + +' + +test_expect_success 'push preserves up-to-date packed refs' ' + + rm -rf parent child && + mkdir parent && + (cd parent && git init && + echo one >foo && git add foo && git commit -m one) && + git clone parent child && + (cd child && + git push && + ! test -f .git/refs/remotes/origin/master) + +' + test_expect_success 'push does not update local refs on failure' ' rm -rf parent child && From 163f3689e94440d1900fbdec4693cfae384be94a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 21 Oct 2008 14:12:15 -0700 Subject: [PATCH 050/138] git-svn: don't escape tilde ('~') for http(s) URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Jose Carlos Garcia Sogo and Björn Steinbrink for the bug report. On 2008.10.18 23:39:19 +0200, Björn Steinbrink wrote: > Hi, > > Jose Carlos Garcia Sogo reported on #git that a git-svn clone of this > svn repo fails for him: > https://sucs.org/~welshbyte/svn/backuptool/trunk > > I can reproduce that here with: > git-svn version 1.6.0.2.541.g46dc1.dirty (svn 1.5.1) > > The error message I get is: > Apache got a malformed URI: Unusable URI: it does not refer to this > repository at /usr/local/libexec/git-core/git-svn line 4057 > > strace revealed that git-svn url-encodes ~ while svn does not do that. > > For svn we have: > write(5, " > https://sucs.org/~welshbyte/svn/backuptool/trunk... > > While git-svn shows: > write(7, " > https://sucs.org/%7Ewelshbyte/svn/backuptool/trunk... Signed-off-by: Eric Wong --- git-svn.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 5702b100f1..70a664ca0b 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -852,7 +852,7 @@ sub escape_uri_only { my ($uri) = @_; my @tmp; foreach (split m{/}, $uri) { - s/([^\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg; + s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg; push @tmp, $_; } join('/', @tmp); @@ -3537,7 +3537,7 @@ sub repo_path { sub url_path { my ($self, $path) = @_; if ($self->{url} =~ m#^https?://#) { - $path =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; + $path =~ s/([^~a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; } $self->{url} . '/' . $self->repo_path($path); } @@ -3890,7 +3890,7 @@ sub escape_uri_only { my ($uri) = @_; my @tmp; foreach (split m{/}, $uri) { - s/([^\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg; + s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg; push @tmp, $_; } join('/', @tmp); From aab57205515d9a74fe20cd51c509f65757b97a66 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 29 Oct 2008 23:49:26 -0700 Subject: [PATCH 051/138] git-svn: respect i18n.commitencoding config SVN itself always stores log messages in the repository as UTF-8. git always stores/retrieves everything as raw binary data with no transformations whatsoever. To interact with SVN, we need to encode log messages as UTF-8 before sending them to SVN, as SVN cannot do it for us. When retrieving log messages from SVN, we also need to (attempt to) reencode the UTF-8 log message back to the user-specified commit encoding. Note, handling i18n.logoutputencoding for "git svn log" also needs to be done in a future change. Also, this change only deals with the encoding of commit messages and nothing else (path names, blob content, ...). In-Reply-To: <8b168cfb0810282014r789ac01dnec51824de1078f0@mail.gmail.com> James North wrote: > Hi, > > I'm using git-svn on a system with ISO-8859-1 encoding. The problem is > when I try to use "git svn dcommit" to send changes to a remote svn > (also ISO-8859-1). > > Seems like git-svn is sending commit messages with utf-8 (just a > guessing...) and they look bad on the remote svn log. E.g. "Ca?\241a > de cami?\243n" > > I have tried using i18n.commitencoding=ISO-8859-1 as suggested by the > warning when doing "git svn dcommit" but messages still are sent with > wrong encoding. Signed-off-by: Eric Wong --- git-svn.perl | 24 +++++++- t/t9129-git-svn-i18n-commitencoding.sh | 80 ++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) create mode 100755 t/t9129-git-svn-i18n-commitencoding.sh diff --git a/git-svn.perl b/git-svn.perl index 70a664ca0b..2abb7b5937 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -1136,9 +1136,19 @@ sub get_commit_entry { system($editor, $commit_editmsg); } rename $commit_editmsg, $commit_msg or croak $!; - open $log_fh, '<', $commit_msg or croak $!; - { local $/; chomp($log_entry{log} = <$log_fh>); } - close $log_fh or croak $!; + { + # SVN requires messages to be UTF-8 when entering the repo + local $/; + open $log_fh, '<', $commit_msg or croak $!; + binmode $log_fh; + chomp($log_entry{log} = <$log_fh>); + + if (my $enc = Git::config('i18n.commitencoding')) { + require Encode; + Encode::from_to($log_entry{log}, $enc, 'UTF-8'); + } + close $log_fh or croak $!; + } unlink $commit_msg; \%log_entry; } @@ -2273,6 +2283,14 @@ sub do_git_commit { } defined(my $pid = open3(my $msg_fh, my $out_fh, '>&STDERR', @exec)) or croak $!; + binmode $msg_fh; + + # we always get UTF-8 from SVN, but we may want our commits in + # a different encoding. + if (my $enc = Git::config('i18n.commitencoding')) { + require Encode; + Encode::from_to($log_entry->{log}, 'UTF-8', $enc); + } print $msg_fh $log_entry->{log} or croak $!; restore_commit_header_env($old_env); unless ($self->no_metadata) { diff --git a/t/t9129-git-svn-i18n-commitencoding.sh b/t/t9129-git-svn-i18n-commitencoding.sh new file mode 100755 index 0000000000..2848e46e38 --- /dev/null +++ b/t/t9129-git-svn-i18n-commitencoding.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# +# Copyright (c) 2008 Eric Wong + +test_description='git svn honors i18n.commitEncoding in config' + +. ./lib-git-svn.sh + +compare_git_head_with () { + nr=`wc -l < "$1"` + a=7 + b=$(($a + $nr - 1)) + git cat-file commit HEAD | sed -ne "$a,${b}p" >current && + test_cmp current "$1" +} + +compare_svn_head_with () { + LC_ALL=en_US.UTF-8 svn log --limit 1 `git svn info --url` | \ + sed -e 1,3d -e "/^-\+\$/d" >current && + test_cmp current "$1" +} + +for H in ISO-8859-1 EUCJP ISO-2022-JP +do + test_expect_success "$H setup" ' + mkdir $H && + svn import -m "$H test" $H "$svnrepo"/$H && + git svn clone "$svnrepo"/$H $H + ' +done + +for H in ISO-8859-1 EUCJP ISO-2022-JP +do + test_expect_success "$H commit on git side" ' + ( + cd $H && + git config i18n.commitencoding $H && + git checkout -b t refs/remotes/git-svn && + echo $H >F && + git add F && + git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt && + E=$(git cat-file commit HEAD | sed -ne "s/^encoding //p") && + test "z$E" = "z$H" + compare_git_head_with "$TEST_DIRECTORY"/t3900/$H.txt + ) + ' +done + +for H in ISO-8859-1 EUCJP ISO-2022-JP +do + test_expect_success "$H dcommit to svn" ' + ( + cd $H && + git svn dcommit && + git cat-file commit HEAD | grep git-svn-id: && + E=$(git cat-file commit HEAD | sed -ne "s/^encoding //p") && + test "z$E" = "z$H" && + compare_git_head_with "$TEST_DIRECTORY"/t3900/$H.txt + ) + ' +done + +test_expect_success 'ISO-8859-1 should match UTF-8 in svn' ' +( + cd ISO-8859-1 && + compare_svn_head_with "$TEST_DIRECTORY"/t3900/1-UTF-8.txt +) +' + +for H in EUCJP ISO-2022-JP +do + test_expect_success '$H should match UTF-8 in svn' ' + ( + cd $H && + compare_svn_head_with "$TEST_DIRECTORY"/t3900/2-UTF-8.txt + ) + ' +done + +test_done From 6e5121f26e95af02d2bbd6a982e44f16e74a67ce Mon Sep 17 00:00:00 2001 From: Deskin Miller Date: Thu, 6 Nov 2008 00:07:39 -0500 Subject: [PATCH 052/138] git-svn: proper detection of bare repositories When in a bare repository (or .git, for that matter), git-svn would fail to initialise properly, since git rev-parse --show-cdup would not output anything. However, git rev-parse --show-cdup actually returns an error code if it's really not in a git directory. Fix the issue by checking for an explicit error from git rev-parse, and setting $git_dir appropriately if instead it just does not output. Signed-off-by: Deskin Miller Acked-by: Eric Wong --- git-svn.perl | 12 +++++++----- t/t9100-git-svn-basic.sh | 9 +++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 2abb7b5937..86075ec616 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -223,11 +223,13 @@ unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) { "but it is not a directory\n"; } my $git_dir = delete $ENV{GIT_DIR}; - chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/)); - unless (length $cdup) { - die "Already at toplevel, but $git_dir ", - "not found '$cdup'\n"; - } + my $cdup = undef; + git_cmd_try { + $cdup = command_oneline(qw/rev-parse --show-cdup/); + $git_dir = '.' unless ($cdup); + chomp $cdup if ($cdup); + $cdup = "." unless ($cdup && length $cdup); + } "Already at toplevel, but $git_dir not found\n"; chdir $cdup or die "Unable to chdir up to '$cdup'\n"; unless (-d $git_dir) { die "$git_dir still not found after going to ", diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh index 9b238c329b..bb921af56a 100755 --- a/t/t9100-git-svn-basic.sh +++ b/t/t9100-git-svn-basic.sh @@ -265,4 +265,13 @@ test_expect_success 'able to set-tree to a subdirectory' " test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" " +test_expect_success 'git-svn works in a bare repository' ' + mkdir bare-repo && + ( cd bare-repo && + git init --bare && + GIT_DIR=. git svn init "$svnrepo" && + git svn fetch ) && + rm -rf bare-repo + ' + test_done From 19fb896f5b6f3e52370b43e4c9339bcbe4c0f2dd Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 2 Nov 2008 20:11:13 +0300 Subject: [PATCH 053/138] Windows: Make OpenSSH properly detect tty detachment. Apparently, CREATE_NO_WINDOW makes the OS tell the process that it has a console, but without actually creating the window. As a result, when git is started from GUI, ssh tries to ask its questions on the invisible console. This patch uses DETACHED_PROCESS instead, which clearly means that the process should be left without a console. The downside is that if the process manually calls AllocConsole, the window will appear. A similar thing might occur if it calls another console executable. Signed-off-by: Alexander Gavrilov Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- compat/mingw.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 09858f6c59..b534a8a472 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -536,12 +536,16 @@ static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env, * would normally create a console window. But * since we'll be redirecting std streams, we do * not need the console. + * It is necessary to use DETACHED_PROCESS + * instead of CREATE_NO_WINDOW to make ssh + * recognize that it has no console. */ - flags = CREATE_NO_WINDOW; + flags = DETACHED_PROCESS; } else { /* There is already a console. If we specified - * CREATE_NO_WINDOW here, too, Windows would + * DETACHED_PROCESS here, too, Windows would * disassociate the child from the console. + * The same is true for CREATE_NO_WINDOW. * Go figure! */ flags = 0; From ec26f098a6593bbd9d396fb7ee74368cdd3eeed3 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 6 Nov 2008 01:15:56 +0300 Subject: [PATCH 054/138] gitweb: Use single implementation of export_ok check. GitWeb source contains a special function that implements the export_ok check, but validate_project still uses a separate copy of essentially the same code. This patch makes it use the dedicated function, thus ensuring that all checks are done through a single code path. Signed-off-by: Alexander Gavrilov Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 9d1af7e557..68bdf62657 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -853,8 +853,7 @@ sub validate_project { my $input = shift || return undef; if (!validate_pathname($input) || !(-d "$projectroot/$input") || - !check_head_link("$projectroot/$input") || - ($export_ok && !(-e "$projectroot/$input/$export_ok")) || + !check_export_ok("$projectroot/$input") || ($strict_export && !project_in_list($input))) { return undef; } else { From dd7f5f105a1d4d094a96c5e3f251854f81106be0 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 6 Nov 2008 01:36:23 +0300 Subject: [PATCH 055/138] gitweb: Add a per-repository authorization hook. Add a configuration variable that can be used to specify an arbitrary subroutine that will be called in the same situations where $export_ok is checked, and its return value used to decide whether the repository is to be shown. This allows the user to implement custom authentication schemes, for example by issuing a subrequest through mod_perl and checking if Apache will authorize it. Signed-off-by: Alexander Gavrilov Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/INSTALL | 21 +++++++++++++++++++++ gitweb/gitweb.perl | 8 +++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gitweb/INSTALL b/gitweb/INSTALL index 26967e201a..18c9ce35e8 100644 --- a/gitweb/INSTALL +++ b/gitweb/INSTALL @@ -166,6 +166,27 @@ Gitweb repositories shows repositories only if this file exists in its object database (if directory has the magic file named $export_ok). +- Finally, it is possible to specify an arbitrary perl subroutine that + will be called for each project to determine if it can be exported. + The subroutine receives an absolute path to the project as its only + parameter. + + For example, if you use mod_perl to run the script, and have dumb + http protocol authentication configured for your repositories, you + can use the following hook to allow access only if the user is + authorized to read the files: + + $export_auth_hook = sub { + use Apache2::SubRequest (); + use Apache2::Const -compile => qw(HTTP_OK); + my $path = "$_[0]/HEAD"; + my $r = Apache2::RequestUtil->request; + my $sub = $r->lookup_file($path); + return $sub->filename eq $path + && $sub->status == Apache2::Const::HTTP_OK; + }; + + Generating projects list using gitweb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 68bdf62657..74672bffd8 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -95,6 +95,11 @@ our $default_projects_order = "project"; # (only effective if this variable evaluates to true) our $export_ok = "++GITWEB_EXPORT_OK++"; +# show repository only if this subroutine returns true +# when given the path to the project, for example: +# sub { return -e "$_[0]/git-daemon-export-ok"; } +our $export_auth_hook = undef; + # only allow viewing of repositories also shown on the overview page our $strict_export = "++GITWEB_STRICT_EXPORT++"; @@ -400,7 +405,8 @@ sub check_head_link { sub check_export_ok { my ($dir) = @_; return (check_head_link($dir) && - (!$export_ok || -e "$dir/$export_ok")); + (!$export_ok || -e "$dir/$export_ok") && + (!$export_auth_hook || $export_auth_hook->($dir))); } # process alternate names for backward compatibility From dde80d9c23e10592817f0c81e32a99a889a9bb8e Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 6 Nov 2008 01:10:07 +0300 Subject: [PATCH 056/138] gitweb: Fix mod_perl support. ModPerl::Registry precompiles scripts by wrapping them in a subroutine. This causes ordinary subroutines of the script to become nested, and warnings appear: gitweb.cgi: Variable "$path_info" will not stay shared This warning means that $path_info was declared as 'my', and thus according to the perl evaluation rules all nested subroutines will retain a reference to the instance of the variable used in the first invocation of the master script. When the script (i.e. the master meta-subroutine) is executed the second time, it will use a new instance, so the logic breaks. To avoid this it is necessary to declare all global variables as 'our', which places them at the package level. Signed-off-by: Alexander Gavrilov Acked-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 74672bffd8..06da30c501 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -30,7 +30,7 @@ our $my_uri = $cgi->url(-absolute => 1); # if we're called with PATH_INFO, we have to strip that # from the URL to find our real URL # we make $path_info global because it's also used later on -my $path_info = $ENV{"PATH_INFO"}; +our $path_info = $ENV{"PATH_INFO"}; if ($path_info) { $my_url =~ s,\Q$path_info\E$,,; $my_uri =~ s,\Q$path_info\E$,,; @@ -442,7 +442,7 @@ $projects_list ||= $projectroot; # together during validation: this allows subsequent uses (e.g. href()) to be # agnostic of the parameter origin -my %input_params = (); +our %input_params = (); # input parameters are stored with the long parameter name as key. This will # also be used in the href subroutine to convert parameters to their CGI @@ -452,7 +452,7 @@ my %input_params = (); # XXX: Warning: If you touch this, check the search form for updating, # too. -my @cgi_param_mapping = ( +our @cgi_param_mapping = ( project => "p", action => "a", file_name => "f", @@ -469,10 +469,10 @@ my @cgi_param_mapping = ( extra_options => "opt", search_use_regexp => "sr", ); -my %cgi_param_mapping = @cgi_param_mapping; +our %cgi_param_mapping = @cgi_param_mapping; # we will also need to know the possible actions, for validation -my %actions = ( +our %actions = ( "blame" => \&git_blame, "blobdiff" => \&git_blobdiff, "blobdiff_plain" => \&git_blobdiff_plain, @@ -504,7 +504,7 @@ my %actions = ( # finally, we have the hash of allowed extra_options for the commands that # allow them -my %allowed_options = ( +our %allowed_options = ( "--no-merges" => [ qw(rss atom log shortlog history) ], ); From 76f15947af78f526925810487f69fed35f6a7daf Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 2 Nov 2008 21:59:44 +0300 Subject: [PATCH 057/138] gitk: Add Return and Escape bindings to dialogs It is often more convenient to dismiss or accept a dialog using the keyboard, than by clicking buttons on the screen. This commit adds key binding to make it possible with gitk's dialogs. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gitk b/gitk index 3fe1b479b2..edef9e224e 100755 --- a/gitk +++ b/gitk @@ -1746,6 +1746,8 @@ proc show_error {w top msg} { pack $w.ok -side bottom -fill x bind $top "grab $top; focus $top" bind $top "destroy $top" + bind $top "destroy $top" + bind $top "destroy $top" tkwait window $top } @@ -1769,6 +1771,9 @@ proc confirm_popup msg { button $w.cancel -text [mc Cancel] -command "destroy $w" pack $w.cancel -side right -fill x bind $w "grab $w; focus $w" + bind $w "set confirm_ok 1; destroy $w" + bind $w "set confirm_ok 1; destroy $w" + bind $w "destroy $w" tkwait window $w return $confirm_ok } @@ -2611,6 +2616,7 @@ proc keys {} { -justify left -bg white -border 2 -relief groove pack $w.m -side top -fill both -padx 2 -pady 2 button $w.ok -text [mc "Close"] -command "destroy $w" -default active + bind $w [list destroy $w] pack $w.ok -side bottom bind $w "focus $w.ok" bind $w "destroy $w" @@ -3533,6 +3539,7 @@ proc vieweditor {top n title} { frame $top.buts button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n] button $top.buts.can -text [mc "Cancel"] -command [list destroy $top] + bind $top [list destroy $top] grid $top.buts.ok $top.buts.can grid columnconfigure $top.buts 0 -weight 1 -uniform a grid columnconfigure $top.buts 1 -weight 1 -uniform a @@ -7793,6 +7800,8 @@ proc mkpatch {} { frame $top.buts button $top.buts.gen -text [mc "Generate"] -command mkpatchgo button $top.buts.can -text [mc "Cancel"] -command mkpatchcan + bind $top mkpatchgo + bind $top mkpatchcan grid $top.buts.gen $top.buts.can grid columnconfigure $top.buts 0 -weight 1 -uniform a grid columnconfigure $top.buts 1 -weight 1 -uniform a @@ -7864,6 +7873,8 @@ proc mktag {} { frame $top.buts button $top.buts.gen -text [mc "Create"] -command mktaggo button $top.buts.can -text [mc "Cancel"] -command mktagcan + bind $top mktaggo + bind $top mktagcan grid $top.buts.gen $top.buts.can grid columnconfigure $top.buts 0 -weight 1 -uniform a grid columnconfigure $top.buts 1 -weight 1 -uniform a @@ -7967,6 +7978,8 @@ proc writecommit {} { frame $top.buts button $top.buts.gen -text [mc "Write"] -command wrcomgo button $top.buts.can -text [mc "Cancel"] -command wrcomcan + bind $top wrcomgo + bind $top wrcomcan grid $top.buts.gen $top.buts.can grid columnconfigure $top.buts 0 -weight 1 -uniform a grid columnconfigure $top.buts 1 -weight 1 -uniform a @@ -8014,6 +8027,8 @@ proc mkbranch {} { frame $top.buts button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top] button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}" + bind $top [list mkbrgo $top] + bind $top "catch {destroy $top}" grid $top.buts.go $top.buts.can grid columnconfigure $top.buts 0 -weight 1 -uniform a grid columnconfigure $top.buts 1 -weight 1 -uniform a @@ -8138,6 +8153,7 @@ proc resethead {} { button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w" pack $w.ok -side left -fill x -padx 20 -pady 20 button $w.cancel -text [mc Cancel] -command "destroy $w" + bind $w [list destroy $w] pack $w.cancel -side right -fill x -padx 20 -pady 20 bind $w "grab $w; focus $w" tkwait window $w @@ -8315,6 +8331,7 @@ proc showrefs {} { pack $top.f.l -side left grid $top.f - -sticky ew -pady 2 button $top.close -command [list destroy $top] -text [mc "Close"] + bind $top [list destroy $top] grid $top.close - grid columnconfigure $top 0 -weight 1 grid rowconfigure $top 0 -weight 1 @@ -9666,6 +9683,8 @@ proc choosefont {font which} { frame $top.buts button $top.buts.ok -text [mc "OK"] -command fontok -default active button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal + bind $top fontok + bind $top fontcan grid $top.buts.ok $top.buts.can grid columnconfigure $top.buts 0 -weight 1 -uniform a grid columnconfigure $top.buts 1 -weight 1 -uniform a @@ -9845,6 +9864,8 @@ proc doprefs {} { frame $top.buts button $top.buts.ok -text [mc "OK"] -command prefsok -default active button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal + bind $top prefsok + bind $top prefscan grid $top.buts.ok $top.buts.can grid columnconfigure $top.buts 0 -weight 1 -uniform a grid columnconfigure $top.buts 1 -weight 1 -uniform a From 84a76f18f0313832ccc9c2f0171ace3da64ffa4f Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 2 Nov 2008 21:59:45 +0300 Subject: [PATCH 058/138] gitk: Make gitk dialog windows transient Transient windows are always kept above their parent, and don't occupy any space in the taskbar, which is useful for dialogs. Also, when transient is used, it is important to bind windows to the correct parent. This commit adds transient annotations to all dialogs, ensures usage of the correct parent for error and confirmation popups, and, as a side job, makes gitk preserve the create tag dialog window in case of errors. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/gitk b/gitk index edef9e224e..41d3d2d98b 100755 --- a/gitk +++ b/gitk @@ -1751,19 +1751,19 @@ proc show_error {w top msg} { tkwait window $top } -proc error_popup msg { +proc error_popup {msg {owner .}} { set w .error toplevel $w - wm transient $w . + wm transient $w $owner show_error $w $w $msg } -proc confirm_popup msg { +proc confirm_popup {msg {owner .}} { global confirm_ok set confirm_ok 0 set w .confirm toplevel $w - wm transient $w . + wm transient $w $owner message $w.m -text $msg -justify center -aspect 400 pack $w.m -side top -fill x -padx 20 -pady 20 button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w" @@ -2546,6 +2546,7 @@ proc about {} { } toplevel $w wm title $w [mc "About gitk"] + wm transient $w . message $w.m -text [mc " Gitk - a commit viewer for git @@ -2574,6 +2575,7 @@ proc keys {} { } toplevel $w wm title $w [mc "Gitk key bindings"] + wm transient $w . message $w.m -text " [mc "Gitk key bindings:"] @@ -3503,6 +3505,7 @@ proc vieweditor {top n title} { toplevel $top wm title $top $title + wm transient $top . label $top.nl -text [mc "Name"] entry $top.name -width 20 -textvariable newviewname($n) grid $top.nl $top.name -sticky w -pady 5 @@ -3572,9 +3575,7 @@ proc newviewok {top n} { if {[catch { set newargs [shellsplit $newviewargs($n)] } err]} { - error_popup "[mc "Error in commit selection arguments:"] $err" - wm raise $top - focus $top + error_popup "[mc "Error in commit selection arguments:"] $err" $top return } set files {} @@ -7770,6 +7771,7 @@ proc mkpatch {} { set patchtop $top catch {destroy $top} toplevel $top + wm transient $top . label $top.title -text [mc "Generate patch"] grid $top.title - -pady 10 label $top.from -text [mc "From:"] @@ -7836,7 +7838,7 @@ proc mkpatchgo {} { set cmd [lrange $cmd 1 end] lappend cmd >$fname & if {[catch {eval exec $cmd} err]} { - error_popup "[mc "Error creating patch:"] $err" + error_popup "[mc "Error creating patch:"] $err" $patchtop } catch {destroy $patchtop} unset patchtop @@ -7856,6 +7858,7 @@ proc mktag {} { set mktagtop $top catch {destroy $top} toplevel $top + wm transient $top . label $top.title -text [mc "Create tag"] grid $top.title - -pady 10 label $top.id -text [mc "ID:"] @@ -7888,18 +7891,18 @@ proc domktag {} { set id [$mktagtop.sha1 get] set tag [$mktagtop.tag get] if {$tag == {}} { - error_popup [mc "No tag name specified"] - return + error_popup [mc "No tag name specified"] $mktagtop + return 0 } if {[info exists tagids($tag)]} { - error_popup [mc "Tag \"%s\" already exists" $tag] - return + error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop + return 0 } if {[catch { exec git tag $tag $id } err]} { - error_popup "[mc "Error creating tag:"] $err" - return + error_popup "[mc "Error creating tag:"] $err" $mktagtop + return 0 } set tagids($tag) $id @@ -7908,6 +7911,7 @@ proc domktag {} { addedtag $id dispneartags 0 run refill_reflist + return 1 } proc redrawtags {id} { @@ -7946,7 +7950,7 @@ proc mktagcan {} { } proc mktaggo {} { - domktag + if {![domktag]} return mktagcan } @@ -7957,6 +7961,7 @@ proc writecommit {} { set wrcomtop $top catch {destroy $top} toplevel $top + wm transient $top . label $top.title -text [mc "Write commit to file"] grid $top.title - -pady 10 label $top.id -text [mc "ID:"] @@ -7994,7 +7999,7 @@ proc wrcomgo {} { set cmd "echo $id | [$wrcomtop.cmd get]" set fname [$wrcomtop.fname get] if {[catch {exec sh -c $cmd >$fname &} err]} { - error_popup "[mc "Error writing commit:"] $err" + error_popup "[mc "Error writing commit:"] $err" $wrcomtop } catch {destroy $wrcomtop} unset wrcomtop @@ -8013,6 +8018,7 @@ proc mkbranch {} { set top .makebranch catch {destroy $top} toplevel $top + wm transient $top . label $top.title -text [mc "Create new branch"] grid $top.title - -pady 10 label $top.id -text [mc "ID:"] @@ -8044,12 +8050,12 @@ proc mkbrgo {top} { set cmdargs {} set old_id {} if {$name eq {}} { - error_popup [mc "Please specify a name for the new branch"] + error_popup [mc "Please specify a name for the new branch"] $top return } if {[info exists headids($name)]} { if {![confirm_popup [mc \ - "Branch '%s' already exists. Overwrite?" $name]]} { + "Branch '%s' already exists. Overwrite?" $name] $top]} { return } set old_id $headids($name) @@ -8310,6 +8316,7 @@ proc showrefs {} { } toplevel $top wm title $top [mc "Tags and heads: %s" [file tail [pwd]]] + wm transient $top . text $top.list -background $bgcolor -foreground $fgcolor \ -selectbackground $selectbgcolor -font mainfont \ -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \ @@ -9637,6 +9644,7 @@ proc mkfontdisp {font top which} { proc choosefont {font which} { global fontparam fontlist fonttop fontattr + global prefstop set fontparam(which) $which set fontparam(font) $font @@ -9650,6 +9658,7 @@ proc choosefont {font which} { font create sample eval font config sample [font actual $font] toplevel $top + wm transient $top $prefstop wm title $top [mc "Gitk font chooser"] label $top.l -textvariable fontparam(which) pack $top.l -side top @@ -9766,6 +9775,7 @@ proc doprefs {} { } toplevel $top wm title $top [mc "Gitk preferences"] + wm transient $top . label $top.ldisp -text [mc "Commit list display options"] grid $top.ldisp - -sticky w -pady 10 label $top.spacer -text " " From 15e350552db1c0e8ede0af4f1f07dbbc9090e420 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 2 Nov 2008 21:59:47 +0300 Subject: [PATCH 059/138] gitk: Make cherry-pick call git-citool on conflicts Now that git-gui has facilities to help users resolve conflicts, it makes sense to launch it from other GUI tools when they happen. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/gitk b/gitk index 41d3d2d98b..4168648b52 100755 --- a/gitk +++ b/gitk @@ -8088,6 +8088,32 @@ proc mkbrgo {top} { } } +proc exec_citool {tool_args {baseid {}}} { + global commitinfo env + + set save_env [array get env GIT_AUTHOR_*] + + if {$baseid ne {}} { + if {![info exists commitinfo($baseid)]} { + getcommit $baseid + } + set author [lindex $commitinfo($baseid) 1] + set date [lindex $commitinfo($baseid) 2] + if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \ + $author author name email] + && $date ne {}} { + set env(GIT_AUTHOR_NAME) $name + set env(GIT_AUTHOR_EMAIL) $email + set env(GIT_AUTHOR_DATE) $date + } + } + + eval exec git citool $tool_args & + + array unset env GIT_AUTHOR_* + array set env $save_env +} + proc cherrypick {} { global rowmenuid curview global mainhead mainheadid @@ -8106,7 +8132,19 @@ proc cherrypick {} { # no error occurs, and exec takes that as an indication of error... if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} { notbusy cherrypick - error_popup $err + if {[regexp -line \ + {Entry '(.*)' would be overwritten by merge} $err msg fname]} { + error_popup [mc "Cherry-pick failed: +file '%s' had local modifications. + +Please commit, reset or stash your changes." $fname] + } elseif {[regexp -line {^CONFLICT \(.*\):} $err msg]} { + # Force citool to read MERGE_MSG + file delete [file join [gitdir] "GITGUI_MSG"] + exec_citool {} $rowmenuid + } else { + error_popup $err + } return } set newhead [exec git rev-parse HEAD] From 887a791f113a09a56bb4916243463481a51d86a4 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Sat, 8 Nov 2008 21:37:09 +1100 Subject: [PATCH 060/138] gitk: Improve cherry-pick error handling This adds to the regexps that are used to work out what sort of error we encountered in trying to do a cherry-pick so that it recognizes some additional common error messages. It adds a confirmation dialog when the error is a merge conflict so the user can choose whether or not to run git citool. Finally, it arranges to update the display after a cherry-pick failed so that any local changes made by the cherry-pick become visible. Signed-off-by: Paul Mackerras --- gitk | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/gitk b/gitk index 4168648b52..58ad47d183 100755 --- a/gitk +++ b/gitk @@ -8133,18 +8133,25 @@ proc cherrypick {} { if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} { notbusy cherrypick if {[regexp -line \ - {Entry '(.*)' would be overwritten by merge} $err msg fname]} { - error_popup [mc "Cherry-pick failed: -file '%s' had local modifications. - -Please commit, reset or stash your changes." $fname] - } elseif {[regexp -line {^CONFLICT \(.*\):} $err msg]} { - # Force citool to read MERGE_MSG - file delete [file join [gitdir] "GITGUI_MSG"] - exec_citool {} $rowmenuid + {Entry '(.*)' (would be overwritten by merge|not uptodate)} \ + $err msg fname]} { + error_popup [mc "Cherry-pick failed because of local changes\ + to file '%s'.\nPlease commit, reset or stash\ + your changes and try again." $fname] + } elseif {[regexp -line \ + {^(CONFLICT \(.*\):|Automatic cherry-pick failed)} \ + $err]} { + if {[confirm_popup [mc "Cherry-pick failed because of merge\ + conflict.\nDo you wish to run git citool to\ + resolve it?"]]} { + # Force citool to read MERGE_MSG + file delete [file join [gitdir] "GITGUI_MSG"] + exec_citool {} $rowmenuid + } } else { error_popup $err } + run updatecommits return } set newhead [exec git rev-parse HEAD] From 218a900bd8efd0d49f8a0d9491aa4786a998d4f4 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 2 Nov 2008 21:59:48 +0300 Subject: [PATCH 061/138] gitk: Implement a user-friendly Edit View dialog Originally gitk required the user to specify all limiting options manually in the same field with the list of commits. It is rather unfriendly for new users, who may not know which options can be used, or, indeed, that it is possible to specify them at all. This commit modifies the dialog to present the most useful options as individual fields. Note that options that may be useful to an extent, but produce a severely broken view, are deliberately not included. It is still possible to specify options in the commit list field, but when the dialog is reopened, they will be extracted into their own separate fields. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 203 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 161 insertions(+), 42 deletions(-) diff --git a/gitk b/gitk index 58ad47d183..2048798bcf 100755 --- a/gitk +++ b/gitk @@ -3467,8 +3467,8 @@ proc shellsplit {str} { # Code to implement multiple views proc newview {ishighlight} { - global nextviewnum newviewname newviewperm newishighlight - global newviewargs revtreeargs viewargscmd newviewargscmd curview + global nextviewnum newviewname newishighlight + global revtreeargs viewargscmd newviewopts curview set newishighlight $ishighlight set top .gitkview @@ -3477,59 +3477,173 @@ proc newview {ishighlight} { return } set newviewname($nextviewnum) "[mc "View"] $nextviewnum" - set newviewperm($nextviewnum) 0 - set newviewargs($nextviewnum) [shellarglist $revtreeargs] - set newviewargscmd($nextviewnum) $viewargscmd($curview) + set newviewopts($nextviewnum,perm) 0 + set newviewopts($nextviewnum,cmd) $viewargscmd($curview) + decode_view_opts $nextviewnum $revtreeargs vieweditor $top $nextviewnum [mc "Gitk view definition"] } +set known_view_options { + {perm b . {} {mc "Remember this view"}} + {args t50= + {} {mc "Commits to include (arguments to git log):"}} + {all b * "--all" {mc "Use all refs"}} + {dorder b . {"--date-order" "-d"} {mc "Strictly sort by date"}} + {lright b . "--left-right" {mc "Mark branch sides"}} + {since t15 + {"--since=*" "--after=*"} {mc "Since date:"}} + {until t15 . {"--until=*" "--before=*"} {mc "Until date:"}} + {limit t10 + "--max-count=*" {mc "Max count:"}} + {skip t10 . "--skip=*" {mc "Skip:"}} + {first b . "--first-parent" {mc "Limit to first parent"}} + {cmd t50= + {} {mc "Command to generate more commits to include:"}} + } + +proc encode_view_opts {n} { + global known_view_options newviewopts + + set rargs [list] + foreach opt $known_view_options { + set patterns [lindex $opt 3] + if {$patterns eq {}} continue + set pattern [lindex $patterns 0] + + set val $newviewopts($n,[lindex $opt 0]) + + if {[lindex $opt 1] eq "b"} { + if {$val} { + lappend rargs $pattern + } + } else { + set val [string trim $val] + if {$val ne {}} { + set pfix [string range $pattern 0 end-1] + lappend rargs $pfix$val + } + } + } + return [concat $rargs [shellsplit $newviewopts($n,args)]] +} + +proc decode_view_opts {n view_args} { + global known_view_options newviewopts + + foreach opt $known_view_options { + if {[lindex $opt 1] eq "b"} { + set val 0 + } else { + set val {} + } + set newviewopts($n,[lindex $opt 0]) $val + } + set oargs [list] + foreach arg $view_args { + if {[regexp -- {^-([0-9]+)$} $arg arg cnt] + && ![info exists found(limit)]} { + set newviewopts($n,limit) $cnt + set found(limit) 1 + continue + } + catch { unset val } + foreach opt $known_view_options { + set id [lindex $opt 0] + if {[info exists found($id)]} continue + foreach pattern [lindex $opt 3] { + if {![string match $pattern $arg]} continue + if {[lindex $opt 1] ne "b"} { + set size [string length $pattern] + set val [string range $arg [expr {$size-1}] end] + } else { + set val 1 + } + set newviewopts($n,$id) $val + set found($id) 1 + break + } + if {[info exists val]} break + } + if {[info exists val]} continue + lappend oargs $arg + } + set newviewopts($n,args) [shellarglist $oargs] +} + proc editview {} { global curview - global viewname viewperm newviewname newviewperm - global viewargs newviewargs viewargscmd newviewargscmd + global viewname viewperm newviewname newviewopts + global viewargs viewargscmd set top .gitkvedit-$curview if {[winfo exists $top]} { raise $top return } - set newviewname($curview) $viewname($curview) - set newviewperm($curview) $viewperm($curview) - set newviewargs($curview) [shellarglist $viewargs($curview)] - set newviewargscmd($curview) $viewargscmd($curview) + set newviewname($curview) $viewname($curview) + set newviewopts($curview,perm) $viewperm($curview) + set newviewopts($curview,cmd) $viewargscmd($curview) + decode_view_opts $curview $viewargs($curview) vieweditor $top $curview "Gitk: edit view $viewname($curview)" } proc vieweditor {top n title} { - global newviewname newviewperm viewfiles bgcolor + global newviewname newviewopts viewfiles bgcolor + global known_view_options toplevel $top wm title $top $title wm transient $top . + + # View name + frame $top.nfr label $top.nl -text [mc "Name"] entry $top.name -width 20 -textvariable newviewname($n) - grid $top.nl $top.name -sticky w -pady 5 - checkbutton $top.perm -text [mc "Remember this view"] \ - -variable newviewperm($n) - grid $top.perm - -pady 5 -sticky w - message $top.al -aspect 1000 \ - -text [mc "Commits to include (arguments to git log):"] - grid $top.al - -sticky w -pady 5 - entry $top.args -width 50 -textvariable newviewargs($n) \ - -background $bgcolor - grid $top.args - -sticky ew -padx 5 + pack $top.nfr -in $top -fill x -pady 5 -padx 3 + pack $top.nl -in $top.nfr -side left -padx {0 30} + pack $top.name -in $top.nfr -side left - message $top.ac -aspect 1000 \ - -text [mc "Command to generate more commits to include:"] - grid $top.ac - -sticky w -pady 5 - entry $top.argscmd -width 50 -textvariable newviewargscmd($n) \ - -background white - grid $top.argscmd - -sticky ew -padx 5 + # View options + set cframe $top.nfr + set cexpand 0 + set cnt 0 + foreach opt $known_view_options { + set id [lindex $opt 0] + set type [lindex $opt 1] + set flags [lindex $opt 2] + set title [eval [lindex $opt 4]] + set lxpad 0 - message $top.l -aspect 1000 \ + if {$flags eq "+" || $flags eq "*"} { + set cframe $top.fr$cnt + incr cnt + frame $cframe + pack $cframe -in $top -fill x -pady 3 -padx 3 + set cexpand [expr {$flags eq "*"}] + } else { + set lxpad 5 + } + + if {$type eq "b"} { + checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id) + pack $cframe.c_$id -in $cframe -side left \ + -padx [list $lxpad 0] -expand $cexpand -anchor w + } elseif {[regexp {^t(\d+)$} $type type sz]} { + message $cframe.l_$id -aspect 1500 -text $title + entry $cframe.e_$id -width $sz -background $bgcolor \ + -textvariable newviewopts($n,$id) + pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0] + pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x + } elseif {[regexp {^t(\d+)=$} $type type sz]} { + message $cframe.l_$id -aspect 1500 -text $title + entry $cframe.e_$id -width $sz -background $bgcolor \ + -textvariable newviewopts($n,$id) + pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w + pack $cframe.e_$id -in $cframe -side top -fill x + } + } + + # Path list + message $top.l -aspect 1500 \ -text [mc "Enter files and directories to include, one per line:"] - grid $top.l - -sticky w - text $top.t -width 40 -height 10 -background $bgcolor -font uifont + pack $top.l -in $top -side top -pady [list 7 0] -anchor w -padx 3 + text $top.t -width 40 -height 5 -background $bgcolor -font uifont if {[info exists viewfiles($n)]} { foreach f $viewfiles($n) { $top.t insert end $f @@ -3538,15 +3652,19 @@ proc vieweditor {top n title} { $top.t delete {end - 1c} end $top.t mark set insert 0.0 } - grid $top.t - -sticky ew -padx 5 + pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3 frame $top.buts button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n] + button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1] button $top.buts.can -text [mc "Cancel"] -command [list destroy $top] + bind $top [list newviewok $top $n] + bind $top [list newviewok $top $n 1] bind $top [list destroy $top] - grid $top.buts.ok $top.buts.can + grid $top.buts.ok $top.buts.apply $top.buts.can grid columnconfigure $top.buts 0 -weight 1 -uniform a grid columnconfigure $top.buts 1 -weight 1 -uniform a - grid $top.buts - -pady 10 -sticky ew + grid columnconfigure $top.buts 2 -weight 1 -uniform a + pack $top.buts -in $top -side top -fill x focus $top.t } @@ -3567,13 +3685,13 @@ proc allviewmenus {n op args} { # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args } -proc newviewok {top n} { +proc newviewok {top n {apply 0}} { global nextviewnum newviewperm newviewname newishighlight global viewname viewfiles viewperm selectedview curview - global viewargs newviewargs viewargscmd newviewargscmd viewhlmenu + global viewargs viewargscmd newviewopts viewhlmenu if {[catch { - set newargs [shellsplit $newviewargs($n)] + set newargs [encode_view_opts $n] } err]} { error_popup "[mc "Error in commit selection arguments:"] $err" $top return @@ -3589,10 +3707,10 @@ proc newviewok {top n} { # creating a new view incr nextviewnum set viewname($n) $newviewname($n) - set viewperm($n) $newviewperm($n) + set viewperm($n) $newviewopts($n,perm) set viewfiles($n) $files set viewargs($n) $newargs - set viewargscmd($n) $newviewargscmd($n) + set viewargscmd($n) $newviewopts($n,cmd) addviewmenu $n if {!$newishighlight} { run showview $n @@ -3601,7 +3719,7 @@ proc newviewok {top n} { } } else { # editing an existing view - set viewperm($n) $newviewperm($n) + set viewperm($n) $newviewopts($n,perm) if {$newviewname($n) ne $viewname($n)} { set viewname($n) $newviewname($n) doviewmenu .bar.view 5 [list showview $n] \ @@ -3610,15 +3728,16 @@ proc newviewok {top n} { # entryconf [list -label $viewname($n) -value $viewname($n)] } if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \ - $newviewargscmd($n) ne $viewargscmd($n)} { + $newviewopts($n,cmd) ne $viewargscmd($n)} { set viewfiles($n) $files set viewargs($n) $newargs - set viewargscmd($n) $newviewargscmd($n) + set viewargscmd($n) $newviewopts($n,cmd) if {$curview == $n} { run reloadcommits } } } + if {$apply} return catch {destroy $top} } From 9b28d55401a529ff08c709f42f66e765c93b0a20 Mon Sep 17 00:00:00 2001 From: Davide Libenzi Date: Fri, 7 Nov 2008 21:24:33 -0800 Subject: [PATCH 062/138] xdiff: give up scanning similar lines early In a corner case of large files whose lines do not match uniquely, the loop to eliminate a line that matches multiple locations adjacent to a run of lines that do not uniquely match wasted too much cycles. Fix this by giving up early after scanning 100 lines in both direction. Signed-off-by: Junio C Hamano --- xdiff/xprepare.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c index e87ab57c65..a43aa72cd0 100644 --- a/xdiff/xprepare.c +++ b/xdiff/xprepare.c @@ -23,10 +23,9 @@ #include "xinclude.h" - #define XDL_KPDIS_RUN 4 #define XDL_MAX_EQLIMIT 1024 - +#define XDL_SIMSCAN_WINDOW 100 typedef struct s_xdlclass { @@ -312,6 +311,18 @@ void xdl_free_env(xdfenv_t *xe) { static int xdl_clean_mmatch(char const *dis, long i, long s, long e) { long r, rdis0, rpdis0, rdis1, rpdis1; + /* + * Limits the window the is examined during the similar-lines + * scan. The loops below stops when dis[i - r] == 1 (line that + * has no match), but there are corner cases where the loop + * proceed all the way to the extremities by causing huge + * performance penalties in case of big files. + */ + if (i - s > XDL_SIMSCAN_WINDOW) + s = i - XDL_SIMSCAN_WINDOW; + if (e - i > XDL_SIMSCAN_WINDOW) + e = i + XDL_SIMSCAN_WINDOW; + /* * Scans the lines before 'i' to find a run of lines that either * have no match (dis[j] == 0) or have multiple matches (dis[j] > 1). From 6abe9c87c78d4925e12e609f4f26447c6a579b9e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 7 Nov 2008 17:09:55 -0500 Subject: [PATCH 063/138] t5400: expect success for denying deletion Commit a240de11 introduced this test and the code to make it successful. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t5400-send-pack.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 6fe2f87b85..da69f087b4 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -103,7 +103,7 @@ unset GIT_CONFIG GIT_CONFIG_LOCAL HOME=`pwd`/no-such-directory export HOME ;# this way we force the victim/.git/config to be used. -test_expect_failure \ +test_expect_success \ 'pushing a delete should be denied with denyDeletes' ' cd victim && git config receive.denyDeletes true && From ee5391c73efaf6dea06f769157fa1650d0bdce31 Mon Sep 17 00:00:00 2001 From: Quy Tonthat Date: Sat, 13 Sep 2008 02:22:44 +1000 Subject: [PATCH 064/138] Update RPM spec for the new location of git-cvsserver. git-cvsserver has been moved from libexecdir to bindir. Signed-off-by: Quy Tonthat Signed-off-by: Junio C Hamano --- git.spec.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git.spec.in b/git.spec.in index c6492e5be2..6733b6f555 100644 --- a/git.spec.in +++ b/git.spec.in @@ -145,6 +145,7 @@ rm -rf $RPM_BUILD_ROOT %files cvs %defattr(-,root,root) %doc Documentation/*git-cvs*.txt +%{_bindir}/git-cvsserver %{_libexecdir}/git-core/*cvs* %{!?_without_docs: %{_mandir}/man1/*cvs*.1*} %{!?_without_docs: %doc Documentation/*git-cvs*.html } @@ -188,6 +189,9 @@ rm -rf $RPM_BUILD_ROOT # No files for you! %changelog +* Fri Sep 12 2008 Quy Tonthat +- move git-cvsserver to bindir. + * Sun Jun 15 2008 Junio C Hamano - Remove curl from Requires list. From 7c181d627c136cbc67ef0f722e74e34017e662f0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 8 Nov 2008 17:33:50 -0800 Subject: [PATCH 065/138] GIT 1.6.0.4 Signed-off-by: Junio C Hamano --- Documentation/RelNotes-1.6.0.4.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Documentation/RelNotes-1.6.0.4.txt b/Documentation/RelNotes-1.6.0.4.txt index db1002e8c7..fba3f30a89 100644 --- a/Documentation/RelNotes-1.6.0.4.txt +++ b/Documentation/RelNotes-1.6.0.4.txt @@ -16,6 +16,9 @@ Fixes since v1.6.0.3 * 'git push --mirror' tried and failed to push the stash; there is no point in sending it to begin with. +* 'git push' did not update the remote tracking reference if the corresponding + ref on the remote end happened to be already up to date. + * 'git pull $there $branch:$current_branch' did not work when you were on a branch yet to be born. @@ -29,12 +32,8 @@ Fixes since v1.6.0.3 * 'git svn' used deprecated 'git-foo' form of subcommand invocaition. +* 'git update-ref -d' to remove a reference did not honor --no-deref option. + * Plugged small memleaks here and there. * Also contains many documentation updates. - --- -exec >/var/tmp/1 -O=v1.6.0.3-34-gf6276b7 -echo O=$(git describe maint) -git shortlog --no-merges $O..maint From 323e00fd46afb9293b25ee85f061ce11a2f95ca6 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 8 Nov 2008 13:03:59 +0100 Subject: [PATCH 066/138] checkout: Don't crash when switching away from an invalid branch. When using alternates, it is possible for HEAD to end up pointing to an invalid commit. git checkout should be able to recover from that situation without crashing. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- builtin-checkout.c | 8 ++++---- t/t2011-checkout-invalid-head.sh | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100755 t/t2011-checkout-invalid-head.sh diff --git a/builtin-checkout.c b/builtin-checkout.c index 1deda927cd..05eee4ecc7 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -32,7 +32,7 @@ static int post_checkout_hook(struct commit *old, struct commit *new, memset(&proc, 0, sizeof(proc)); argv[0] = name; - argv[1] = xstrdup(sha1_to_hex(old->object.sha1)); + argv[1] = xstrdup(sha1_to_hex(old ? old->object.sha1 : null_sha1)); argv[2] = xstrdup(sha1_to_hex(new->object.sha1)); argv[3] = changed ? "1" : "0"; argv[4] = NULL; @@ -360,10 +360,10 @@ static void update_refs_for_switch(struct checkout_opts *opts, strbuf_init(&msg, 0); old_desc = old->name; - if (!old_desc) + if (!old_desc && old->commit) old_desc = sha1_to_hex(old->commit->object.sha1); strbuf_addf(&msg, "checkout: moving from %s to %s", - old_desc, new->name); + old_desc ? old_desc : "(invalid)", new->name); if (new->path) { create_symref("HEAD", new->path, msg.buf); @@ -419,7 +419,7 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new) * a new commit, we want to mention the old commit once more * to remind the user that it might be lost. */ - if (!opts->quiet && !old.path && new->commit != old.commit) + if (!opts->quiet && !old.path && old.commit && new->commit != old.commit) describe_detached_head("Previous HEAD position was", old.commit); if (!old.commit) { diff --git a/t/t2011-checkout-invalid-head.sh b/t/t2011-checkout-invalid-head.sh new file mode 100755 index 0000000000..764bb0a6bc --- /dev/null +++ b/t/t2011-checkout-invalid-head.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +test_description='checkout switching away from an invalid branch' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo hello >world && + git add world && + git commit -m initial +' + +test_expect_success 'checkout master from invalid HEAD' ' + echo 0000000000000000000000000000000000000000 >.git/HEAD && + git checkout master -- +' + +test_done From b2dc968e60c94189805228f5d99786bd50189583 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 7 Nov 2008 17:20:33 -0500 Subject: [PATCH 067/138] t5516: refactor oddball tests t5516 sets up some utility functions for starting each test with a clean slate. However, there were a few tests added that do not use these functions, but instead make their own repositories. Let's bring these in line with the rest of the tests. Not only do we reduce the number of lines, but these tests will benefit from any further enhancements to the utility scripts. The conversion is pretty straightforward. Most of the tests created a parent/child clone relationship, for which we now use 'testrepo' as the parent. One test looked in testrepo, but relied on previous tests to have set it up; it now sets up testrepo explicitly, which makes it a bit more robust to changes in the script, as well. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t5516-fetch-push.sh | 50 ++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 598664ce7f..3411107651 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -39,6 +39,11 @@ mk_test () { ) } +mk_child() { + rm -rf "$1" && + git clone testrepo "$1" +} + check_push_result () { ( cd testrepo && @@ -425,13 +430,10 @@ test_expect_success 'push with dry-run' ' test_expect_success 'push updates local refs' ' - rm -rf parent child && - mkdir parent && - (cd parent && git init && - echo one >foo && git add foo && git commit -m one) && - git clone parent child && + mk_test heads/master && + mk_child child && (cd child && - echo two >foo && git commit -a -m two && + git pull .. master && git push && test $(git rev-parse master) = $(git rev-parse remotes/origin/master)) @@ -439,15 +441,10 @@ test_expect_success 'push updates local refs' ' test_expect_success 'push updates up-to-date local refs' ' - rm -rf parent child && - mkdir parent && - (cd parent && git init && - echo one >foo && git add foo && git commit -m one) && - git clone parent child1 && - git clone parent child2 && - (cd child1 && - echo two >foo && git commit -a -m two && - git push) && + mk_test heads/master && + mk_child child1 && + mk_child child2 && + (cd child1 && git pull .. master && git push) && (cd child2 && git pull ../child1 master && git push && @@ -457,11 +454,8 @@ test_expect_success 'push updates up-to-date local refs' ' test_expect_success 'push preserves up-to-date packed refs' ' - rm -rf parent child && - mkdir parent && - (cd parent && git init && - echo one >foo && git add foo && git commit -m one) && - git clone parent child && + mk_test heads/master && + mk_child child && (cd child && git push && ! test -f .git/refs/remotes/origin/master) @@ -470,15 +464,13 @@ test_expect_success 'push preserves up-to-date packed refs' ' test_expect_success 'push does not update local refs on failure' ' - rm -rf parent child && - mkdir parent && - (cd parent && git init && - echo one >foo && git add foo && git commit -m one && - echo exit 1 >.git/hooks/pre-receive && - chmod +x .git/hooks/pre-receive) && - git clone parent child && + mk_test heads/master && + mk_child child && + mkdir testrepo/.git/hooks && + echo exit 1 >testrepo/.git/hooks/pre-receive && + chmod +x testrepo/.git/hooks/pre-receive && (cd child && - echo two >foo && git commit -a -m two && + git pull .. master test_must_fail git push && test $(git rev-parse master) != \ $(git rev-parse remotes/origin/master)) @@ -487,7 +479,7 @@ test_expect_success 'push does not update local refs on failure' ' test_expect_success 'allow deleting an invalid remote ref' ' - pwd && + mk_test heads/master && rm -f testrepo/.git/objects/??/* && git push testrepo :refs/heads/master && (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master) From 986e82396ab23b9e5f4eab7183bbf76e7bc756d0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 8 Nov 2008 20:49:27 -0500 Subject: [PATCH 068/138] receive-pack: detect push to current branch of non-bare repo Pushing into the currently checked out branch of a non-bare repository can be dangerous; the HEAD then loses sync with the index and working tree, and it looks in the receiving repo as if the pushed changes have been reverted in the index (since they were never there in the first place). This patch adds a safety valve that checks for this condition and either generates a warning or denies the update. We trigger the check only on a non-bare repository, since a bare repo does not have a working tree (and in fact, pushing to the HEAD branch is a common workflow for publishing repositories). The behavior is configurable via receive.denyCurrentBranch, defaulting to "warn" so as not to break existing setups (though it may, after a deprecation period, switch to "refuse" by default). For users who know what they are doing and want to silence the warning (e.g., because they have a post-receive hook that reconciles the HEAD and working tree), they can turn off the warning by setting it to false or "ignore". Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/config.txt | 9 ++++++ builtin-receive-pack.c | 59 ++++++++++++++++++++++++++++++++++++++++ t/t5516-fetch-push.sh | 37 +++++++++++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index 965ed746da..32dcd643d2 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -1198,6 +1198,15 @@ receive.denyNonFastForwards:: even if that push is forced. This configuration variable is set when initializing a shared repository. +receive.denyCurrentBranch:: + If set to true or "refuse", receive-pack will deny a ref update + to the currently checked out branch of a non-bare repository. + Such a push is potentially dangerous because it brings the HEAD + out of sync with the index and working tree. If set to "warn", + print a warning of such a push to stderr, but allow the push to + proceed. If set to false or "ignore", allow such pushes with no + message. Defaults to "warn". + transfer.unpackLimit:: When `fetch.unpackLimit` or `receive.unpackLimit` are not set, the value of this variable is used instead. diff --git a/builtin-receive-pack.c b/builtin-receive-pack.c index 7f9f134806..db67c3162c 100644 --- a/builtin-receive-pack.c +++ b/builtin-receive-pack.c @@ -11,8 +11,15 @@ static const char receive_pack_usage[] = "git-receive-pack "; +enum deny_action { + DENY_IGNORE, + DENY_WARN, + DENY_REFUSE, +}; + static int deny_deletes = 0; static int deny_non_fast_forwards = 0; +static enum deny_action deny_current_branch = DENY_WARN; static int receive_fsck_objects; static int receive_unpack_limit = -1; static int transfer_unpack_limit = -1; @@ -22,6 +29,21 @@ static int report_status; static char capabilities[] = " report-status delete-refs "; static int capabilities_sent; +static enum deny_action parse_deny_action(const char *var, const char *value) +{ + if (value) { + if (!strcasecmp(value, "ignore")) + return DENY_IGNORE; + if (!strcasecmp(value, "warn")) + return DENY_WARN; + if (!strcasecmp(value, "refuse")) + return DENY_REFUSE; + } + if (git_config_bool(var, value)) + return DENY_REFUSE; + return DENY_IGNORE; +} + static int receive_pack_config(const char *var, const char *value, void *cb) { if (strcmp(var, "receive.denydeletes") == 0) { @@ -49,6 +71,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb) return 0; } + if (!strcmp(var, "receive.denycurrentbranch")) { + deny_current_branch = parse_deny_action(var, value); + return 0; + } + return git_default_config(var, value, cb); } @@ -173,6 +200,20 @@ static int run_update_hook(struct command *cmd) return hook_status(run_command(&proc), update_hook); } +static int is_ref_checked_out(const char *ref) +{ + unsigned char sha1[20]; + const char *head; + + if (is_bare_repository()) + return 0; + + head = resolve_ref("HEAD", sha1, 0, NULL); + if (!head) + return 0; + return !strcmp(head, ref); +} + static const char *update(struct command *cmd) { const char *name = cmd->ref_name; @@ -186,6 +227,24 @@ static const char *update(struct command *cmd) return "funny refname"; } + switch (deny_current_branch) { + case DENY_IGNORE: + break; + case DENY_WARN: + if (!is_ref_checked_out(name)) + break; + warning("updating the currently checked out branch; this may" + " cause confusion,\n" + "as the index and working tree do not reflect changes" + " that are now in HEAD."); + break; + case DENY_REFUSE: + if (!is_ref_checked_out(name)) + break; + error("refusing to update checked out branch: %s", name); + return "branch is currently checked out"; + } + if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) { error("unpack should have generated %s, " "but I can't find it!", sha1_to_hex(new_sha1)); diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 3411107651..a6532cb29e 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -486,4 +486,41 @@ test_expect_success 'allow deleting an invalid remote ref' ' ' +test_expect_success 'warn on push to HEAD of non-bare repository' ' + mk_test heads/master + (cd testrepo && + git checkout master && + git config receive.denyCurrentBranch warn) && + git push testrepo master 2>stderr && + grep "warning.*this may cause confusion" stderr +' + +test_expect_success 'deny push to HEAD of non-bare repository' ' + mk_test heads/master + (cd testrepo && + git checkout master && + git config receive.denyCurrentBranch true) && + test_must_fail git push testrepo master +' + +test_expect_success 'allow push to HEAD of bare repository (bare)' ' + mk_test heads/master + (cd testrepo && + git checkout master && + git config receive.denyCurrentBranch true && + git config core.bare true) && + git push testrepo master 2>stderr && + ! grep "warning.*this may cause confusion" stderr +' + +test_expect_success 'allow push to HEAD of non-bare repository (config)' ' + mk_test heads/master + (cd testrepo && + git checkout master && + git config receive.denyCurrentBranch false + ) && + git push testrepo master 2>stderr && + ! grep "warning.*this may cause confusion" stderr +' + test_done From 6514aa36d27165d088dd4a2c3046c635f3ca85be Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 9 Nov 2008 14:46:35 +0100 Subject: [PATCH 069/138] Documentation: rev-list: change a few instances of "git-cmd" to "git cmd" Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/rev-list-options.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 5df35ce519..1023ac2b59 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -285,7 +285,7 @@ See also linkgit:git-reflog[1]. History Simplification ~~~~~~~~~~~~~~~~~~~~~~ -When optional paths are given, 'git-rev-list' simplifies commits with +When optional paths are given, 'git rev-list' simplifies commits with various strategies, according to the options you have selected. Suppose you specified `foo` as the . We shall call commits @@ -424,14 +424,14 @@ Limit output to the one commit object which is roughly halfway between the included and excluded commits. Thus, if ----------------------------------------------------------------------- - $ git-rev-list --bisect foo ^bar ^baz + $ git rev-list --bisect foo ^bar ^baz ----------------------------------------------------------------------- outputs 'midpoint', the output of the two commands ----------------------------------------------------------------------- - $ git-rev-list foo ^midpoint - $ git-rev-list midpoint ^bar ^baz + $ git rev-list foo ^midpoint + $ git rev-list midpoint ^bar ^baz ----------------------------------------------------------------------- would be of roughly the same length. Finding the change which From 5bcce8494a2ee09250404b8b086cbd62f9506703 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 9 Nov 2008 14:53:14 +0100 Subject: [PATCH 070/138] Documentation: bisect: change a few instances of "git-cmd" to "git cmd" Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-bisect.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/git-bisect.txt b/Documentation/git-bisect.txt index c7981efcd9..39034ec7d6 100644 --- a/Documentation/git-bisect.txt +++ b/Documentation/git-bisect.txt @@ -26,7 +26,7 @@ on the subcommand: git bisect log git bisect run ... -This command uses 'git-rev-list --bisect' to help drive the +This command uses 'git rev-list --bisect' to help drive the binary search process to find which change introduced a bug, given an old "good" commit object name and a later "bad" commit object name. @@ -101,7 +101,7 @@ $ git bisect visualize to see the currently remaining suspects in 'gitk'. `visualize` is a bit too long to type and `view` is provided as a synonym. -If 'DISPLAY' environment variable is not set, 'git-log' is used +If 'DISPLAY' environment variable is not set, 'git log' is used instead. You can even give command line options such as `-p` and `--stat`. @@ -215,7 +215,7 @@ tweaks (e.g., s/#define DEBUG 0/#define DEBUG 1/ in a header file, or work around other problem this bisection is not interested in") applied to the revision being tested. -To cope with such a situation, after the inner 'git-bisect' finds the +To cope with such a situation, after the inner 'git bisect' finds the next revision to test, with the "run" script, you can apply that tweak before compiling, run the real test, and after the test decides if the revision (possibly with the needed tweaks) passed the test, rewind the From d2d188d92203997d260e8a21695b85c18b002d8f Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 9 Nov 2008 15:25:55 +0100 Subject: [PATCH 071/138] bisect: fix missing "exit" Check to see given bad/good/skip sets are valid commit and to exit otherwise was broken by 6a54d97 (bisect: remove "checkout_done" variable used when checking merge bases, 2008-09-06). Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- git-bisect.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-bisect.sh b/git-bisect.sh index 79de7017e8..0d0e278c92 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -455,7 +455,7 @@ bisect_next() { good=$(git for-each-ref --format='^%(objectname)' \ "refs/bisect/good-*" | tr '\012' ' ') && skip=$(git for-each-ref --format='%(objectname)' \ - "refs/bisect/skip-*" | tr '\012' ' ') && + "refs/bisect/skip-*" | tr '\012' ' ') || exit # Maybe some merge bases must be tested first check_good_are_ancestors_of_bad "$bad" "$good" "$skip" From 20f7a39825e30891056ab00ea620eaffda6aa451 Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Mon, 3 Nov 2008 09:14:28 -0900 Subject: [PATCH 072/138] Add autoconf tests for pthreads Set the value of PTHREAD_LIBS to the correct flags for linking pthreads on the current environment. Signed-off-by: David M. Syzdek Signed-off-by: Junio C Hamano --- config.mak.in | 1 + configure.ac | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/config.mak.in b/config.mak.in index 717072943f..ea7705c1ed 100644 --- a/config.mak.in +++ b/config.mak.in @@ -51,3 +51,4 @@ OLD_ICONV=@OLD_ICONV@ NO_DEFLATE_BOUND=@NO_DEFLATE_BOUND@ FREAD_READS_DIRECTORIES=@FREAD_READS_DIRECTORIES@ SNPRINTF_RETURNS_BOGUS=@SNPRINTF_RETURNS_BOGUS@ +PTHREAD_LIBS=@PTHREAD_LIBS@ diff --git a/configure.ac b/configure.ac index a0d53f3124..3f058a087b 100644 --- a/configure.ac +++ b/configure.ac @@ -479,6 +479,22 @@ AC_SUBST(NO_MKDTEMP) # # Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link. # Enable it on Windows. By default, symrefs are still used. +# +# Define PTHREAD_LIBS to the linker flag used for Pthread support. +AC_LANG_CONFTEST([AC_LANG_PROGRAM( + [[#include ]], + [[pthread_mutex_t test_mutex;]] +)]) +${CC} -pthread conftest.c -o conftest.o > /dev/null 2>&1 +if test $? -eq 0;then + PTHREAD_LIBS="-pthread" +else + ${CC} -lpthread conftest.c -o conftest.o > /dev/null 2>&1 + if test $? -eq 0;then + PTHREAD_LIBS="-lpthread" + fi +fi +AC_SUBST(PTHREAD_LIBS) ## Site configuration (override autodetection) ## --with-PACKAGE[=ARG] and --without-PACKAGE From 8c1f6f6c5797d1a3fa9ec9d38ae30b4f19e70a3c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 9 Nov 2008 13:08:38 -0800 Subject: [PATCH 073/138] t5303: work around printf breakage in dash Signed-off-by: Junio C Hamano --- t/t5303-pack-corruption-resilience.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh index ac181ea38a..f471eadb96 100755 --- a/t/t5303-pack-corruption-resilience.sh +++ b/t/t5303-pack-corruption-resilience.sh @@ -234,7 +234,7 @@ test_expect_success \ 'corruption #1 in delta base reference of first delta (OBJ_OFS_DELTA)' \ 'create_new_pack --delta-base-offset && git prune-packed && - printf "\x01" | do_corrupt_object $blob_2 2 && + tr "\000" "\001" /dev/null && test_must_fail git cat-file blob $blob_2 > /dev/null && test_must_fail git cat-file blob $blob_3 > /dev/null' From a2d2c478f325690e1575e14e7d310fd7435d83be Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 9 Nov 2008 13:11:06 -0800 Subject: [PATCH 074/138] t5303: fix printf format string for portability printf "\x01" is bad; write printf "\001" for portability. Testing with dash is a good way to find this kind of POSIX.1 violation breakages. Signed-off-by: Junio C Hamano --- t/t5303-pack-corruption-resilience.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh index f471eadb96..d4e30fc43c 100755 --- a/t/t5303-pack-corruption-resilience.sh +++ b/t/t5303-pack-corruption-resilience.sh @@ -234,7 +234,7 @@ test_expect_success \ 'corruption #1 in delta base reference of first delta (OBJ_OFS_DELTA)' \ 'create_new_pack --delta-base-offset && git prune-packed && - tr "\000" "\001" /dev/null && test_must_fail git cat-file blob $blob_2 > /dev/null && test_must_fail git cat-file blob $blob_3 > /dev/null' From b28ebab294fb13f1bb5cd36ab9774a6dcf50a004 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 9 Nov 2008 18:36:50 +0300 Subject: [PATCH 075/138] git-gui: Fix focus transition in the blame viewer. Now that the blame viewer has a search panel, it should be taken into account by the focus transition code. Otherwise showing a commit tip (by accidentally moving the mouse to the text frame) causes the focus to transfer away from the search field. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce --- lib/blame.tcl | 16 ++++++++++++---- lib/search.tcl | 14 +++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/blame.tcl b/lib/blame.tcl index 765d08c004..642f5cab86 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -321,7 +321,7 @@ constructor new {i_commit i_path i_jump} { tk_popup $w.ctxm %X %Y " bind $i "[list focus $w_cviewer];break" - bind $i "[list focus $w_cviewer];break" + bind $i "[cb _focus_search $w_cviewer];break" } foreach i [concat $w_columns $w_cviewer] { @@ -337,10 +337,10 @@ constructor new {i_commit i_path i_jump} { bind $i {catch {%W yview scroll 1 pages};break} } - bind $w_cviewer "[list focus $w_file];break" + bind $w_cviewer "[cb _focus_search $w_file];break" bind $w_cviewer "[list focus $w_file];break" - bind $w_cviewer [list focus $w_cviewer] - bind $w_file [list focus $w_file] + bind $w_cviewer [list focus $w_cviewer] + bind $w_file [cb _focus_search $w_file] bind $top [list searchbar::show $finder] bind $top [list searchbar::hide $finder] bind $top [list searchbar::find_next $finder] @@ -382,6 +382,14 @@ constructor new {i_commit i_path i_jump} { _load $this $i_jump } +method _focus_search {win} { + if {[searchbar::visible $finder]} { + focus [searchbar::editor $finder] + } else { + focus $win + } +} + method _handle_destroy {win} { if {$win eq $w} { _kill $this diff --git a/lib/search.tcl b/lib/search.tcl index d292f20f66..32c8656fc9 100644 --- a/lib/search.tcl +++ b/lib/search.tcl @@ -19,11 +19,11 @@ constructor new {i_w i_text args} { frame $w label $w.l -text [mc Find:] + entry $w.ent -textvariable ${__this}::searchstring -background lightgreen button $w.bn -text [mc Next] -command [cb find_next] button $w.bp -text [mc Prev] -command [cb find_prev] checkbutton $w.cs -text [mc Case-Sensitive] \ -variable ${__this}::casesensitive -command [cb _incrsearch] - entry $w.ent -textvariable ${__this}::searchstring -background lightgreen pack $w.l -side left pack $w.cs -side right pack $w.bp -side right @@ -40,19 +40,27 @@ constructor new {i_w i_text args} { } method show {} { - if {![winfo ismapped $w]} { + if {![visible $this]} { grid $w } focus -force $w.ent } method hide {} { - if {[winfo ismapped $w]} { + if {[visible $this]} { focus $ctext grid remove $w } } +method visible {} { + return [winfo ismapped $w] +} + +method editor {} { + return $w.ent +} + method _get_new_anchor {} { # use start of selection if it is visible, # or the bounds of the visible area From e29c0d10a201a4ce0c71ddb65faadff533ed2a98 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 9 Nov 2008 18:51:16 +0300 Subject: [PATCH 076/138] git-gui: Add the Show SSH Key item to the clone dialog. The user might need to see the key before cloning a repository. This patch makes the relevant menu item available in the Select Repository/Clone dialog. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce --- git-gui.sh | 20 +++++++++++--------- lib/choose_repository.tcl | 6 ++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 12b496bec9..cf9ef6ee07 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -997,6 +997,17 @@ citool { } } +###################################################################### +## +## execution environment + +set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}] + +# Suggest our implementation of askpass, if none is set +if {![info exists env(SSH_ASKPASS)]} { + set env(SSH_ASKPASS) [gitexec git-gui--askpass] +} + ###################################################################### ## ## repository setup @@ -1073,15 +1084,6 @@ set selected_commit_type new set nullid "0000000000000000000000000000000000000000" set nullid2 "0000000000000000000000000000000000000001" -set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}] - -###################################################################### - -# Suggest our implementation of askpass, if none is set -if {![info exists env(SSH_ASKPASS)]} { - set env(SSH_ASKPASS) [gitexec git-gui--askpass] -} - ###################################################################### ## ## task management diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl index 909131689e..f9ff62a3b2 100644 --- a/lib/choose_repository.tcl +++ b/lib/choose_repository.tcl @@ -43,12 +43,18 @@ constructor pick {} { $w.mbar.apple add command \ -label [mc "About %s" [appname]] \ -command do_about + $w.mbar.apple add command \ + -label [mc "Show SSH Key"] \ + -command do_ssh_key } else { $w.mbar add cascade -label [mc Help] -menu $w.mbar.help menu $w.mbar.help $w.mbar.help add command \ -label [mc "About %s" [appname]] \ -command do_about + $w.mbar.help add command \ + -label [mc "Show SSH Key"] \ + -command do_ssh_key } wm protocol $top WM_DELETE_WINDOW exit From f75c8b319f5b448d8e7dc589ca581eec852a131e Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 9 Nov 2008 18:53:09 +0300 Subject: [PATCH 077/138] git-gui: Request blame metadata in utf-8. The blame builtin now supports automatic conversion of metadata encoding. By default it is converted to the character set specified by i18n.logoutputencoding. Since gui blame expects the data in utf-8, it is necessary to specify the desired encoding directly. An old version of the blame command will simply ignore the option. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce --- lib/blame.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blame.tcl b/lib/blame.tcl index 642f5cab86..c1cd7f3b92 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -559,7 +559,7 @@ method _read_file {fd jump} { } ifdeleted { catch {close $fd} } method _exec_blame {cur_w cur_d options cur_s} { - lappend options --incremental + lappend options --incremental --encoding=utf-8 if {$commit eq {}} { lappend options --contents $path } else { From 30c4d7a76a96cf7a2848b752083364c51b051f30 Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Mon, 10 Nov 2008 18:58:15 +0900 Subject: [PATCH 078/138] Document "git log --source" Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- Documentation/git-log.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 93a2a227c4..34cf4e5811 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -40,6 +40,10 @@ include::diff-options.txt[] --decorate:: Print out the ref names of any commits that are shown. +--source:: + Print out the ref name given on the command line by which each + commit was reached. + --full-diff:: Without this flag, "git log -p ..." shows commits that touch the specified paths, and diffs about the same specified From 912f9980d233961c48a225cce2657f165c98c8ae Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 11 Nov 2008 13:12:17 -0800 Subject: [PATCH 079/138] Makefile: help people who run 'make check' by mistake The target to run self test is 'make test', but there are people who try 'make check' and worse yet do not have sparse installed. Suggest 'make test' target when they do not have 'sparse'. Signed-off-by: Junio C Hamano --- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index becd008e04..186a8efd1b 100644 --- a/Makefile +++ b/Makefile @@ -1329,7 +1329,16 @@ check-sha1:: test-sha1$X ./test-sha1.sh check: common-cmds.h - for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; done + if sparse; \ + then \ + for i in *.c; \ + do \ + sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; \ + done; \ + else \ + echo 2>&1 "Did you mean 'make test'?"; \ + exit 1; \ + fi remove-dashes: ./fixup-builtins $(BUILT_INS) $(PROGRAMS) $(SCRIPTS) From 0a2bb55848c031f431d8507d0083247ece126b8f Mon Sep 17 00:00:00 2001 From: Stefan Naewe Date: Tue, 11 Nov 2008 16:52:31 +0100 Subject: [PATCH 080/138] git ls-remote: make usage string match manpage The usage string of 'git ls-remote' is pretty terse. The manpage however gives the correct 'synopsis'. Signed-off-by: Stefan Naewe Signed-off-by: Junio C Hamano --- builtin-ls-remote.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-ls-remote.c b/builtin-ls-remote.c index c21b841e7c..78a88f7476 100644 --- a/builtin-ls-remote.c +++ b/builtin-ls-remote.c @@ -4,7 +4,7 @@ #include "remote.h" static const char ls_remote_usage[] = -"git ls-remote [--upload-pack=] [:]"; +"git ls-remote [--heads] [--tags] [-u | --upload-pack ] ..."; /* * Is there one among the list of patterns that match the tail part From 989206f535dcd0f43356ad38e1d54cb833d96fc2 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 11 Nov 2008 22:09:16 +0100 Subject: [PATCH 081/138] git-submodule: Avoid printing a spurious message. Fix 'git submodule update' to avoid printing a spurious "Maybe you want to use 'update --init'?" once for every uninitialized submodule it encounters. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- git-submodule.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-submodule.sh b/git-submodule.sh index 5888735e4f..97e4d9a1ef 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -294,7 +294,7 @@ cmd_update() # Only mention uninitialized submodules when its # path have been specified test "$#" != "0" && - say "Submodule path '$path' not initialized" + say "Submodule path '$path' not initialized" && say "Maybe you want to use 'update --init'?" continue fi From 89cf4c7004ec329c3171448a154d050c8f75874e Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 10 Nov 2008 21:43:00 +0100 Subject: [PATCH 082/138] remote: add a new 'origin' variable to the struct This allows one to track where was the remote's original source, so that it's possible to decide if it makes sense to migrate it to the config format or not. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- remote.c | 3 +++ remote.h | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/remote.c b/remote.c index e530a21e5c..cbb3e484fe 100644 --- a/remote.c +++ b/remote.c @@ -201,6 +201,7 @@ static void read_remotes_file(struct remote *remote) if (!f) return; + remote->origin = REMOTE_REMOTES; while (fgets(buffer, BUF_SIZE, f)) { int value_list; char *s, *p; @@ -261,6 +262,7 @@ static void read_branches_file(struct remote *remote) s++; if (!*s) return; + remote->origin = REMOTE_BRANCHES; p = s + strlen(s); while (isspace(p[-1])) *--p = 0; @@ -350,6 +352,7 @@ static int handle_config(const char *key, const char *value, void *cb) if (!subkey) return error("Config with no key for remote %s", name); remote = make_remote(name, subkey - name); + remote->origin = REMOTE_CONFIG; if (!strcmp(subkey, ".mirror")) remote->mirror = git_config_bool(key, value); else if (!strcmp(subkey, ".skipdefaultupdate")) diff --git a/remote.h b/remote.h index d2e170ce66..a46a5be131 100644 --- a/remote.h +++ b/remote.h @@ -1,8 +1,15 @@ #ifndef REMOTE_H #define REMOTE_H +enum { + REMOTE_CONFIG, + REMOTE_REMOTES, + REMOTE_BRANCHES +}; + struct remote { const char *name; + int origin; const char **url; int url_nr; From 9db56f71b91153f4076a796c80c61f00edd8b700 Mon Sep 17 00:00:00 2001 From: Daniel Lowe Date: Mon, 10 Nov 2008 16:07:52 -0500 Subject: [PATCH 083/138] Fix non-literal format in printf-style calls These were found using gcc 4.3.2-1ubuntu11 with the warning: warning: format not a string literal and no format arguments Incorporated suggestions from Brandon Casey . Signed-off-by: Junio C Hamano --- builtin-remote.c | 2 +- bundle.c | 4 ++-- environment.c | 2 +- fsck.c | 2 +- grep.c | 6 +++--- path.c | 4 ++-- refs.c | 2 +- unpack-trees.c | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/builtin-remote.c b/builtin-remote.c index 584280fbf5..5af4e643eb 100644 --- a/builtin-remote.c +++ b/builtin-remote.c @@ -323,7 +323,7 @@ static int add_branch_for_removal(const char *refname, /* make sure that symrefs are deleted */ if (flags & REF_ISSYMREF) - return unlink(git_path(refname)); + return unlink(git_path("%s", refname)); item = string_list_append(refname, branches->branches); item->util = xmalloc(20); diff --git a/bundle.c b/bundle.c index 7d17a1fde1..daecd8e1ca 100644 --- a/bundle.c +++ b/bundle.c @@ -114,7 +114,7 @@ int verify_bundle(struct bundle_header *header, int verbose) continue; } if (++ret == 1) - error(message); + error("%s", message); error("%s %s", sha1_to_hex(e->sha1), e->name); } if (revs.pending.nr != p->nr) @@ -139,7 +139,7 @@ int verify_bundle(struct bundle_header *header, int verbose) for (i = 0; i < req_nr; i++) if (!(refs.objects[i].item->flags & SHOWN)) { if (++ret == 1) - error(message); + error("%s", message); error("%s %s", sha1_to_hex(refs.objects[i].item->sha1), refs.objects[i].name); } diff --git a/environment.c b/environment.c index df4f03a95f..9ebf485a73 100644 --- a/environment.c +++ b/environment.c @@ -113,7 +113,7 @@ const char *get_git_work_tree(void) work_tree = git_work_tree_cfg; /* make_absolute_path also normalizes the path */ if (work_tree && !is_absolute_path(work_tree)) - work_tree = xstrdup(make_absolute_path(git_path(work_tree))); + work_tree = xstrdup(make_absolute_path(git_path("%s", work_tree))); } else if (work_tree) work_tree = xstrdup(make_absolute_path(work_tree)); git_work_tree_initialized = 1; diff --git a/fsck.c b/fsck.c index 797e3178ae..ab64c18a2b 100644 --- a/fsck.c +++ b/fsck.c @@ -327,7 +327,7 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...) die("this should not happen, your snprintf is broken"); } - error(sb.buf); + error("%s", sb.buf); strbuf_release(&sb); return 1; } diff --git a/grep.c b/grep.c index 706351197f..13c18ff652 100644 --- a/grep.c +++ b/grep.c @@ -507,7 +507,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, if (from <= last_shown) from = last_shown + 1; if (last_shown && from != last_shown + 1) - printf(hunk_mark); + fputs(hunk_mark, stdout); while (from < lno) { pcl = &prev[lno-from-1]; show_line(opt, pcl->bol, pcl->eol, @@ -517,7 +517,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, last_shown = lno-1; } if (last_shown && lno != last_shown + 1) - printf(hunk_mark); + fputs(hunk_mark, stdout); if (!opt->count) show_line(opt, bol, eol, name, lno, ':'); last_shown = last_hit = lno; @@ -528,7 +528,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, * we need to show this line. */ if (last_shown && lno != last_shown + 1) - printf(hunk_mark); + fputs(hunk_mark, stdout); show_line(opt, bol, eol, name, lno, '-'); last_shown = lno; } diff --git a/path.c b/path.c index eb24017535..a074aea649 100644 --- a/path.c +++ b/path.c @@ -41,7 +41,7 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...) len = vsnprintf(buf, n, fmt, args); va_end(args); if (len >= n) { - snprintf(buf, n, bad_path); + strlcpy(buf, bad_path, n); return buf; } return cleanup_path(buf); @@ -63,7 +63,7 @@ static char *git_vsnpath(char *buf, size_t n, const char *fmt, va_list args) goto bad; return cleanup_path(buf); bad: - snprintf(buf, n, bad_path); + strlcpy(buf, bad_path, n); return buf; } diff --git a/refs.c b/refs.c index 293389e764..be095cb07d 100644 --- a/refs.c +++ b/refs.c @@ -934,7 +934,7 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt) lock->lk->filename[i] = 0; path = lock->lk->filename; } else { - path = git_path(refname); + path = git_path("%s", refname); } err = unlink(path); if (err && errno != ENOENT) { diff --git a/unpack-trees.c b/unpack-trees.c index e5749ef638..54f301da67 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -352,7 +352,7 @@ static int unpack_failed(struct unpack_trees_options *o, const char *message) discard_index(&o->result); if (!o->gently) { if (message) - return error(message); + return error("%s", message); return -1; } return -1; From 42fc1139a07b4292d3e5251c591609126664941a Mon Sep 17 00:00:00 2001 From: Daniel Lowe Date: Mon, 10 Nov 2008 16:07:52 -0500 Subject: [PATCH 084/138] Fix non-literal format in printf-style calls These were found using gcc 4.3.2-1ubuntu11 with the warning: warning: format not a string literal and no format arguments Signed-off-by: Junio C Hamano --- builtin-check-attr.c | 2 +- hash-object.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin-check-attr.c b/builtin-check-attr.c index 4921341e33..15a04b7179 100644 --- a/builtin-check-attr.c +++ b/builtin-check-attr.c @@ -97,7 +97,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix) else if (stdin_paths && doubledash < argc) errstr = "Can't specify files with --stdin"; if (errstr) { - error (errstr); + error("%s", errstr); usage_with_options(check_attr_usage, check_attr_options); } diff --git a/hash-object.c b/hash-object.c index 20937ff94c..846e91a231 100644 --- a/hash-object.c +++ b/hash-object.c @@ -110,7 +110,7 @@ int main(int argc, const char **argv) } if (errstr) { - error (errstr); + error("%s", errstr); usage_with_options(hash_object_usage, hash_object_options); } From 7f96e2e25aa008556a4ede7a65de8488eb9890e6 Mon Sep 17 00:00:00 2001 From: John Chapman Date: Sat, 8 Nov 2008 14:22:48 +1100 Subject: [PATCH 085/138] git-p4: Support purged files and optimize memory usage Purged files are handled as if they are merely deleted, which is not entirely optimal, but I don't know of any other way to handle them. File data is deleted from memory as early as they can, and they are more efficiently handled, at (significant) cost to CPU usage. Still need to handle p4 branches with spaces in their names. Still need to make git-p4 clone more reliable. - Perhaps with a --continue option. (Sometimes the p4 server kills the connection) Signed-off-by: John Chapman Acked-by: Simon Hausmann Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 2216cacba7..38d1a17333 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -946,7 +946,7 @@ class P4Sync(Command): if includeFile: filesForCommit.append(f) - if f['action'] != 'delete': + if f['action'] not in ('delete', 'purge'): filesToRead.append(f) filedata = [] @@ -965,11 +965,11 @@ class P4Sync(Command): while j < len(filedata): stat = filedata[j] j += 1 - text = []; + text = '' while j < len(filedata) and filedata[j]['code'] in ('text', 'unicode', 'binary'): - text.append(filedata[j]['data']) + text += filedata[j]['data'] + del filedata[j]['data'] j += 1 - text = ''.join(text) if not stat.has_key('depotFile'): sys.stderr.write("p4 print fails with: %s\n" % repr(stat)) @@ -1038,7 +1038,7 @@ class P4Sync(Command): continue relPath = self.stripRepoPath(file['path'], branchPrefixes) - if file["action"] == "delete": + if file["action"] in ("delete", "purge"): self.gitStream.write("D %s\n" % relPath) else: data = file['data'] @@ -1077,7 +1077,7 @@ class P4Sync(Command): cleanedFiles = {} for info in files: - if info["action"] == "delete": + if info["action"] in ("delete", "purge"): continue cleanedFiles[info["depotFile"]] = info["rev"] @@ -1400,7 +1400,7 @@ class P4Sync(Command): if change > newestRevision: newestRevision = change - if info["action"] == "delete": + if info["action"] in ("delete", "purge"): # don't increase the file cnt, otherwise details["depotFile123"] will have gaps! #fileCnt = fileCnt + 1 continue From 36bd844658cf244ec2c6756c18673a4b7ed8ec9e Mon Sep 17 00:00:00 2001 From: John Chapman Date: Sat, 8 Nov 2008 14:22:49 +1100 Subject: [PATCH 086/138] git-p4: Cache git config for performance This makes git-p4 noticibly faster on Windows. Signed-off-by: John Chapman Acked-by: Simon Hausmann Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 38d1a17333..9f0a5f92c1 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -316,8 +316,11 @@ def gitBranchExists(branch): stderr=subprocess.PIPE, stdout=subprocess.PIPE); return proc.wait() == 0; +_gitConfig = {} def gitConfig(key): - return read_pipe("git config %s" % key, ignore_error=True).strip() + if not _gitConfig.has_key(key): + _gitConfig[key] = read_pipe("git config %s" % key, ignore_error=True).strip() + return _gitConfig[key] def p4BranchesInGit(branchesAreInRemotes = True): branches = {} From 2baf1850ceb01dfbee862e30f2a69cf6064e13eb Mon Sep 17 00:00:00 2001 From: David Symonds Date: Wed, 29 Oct 2008 09:15:36 -0700 Subject: [PATCH 087/138] git-diff: Add --staged as a synonym for --cached. Signed-off-by: Junio C Hamano --- Documentation/git-diff.txt | 1 + builtin-diff.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index c53eba557d..a2f192fb75 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -33,6 +33,7 @@ forced by --no-index. commit relative to the named . Typically you would want comparison with the latest commit, so if you do not give , it defaults to HEAD. + --staged is a synonym of --cached. 'git diff' [--options] [--] [...]:: diff --git a/builtin-diff.c b/builtin-diff.c index 9c8c295732..82d4ddabd8 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -118,7 +118,7 @@ static int builtin_diff_index(struct rev_info *revs, int cached = 0; while (1 < argc) { const char *arg = argv[1]; - if (!strcmp(arg, "--cached")) + if (!strcmp(arg, "--cached") || !strcmp(arg, "--staged")) cached = 1; else usage(builtin_diff_usage); @@ -319,7 +319,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix) const char *arg = argv[i]; if (!strcmp(arg, "--")) break; - else if (!strcmp(arg, "--cached")) { + else if (!strcmp(arg, "--cached") || + !strcmp(arg, "--staged")) { add_head_to_pending(&rev); if (!rev.pending.nr) die("No HEAD commit to compare with (yet)"); From 18afe101eb2c2f68ba58085515f592148128fba3 Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Mon, 10 Nov 2008 22:47:11 +0100 Subject: [PATCH 088/138] git push: Interpret $GIT_DIR/branches in a Cogito compatible way Current git versions ignore everything after # (called in the following) when pushing. Older versions (before cf818348f1ab57), interpret # as part of the URL, which make git bail out. As branches origin from Cogito, it is the best to correct this by using the behaviour of cg-push, that is to push HEAD to remote refs/heads/. Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- Documentation/urls-remotes.txt | 19 +++++++++---- remote.c | 11 ++++++++ t/t5516-fetch-push.sh | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/Documentation/urls-remotes.txt b/Documentation/urls-remotes.txt index 504ae8a53b..41ec7774f4 100644 --- a/Documentation/urls-remotes.txt +++ b/Documentation/urls-remotes.txt @@ -68,13 +68,22 @@ This file should have the following format: ------------ `` is required; `#` is optional. -When you do not provide a refspec on the command line, -git will use the following refspec, where `` defaults to `master`, -and `` is the name of this file -you provided in the command line. + +Depending on the operation, git will use one of the following +refspecs, if you don't provide one on the command line. +`` is the name of this file in `$GIT_DIR/branches` and +`` defaults to `master`. + +git fetch uses: ------------ - refs/heads/: + refs/heads/:refs/heads/ +------------ + +git push uses: + +------------ + HEAD:refs/heads/ ------------ diff --git a/remote.c b/remote.c index 7688f3b04d..91f1b7cd81 100644 --- a/remote.c +++ b/remote.c @@ -298,6 +298,17 @@ static void read_branches_file(struct remote *remote) } add_url_alias(remote, p); add_fetch_refspec(remote, strbuf_detach(&branch, 0)); + /* + * Cogito compatible push: push current HEAD to remote #branch + * (master if missing) + */ + strbuf_init(&branch, 0); + strbuf_addstr(&branch, "HEAD"); + if (frag) + strbuf_addf(&branch, ":refs/heads/%s", frag); + else + strbuf_addstr(&branch, ":refs/heads/master"); + add_push_refspec(remote, strbuf_detach(&branch, 0)); remote->fetch_tags = 1; /* always auto-follow */ } diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 598664ce7f..f9e878022a 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -494,4 +494,54 @@ test_expect_success 'allow deleting an invalid remote ref' ' ' +test_expect_success 'fetch with branches' ' + mk_empty && + git branch second $the_first_commit && + git checkout second && + echo ".." > testrepo/.git/branches/branch1 && + (cd testrepo && + git fetch branch1 && + r=$(git show-ref -s --verify refs/heads/branch1) && + test "z$r" = "z$the_commit" && + test 1 = $(git for-each-ref refs/heads | wc -l) + ) && + git checkout master +' + +test_expect_success 'fetch with branches containing #' ' + mk_empty && + echo "..#second" > testrepo/.git/branches/branch2 && + (cd testrepo && + git fetch branch2 && + r=$(git show-ref -s --verify refs/heads/branch2) && + test "z$r" = "z$the_first_commit" && + test 1 = $(git for-each-ref refs/heads | wc -l) + ) && + git checkout master +' + +test_expect_success 'push with branches' ' + mk_empty && + git checkout second && + echo "testrepo" > .git/branches/branch1 && + git push branch1 && + (cd testrepo && + r=$(git show-ref -s --verify refs/heads/master) && + test "z$r" = "z$the_first_commit" && + test 1 = $(git for-each-ref refs/heads | wc -l) + ) +' + +test_expect_success 'push with branches containing #' ' + mk_empty && + echo "testrepo#branch3" > .git/branches/branch2 && + git push branch2 && + (cd testrepo && + r=$(git show-ref -s --verify refs/heads/branch3) && + test "z$r" = "z$the_first_commit" && + test 1 = $(git for-each-ref refs/heads | wc -l) + ) && + git checkout master +' + test_done From 1dd1239aa33ddd7f159cd183338ef6f71298e29a Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 10 Nov 2008 21:43:01 +0100 Subject: [PATCH 089/138] git-remote rename: migrate from remotes/ and branches/ Remote definition that came from $GIT_DIR/remotes/nick and $GIT_DIR/branches/nick are migrated to [remotes "nick"] section in the configuration file. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- builtin-remote.c | 35 +++++++++++++++++++++++++++++++++++ t/t5505-remote.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/builtin-remote.c b/builtin-remote.c index 1ca6cdbe2a..3af18768e5 100644 --- a/builtin-remote.c +++ b/builtin-remote.c @@ -359,6 +359,38 @@ static int read_remote_branches(const char *refname, return 0; } +static int migrate_file(struct remote *remote) +{ + struct strbuf buf = STRBUF_INIT; + int i; + char *path = NULL; + + strbuf_addf(&buf, "remote.%s.url", remote->name); + for (i = 0; i < remote->url_nr; i++) + if (git_config_set_multivar(buf.buf, remote->url[i], "^$", 0)) + return error("Could not append '%s' to '%s'", + remote->url[i], buf.buf); + strbuf_reset(&buf); + strbuf_addf(&buf, "remote.%s.push", remote->name); + for (i = 0; i < remote->push_refspec_nr; i++) + if (git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0)) + return error("Could not append '%s' to '%s'", + remote->push_refspec[i], buf.buf); + strbuf_reset(&buf); + strbuf_addf(&buf, "remote.%s.fetch", remote->name); + for (i = 0; i < remote->fetch_refspec_nr; i++) + if (git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0)) + return error("Could not append '%s' to '%s'", + remote->fetch_refspec[i], buf.buf); + if (remote->origin == REMOTE_REMOTES) + path = git_path("remotes/%s", remote->name); + else if (remote->origin == REMOTE_BRANCHES) + path = git_path("branches/%s", remote->name); + if (path && unlink(path)) + warning("failed to remove '%s'", path); + return 0; +} + static int mv(int argc, const char **argv) { struct option options[] = { @@ -381,6 +413,9 @@ static int mv(int argc, const char **argv) if (!oldremote) die("No such remote: %s", rename.old); + if (!strcmp(rename.old, rename.new) && oldremote->origin != REMOTE_CONFIG) + return migrate_file(oldremote); + newremote = remote_get(rename.new); if (newremote && (newremote->url_nr > 1 || newremote->fetch_refspec_nr)) die("remote %s already exists.", rename.new); diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 0c956bad69..1f59960d90 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -343,4 +343,37 @@ test_expect_success 'rename a remote' ' test "$(git config branch.master.remote)" = "upstream") ' + +cat > remotes_origin << EOF +URL: $(pwd)/one +Push: refs/heads/master:refs/heads/upstream +Pull: refs/heads/master:refs/heads/origin +EOF + +test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' ' + git clone one five && + origin_url=$(pwd)/one && + (cd five && + git remote rm origin && + mkdir -p .git/remotes && + cat ../remotes_origin > .git/remotes/origin && + git remote rename origin origin && + ! test -f .git/remotes/origin && + test "$(git config remote.origin.url)" = "$origin_url" && + test "$(git config remote.origin.push)" = "refs/heads/master:refs/heads/upstream" && + test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin") +' + +test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' ' + git clone one six && + origin_url=$(pwd)/one && + (cd six && + git remote rm origin && + echo "$origin_url" > .git/branches/origin && + git remote rename origin origin && + ! test -f .git/branches/origin && + test "$(git config remote.origin.url)" = "$origin_url" && + test "$(git config remote.origin.fetch)" = "refs/heads/master:refs/heads/origin") +' + test_done From 74443f185ed91f3388b0e45838262eb3ec8338aa Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 10 Nov 2008 21:43:03 +0100 Subject: [PATCH 090/138] git-remote: document the migration feature of the rename subcommand Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- Documentation/git-remote.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt index 7b227b307f..fad983e297 100644 --- a/Documentation/git-remote.txt +++ b/Documentation/git-remote.txt @@ -66,6 +66,10 @@ was passed. Rename the remote named to . All remote tracking branches and configuration settings for the remote are updated. ++ +In case and are the same, and is a file under +`$GIT_DIR/remotes` or `$GIT_DIR/branches`, the remote is converted to +the configuration file format. 'rm':: From 9245ddd515d0fb5da52da4fd4dfc71460e98db90 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 12 Nov 2008 11:59:02 -0600 Subject: [PATCH 091/138] t7700: demonstrate mishandling of objects in packs with a .keep file Objects residing in pack files that have an associated .keep file are not supposed to be repacked into new pack files, but they are. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7700-repack.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 t/t7700-repack.sh diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh new file mode 100755 index 0000000000..7aaff0bbe0 --- /dev/null +++ b/t/t7700-repack.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +test_description='git repack works correctly' + +. ./test-lib.sh + +test_expect_failure 'objects in packs marked .keep are not repacked' ' + echo content1 > file1 && + echo content2 > file2 && + git add . && + git commit -m initial_commit && + # Create two packs + # The first pack will contain all of the objects except one + git rev-list --objects --all | grep -v file2 | + git pack-objects pack > /dev/null && + # The second pack will contain the excluded object + packsha1=$(git rev-list --objects --all | grep file2 | + git pack-objects pack) && + touch -r pack-$packsha1.pack pack-$packsha1.keep && + objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | + sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && + mv pack-* .git/objects/pack/ && + git repack -A -d -l && + git prune-packed && + for p in .git/objects/pack/*.idx; do + idx=$(basename $p) + test "pack-$packsha1.idx" = "$idx" && continue + if git verify-pack -v $p | egrep "^$objsha1"; then + found_duplicate_object=1 + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test -z "$found_duplicate_object" +' + +test_done + From 8d25931d6ff47a7fb06512d767d1d416d9bc7733 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 12 Nov 2008 11:59:03 -0600 Subject: [PATCH 092/138] packed_git: convert pack_local flag into a bitfield and add pack_keep pack_keep will be set when a pack file has an associated .keep file. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- cache.h | 3 ++- sha1_file.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cache.h b/cache.h index a1e4982cd4..1a5740f589 100644 --- a/cache.h +++ b/cache.h @@ -671,7 +671,8 @@ extern struct packed_git { int index_version; time_t mtime; int pack_fd; - int pack_local; + unsigned pack_local:1, + pack_keep:1; unsigned char sha1[20]; /* something like ".git/objects/pack/xxxxx.pack" */ char pack_name[FLEX_ARRAY]; /* more */ diff --git a/sha1_file.c b/sha1_file.c index 12fc767ee5..adb116350b 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -828,6 +828,11 @@ struct packed_git *add_packed_git(const char *path, int path_len, int local) return NULL; } memcpy(p->pack_name, path, path_len); + + strcpy(p->pack_name + path_len, ".keep"); + if (!access(p->pack_name, F_OK)) + p->pack_keep = 1; + strcpy(p->pack_name + path_len, ".pack"); if (stat(p->pack_name, &st) || !S_ISREG(st.st_mode)) { free(p); From e96fb9b8f90f907d720ea6b71c92e30c2b071f4a Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 12 Nov 2008 11:59:04 -0600 Subject: [PATCH 093/138] pack-objects: new option --honor-pack-keep This adds a new option to pack-objects which will cause it to ignore an object which appears in a local pack which has a .keep file, even if it was specified for packing. This option will be used by the porcelain repack. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- Documentation/git-pack-objects.txt | 5 +++++ builtin-pack-objects.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/Documentation/git-pack-objects.txt b/Documentation/git-pack-objects.txt index 8c354bd470..f9fac2ccf9 100644 --- a/Documentation/git-pack-objects.txt +++ b/Documentation/git-pack-objects.txt @@ -109,6 +109,11 @@ base-name:: The default is unlimited, unless the config variable `pack.packSizeLimit` is set. +--honor-pack-keep:: + This flag causes an object already in a local pack that + has a .keep file to be ignored, even if it appears in the + standard input. + --incremental:: This flag causes an object already in a pack ignored even if it appears in the standard input. diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b0dddbee4f..29c00474d6 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -71,6 +71,7 @@ static int reuse_delta = 1, reuse_object = 1; static int keep_unreachable, unpack_unreachable, include_tag; static int local; static int incremental; +static int ignore_packed_keep; static int allow_ofs_delta; static const char *base_name; static int progress = 1; @@ -703,6 +704,8 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type, return 0; if (local && !p->pack_local) return 0; + if (ignore_packed_keep && p->pack_local && p->pack_keep) + return 0; } } @@ -2042,6 +2045,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) incremental = 1; continue; } + if (!strcmp("--honor-pack-keep", arg)) { + ignore_packed_keep = 1; + continue; + } if (!prefixcmp(arg, "--compression=")) { char *end; int level = strtoul(arg+14, &end, 0); From dd718365cccfddd7d5992a40296de50e7cabdfc8 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 12 Nov 2008 11:59:05 -0600 Subject: [PATCH 094/138] repack: don't repack local objects in packs with .keep file If the user created a .keep file for a local pack, then it can be inferred that the user does not want those objects repacked. This fixes the repack bug tested by t7700. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- git-repack.sh | 2 +- t/t7700-repack.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/git-repack.sh b/git-repack.sh index d39eb6cea6..8bb22014b9 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -83,7 +83,7 @@ case ",$all_into_one," in esac args="$args $local $quiet $no_reuse$extra" -names=$(git pack-objects --non-empty --all --reflog $args file1 && echo content2 > file2 && git add . && From f7991d1ed37502c0e98dfa95866dfc1a8b08d834 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 12 Nov 2008 11:59:06 -0600 Subject: [PATCH 095/138] repack: do not fall back to incremental repacking with [-a|-A] When repack is called with either the -a or -A option, the user has requested to repack all objects including those referenced by the alternates mechanism. Currently, if there are no local packs without .keep files, then repack will call pack-objects with the '--unpacked --incremental' options which causes it to exclude alternate packed objects. So, remove this fallback. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- git-repack.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/git-repack.sh b/git-repack.sh index 8bb22014b9..4d313d136e 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -71,13 +71,10 @@ case ",$all_into_one," in existing="$existing $e" fi done - fi - if test -z "$args" - then - args='--unpacked --incremental' - elif test -n "$unpack_unreachable" - then - args="$args $unpack_unreachable" + if test -n "$args" -a -n "$unpack_unreachable" + then + args="$args $unpack_unreachable" + fi fi ;; esac From 01af249fa15ce63ea69e89e3520022420ecb409c Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 12 Nov 2008 11:59:07 -0600 Subject: [PATCH 096/138] builtin-gc.c: use new pack_keep bitfield to detect .keep file existence Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- builtin-gc.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/builtin-gc.c b/builtin-gc.c index fac200e0b0..53a0d43b67 100644 --- a/builtin-gc.c +++ b/builtin-gc.c @@ -134,19 +134,9 @@ static int too_many_packs(void) prepare_packed_git(); for (cnt = 0, p = packed_git; p; p = p->next) { - char path[PATH_MAX]; - size_t len; - int keep; - if (!p->pack_local) continue; - len = strlen(p->pack_name); - if (PATH_MAX <= len + 1) - continue; /* oops, give up */ - memcpy(path, p->pack_name, len-5); - memcpy(path + len - 5, ".keep", 6); - keep = access(p->pack_name, F_OK) && (errno == ENOENT); - if (keep) + if (p->pack_keep) continue; /* * Perhaps check the size of the pack and count only From 3c3df429106770966397086b6d2bced452ec7383 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Sun, 9 Nov 2008 23:59:56 -0600 Subject: [PATCH 097/138] t7700: demonstrate mishandling of loose objects in an alternate ODB Loose objects residing in an alternate object database should not be packed when the -l option to repack is used. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7700-repack.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 356afe371b..43c9cf9139 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -34,5 +34,24 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' test -z "$found_duplicate_object" ' +test_expect_failure 'loose objects in alternate ODB are not repacked' ' + mkdir alt_objects && + echo `pwd`/alt_objects > .git/objects/info/alternates && + echo content3 > file3 && + objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && + git add file3 && + git commit -m commit_file3 && + git repack -a -d -l && + git prune-packed && + for p in .git/objects/pack/*.idx; do + if git verify-pack -v $p | egrep "^$objsha1"; then + found_duplicate_object=1 + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test -z "$found_duplicate_object" +' + test_done From 0f4dc14ac4945448f7309964afeb879d20408e07 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Sun, 9 Nov 2008 23:59:57 -0600 Subject: [PATCH 098/138] sha1_file.c: split has_loose_object() into local and non-local counterparts Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- cache.h | 1 + sha1_file.c | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cache.h b/cache.h index 1a5740f589..7595c149ea 100644 --- a/cache.h +++ b/cache.h @@ -565,6 +565,7 @@ extern int move_temp_to_file(const char *tmpfile, const char *filename); extern int has_sha1_pack(const unsigned char *sha1, const char **ignore); extern int has_sha1_file(const unsigned char *sha1); +extern int has_loose_object_nonlocal(const unsigned char *sha1); extern int has_pack_file(const unsigned char *sha1); extern int has_pack_index(const unsigned char *sha1); diff --git a/sha1_file.c b/sha1_file.c index adb116350b..0203de5855 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -410,23 +410,30 @@ void prepare_alt_odb(void) read_info_alternates(get_object_directory(), 0); } -static int has_loose_object(const unsigned char *sha1) +static int has_loose_object_local(const unsigned char *sha1) { char *name = sha1_file_name(sha1); - struct alternate_object_database *alt; + return !access(name, F_OK); +} - if (!access(name, F_OK)) - return 1; +int has_loose_object_nonlocal(const unsigned char *sha1) +{ + struct alternate_object_database *alt; prepare_alt_odb(); for (alt = alt_odb_list; alt; alt = alt->next) { - name = alt->name; - fill_sha1_path(name, sha1); + fill_sha1_path(alt->name, sha1); if (!access(alt->base, F_OK)) return 1; } return 0; } +static int has_loose_object(const unsigned char *sha1) +{ + return has_loose_object_local(sha1) || + has_loose_object_nonlocal(sha1); +} + static unsigned int pack_used_ctr; static unsigned int pack_mmap_calls; static unsigned int peak_pack_open_windows; From daae06259556246959963947752bde4ee2df7b44 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Sun, 9 Nov 2008 23:59:58 -0600 Subject: [PATCH 099/138] pack-objects: extend --local to mean ignore non-local loose objects too With this patch, --local means pack only local objects that are not already packed. Additionally, this fixes t7700 testing whether loose objects in an alternate object database are repacked. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- Documentation/git-pack-objects.txt | 2 +- builtin-pack-objects.c | 3 +++ t/t7700-repack.sh | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/git-pack-objects.txt b/Documentation/git-pack-objects.txt index f9fac2ccf9..7d4c1a7556 100644 --- a/Documentation/git-pack-objects.txt +++ b/Documentation/git-pack-objects.txt @@ -121,7 +121,7 @@ base-name:: --local:: This flag is similar to `--incremental`; instead of ignoring all packed objects, it only ignores objects - that are packed and not in the local object store + that are packed and/or not in the local object store (i.e. borrowed from an alternate). --non-empty:: diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 29c00474d6..85bd795d3b 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -691,6 +691,9 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type, return 0; } + if (!exclude && local && has_loose_object_nonlocal(sha1)) + return 0; + for (p = packed_git; p; p = p->next) { off_t offset = find_pack_entry_one(sha1, p); if (offset) { diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 43c9cf9139..960bff47fa 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -34,7 +34,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' test -z "$found_duplicate_object" ' -test_expect_failure 'loose objects in alternate ODB are not repacked' ' +test_expect_success 'loose objects in alternate ODB are not repacked' ' mkdir alt_objects && echo `pwd`/alt_objects > .git/objects/info/alternates && echo content3 > file3 && From 0d641f75d1237b34d3cfb411a18c813cfacb4726 Mon Sep 17 00:00:00 2001 From: Matt Kraai Date: Fri, 7 Nov 2008 04:26:55 -0800 Subject: [PATCH 100/138] Remove the period after the git-check-attr summary The period at the end of the git-check-attr summary causes there to be two periods after the summary in the git(1) manual page. Signed-off-by: Matt Kraai Signed-off-by: Junio C Hamano --- Documentation/git-check-attr.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-check-attr.txt b/Documentation/git-check-attr.txt index 4b3c2b0b06..043274b1b7 100644 --- a/Documentation/git-check-attr.txt +++ b/Documentation/git-check-attr.txt @@ -3,7 +3,7 @@ git-check-attr(1) NAME ---- -git-check-attr - Display gitattributes information. +git-check-attr - Display gitattributes information SYNOPSIS From 14d9c578961ab834bfb0e26481d0212bc0670883 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Nov 2008 03:17:52 -0500 Subject: [PATCH 101/138] define empty tree sha1 as a macro This can potentially be used in a few places, so let's make it available to all parts of the code. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 6 ++++++ sha1_file.c | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cache.h b/cache.h index eda7028992..07795d9a81 100644 --- a/cache.h +++ b/cache.h @@ -528,6 +528,12 @@ static inline void hashclr(unsigned char *hash) } extern int is_empty_blob_sha1(const unsigned char *sha1); +#define EMPTY_TREE_SHA1_HEX \ + "4b825dc642cb6eb9a060e54bf8d69288fbee4904" +#define EMPTY_TREE_SHA1_BIN \ + "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \ + "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04" + int git_mkstemp(char *path, size_t n, const char *template); /* diff --git a/sha1_file.c b/sha1_file.c index ab2b520f03..1489d04d03 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1996,9 +1996,7 @@ static struct cached_object { static int cached_object_nr, cached_object_alloc; static struct cached_object empty_tree = { - /* empty tree sha1: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 */ - "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" - "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04", + EMPTY_TREE_SHA1_BIN, OBJ_TREE, "", 0 From c1e255b71964e45cee571819c011fbcaaf18be41 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Nov 2008 03:21:39 -0500 Subject: [PATCH 102/138] wt-status: refactor initial commit printing When we showed the initial commit, we had no reference to diff against, so we went through the cache manually. Nowadays, however, we have a virtual empty tree commit, so we can simply diff against that to get the same results. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- wt-status.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/wt-status.c b/wt-status.c index c3a9cab898..cb1fc48079 100644 --- a/wt-status.c +++ b/wt-status.c @@ -185,31 +185,12 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q, wt_status_print_trailer(s); } -static void wt_status_print_initial(struct wt_status *s) -{ - int i; - struct strbuf buf = STRBUF_INIT; - - if (active_nr) { - s->commitable = 1; - wt_status_print_cached_header(s); - } - for (i = 0; i < active_nr; i++) { - color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t"); - color_fprintf_ln(s->fp, color(WT_STATUS_UPDATED), "new file: %s", - quote_path(active_cache[i]->name, -1, - &buf, s->prefix)); - } - if (active_nr) - wt_status_print_trailer(s); - strbuf_release(&buf); -} - static void wt_status_print_updated(struct wt_status *s) { struct rev_info rev; init_revisions(&rev, NULL); - setup_revisions(0, NULL, &rev, s->reference); + setup_revisions(0, NULL, &rev, + s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference); rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = wt_status_print_updated_cb; rev.diffopt.format_callback_data = s; @@ -351,12 +332,9 @@ void wt_status_print(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "# Initial commit"); color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); - wt_status_print_initial(s); - } - else { - wt_status_print_updated(s); } + wt_status_print_updated(s); wt_status_print_changed(s); if (wt_status_submodule_summary) wt_status_print_submodule_summary(s); From 0b38227f283e208866d3e2ac85bcd947a71f1b17 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Nov 2008 03:25:52 -0500 Subject: [PATCH 103/138] commit: Fix stripping of patch in verbose mode. When the "-v" option is given, we put diff of what is to be committed into the commit template, and then strip it back out again after the user has edited it. We used to look for the diff by searching for the "diff --git a/" header. With diff.mnemonicprefix set in the configuration, however, this pattern does not match. The pattern is loosened to cover this case. Also, if the user puts their own diff in the message (e.g., as a sample output), then we will accidentally trigger the pattern, removing part of their output. We can avoid doing this stripping altogether if the user didn't use "-v" in the first place, so we know that any match we find will be a false positive. [jc: this fix was split out of a series originally meant for master.] Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-commit.c | 8 +++-- t/t7507-commit-verbose.sh | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100755 t/t7507-commit-verbose.sh diff --git a/builtin-commit.c b/builtin-commit.c index b563a0d67c..1e08399919 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -1004,9 +1004,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix) } /* Truncate the message just before the diff, if any. */ - p = strstr(sb.buf, "\ndiff --git a/"); - if (p != NULL) - strbuf_setlen(&sb, p - sb.buf + 1); + if (verbose) { + p = strstr(sb.buf, "\ndiff --git "); + if (p != NULL) + strbuf_setlen(&sb, p - sb.buf + 1); + } if (cleanup_mode != CLEANUP_NONE) stripspace(&sb, cleanup_mode == CLEANUP_ALL); diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh new file mode 100755 index 0000000000..519adba80b --- /dev/null +++ b/t/t7507-commit-verbose.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +test_description='verbose commit template' +. ./test-lib.sh + +cat >check-for-diff <message <<'EOF' +subject + +body +EOF + +test_expect_success 'setup' ' + echo content >file && + git add file && + git commit -F message +' + +test_expect_failure 'initial commit shows verbose diff' ' + git commit --amend -v +' + +test_expect_success 'second commit' ' + echo content modified >file && + git add file && + git commit -F message +' + +check_message() { + git log -1 --pretty=format:%s%n%n%b >actual && + test_cmp "$1" actual +} + +test_expect_success 'verbose diff is stripped out' ' + git commit --amend -v && + check_message message +' + +test_expect_success 'verbose diff is stripped out (mnemonicprefix)' ' + git config diff.mnemonicprefix true && + git commit --amend -v && + check_message message +' + +cat >diff <<'EOF' +This is an example commit message that contains a diff. + +diff --git c/file i/file +new file mode 100644 +index 0000000..f95c11d +--- /dev/null ++++ i/file +@@ -0,0 +1 @@ ++this is some content +EOF + +test_expect_success 'diff in message is retained without -v' ' + git commit --amend -F diff && + check_message diff +' + +test_expect_failure 'diff in message is retained with -v' ' + git commit --amend -F diff -v && + check_message diff +' + +test_done From 1324fb6f161ee516eb4c597880847003a42c0c5d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Nov 2008 03:23:37 -0500 Subject: [PATCH 104/138] status: show "-v" diff even for initial commit Since we can use the same "diff against empty tree" trick as we do for the non-initial case, it is trivial to make this work. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t7507-commit-verbose.sh | 2 +- wt-status.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh index 519adba80b..da5bd3b5a5 100755 --- a/t/t7507-commit-verbose.sh +++ b/t/t7507-commit-verbose.sh @@ -22,7 +22,7 @@ test_expect_success 'setup' ' git commit -F message ' -test_expect_failure 'initial commit shows verbose diff' ' +test_expect_success 'initial commit shows verbose diff' ' git commit --amend -v ' diff --git a/wt-status.c b/wt-status.c index cb1fc48079..ec91fba601 100644 --- a/wt-status.c +++ b/wt-status.c @@ -279,7 +279,8 @@ static void wt_status_print_verbose(struct wt_status *s) struct rev_info rev; init_revisions(&rev, NULL); - setup_revisions(0, NULL, &rev, s->reference); + setup_revisions(0, NULL, &rev, + s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference); rev.diffopt.output_format |= DIFF_FORMAT_PATCH; rev.diffopt.detect_rename = 1; rev.diffopt.file = s->fp; @@ -343,7 +344,7 @@ void wt_status_print(struct wt_status *s) else if (s->commitable) fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n"); - if (s->verbose && !s->is_initial) + if (s->verbose) wt_status_print_verbose(s); if (!s->commitable) { if (s->amend) From fa7b3c2f752a10a5dca9989d4a1c4b93ffa7f943 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 12 Nov 2008 11:52:35 -0800 Subject: [PATCH 105/138] checkout: Fix "initial checkout" detection Earlier commit 5521883 (checkout: do not lose staged removal, 2008-09-07) tightened the rule to prevent switching branches from losing local changes, so that staged removal of paths can be protected, while attempting to keep a loophole to still allow a special case of switching out of an un-checked-out state. However, the loophole was made a bit too tight, and did not allow switching from one branch (in an un-checked-out state) to check out another branch. The change to builtin-checkout.c in this commit loosens it to allow this, by not insisting the original commit and the new commit to be the same. It also introduces a new function, is_index_unborn (and an associated macro, is_cache_unborn), to check if the repository is truly in an un-checked-out state more reliably, by making sure that $GIT_INDEX_FILE did not exist when populating the in-core index structure. A few places the earlier commit 5521883 added the check for the initial checkout condition are updated to use this function. Signed-off-by: Junio C Hamano --- builtin-checkout.c | 3 +-- builtin-read-tree.c | 2 +- cache.h | 2 ++ read-cache.c | 5 +++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/builtin-checkout.c b/builtin-checkout.c index 05eee4ecc7..25845cdd5e 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -269,8 +269,7 @@ static int merge_working_tree(struct checkout_opts *opts, } /* 2-way merge to the new branch */ - topts.initial_checkout = (!active_nr && - (old->commit == new->commit)); + topts.initial_checkout = is_cache_unborn(); topts.update = 1; topts.merge = 1; topts.gently = opts->merge; diff --git a/builtin-read-tree.c b/builtin-read-tree.c index 0706c95818..38fef34d3f 100644 --- a/builtin-read-tree.c +++ b/builtin-read-tree.c @@ -206,7 +206,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) break; case 2: opts.fn = twoway_merge; - opts.initial_checkout = !active_nr; + opts.initial_checkout = is_cache_unborn(); break; case 3: default: diff --git a/cache.h b/cache.h index a1e4982cd4..3960931a95 100644 --- a/cache.h +++ b/cache.h @@ -255,6 +255,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define read_cache() read_index(&the_index) #define read_cache_from(path) read_index_from(&the_index, (path)) +#define is_cache_unborn() is_index_unborn(&the_index) #define read_cache_unmerged() read_index_unmerged(&the_index) #define write_cache(newfd, cache, entries) write_index(&the_index, (newfd)) #define discard_cache() discard_index(&the_index) @@ -360,6 +361,7 @@ extern int init_db(const char *template_dir, unsigned int flags); /* Initialize and use the cache information */ extern int read_index(struct index_state *); extern int read_index_from(struct index_state *, const char *path); +extern int is_index_unborn(struct index_state *); extern int read_index_unmerged(struct index_state *); extern int write_index(const struct index_state *, int newfd); extern int discard_index(struct index_state *); diff --git a/read-cache.c b/read-cache.c index 967f483f78..525d138e90 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1239,6 +1239,11 @@ unmap: die("index file corrupt"); } +int is_index_unborn(struct index_state *istate) +{ + return (!istate->cache_nr && !istate->alloc && !istate->timestamp); +} + int discard_index(struct index_state *istate) { istate->cache_nr = 0; From 3fcfd662dc84830d25ee966b8d5325806b7c51b2 Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Mon, 10 Nov 2008 18:58:17 +0900 Subject: [PATCH 106/138] Document "git log --simplify-by-decoration" Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- Documentation/rev-list-options.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 966276b169..668923893e 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -456,6 +456,14 @@ Note the major differences in `N` and `P` over '\--full-history': removed completely, because it had one parent and is TREESAME. -- +The '\--simplify-by-decoration' option allows you to view only the +big picture of the topology of the history, by omitting commits +that are not referenced by tags. Commits are marked as !TREESAME +(in other words, kept after history simplification rules described +above) if (1) they are referenced by tags, or (2) they change the +contents of the paths given on the command line. All other +commits are marked as TREESAME (subject to be simplified away). + ifdef::git-rev-list[] Bisection Helpers ~~~~~~~~~~~~~~~~~ From 7bc2508bfe0f7e8c0371a68f57ac5b7d4fe7e1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santi=20B=C3=A9jar?= Date: Wed, 12 Nov 2008 11:51:28 +0100 Subject: [PATCH 107/138] rev-list documentation: clarify the two parts of history simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One set of options and parameters determine what commits are involved in the simplification process, and another set of options determine how the simplification is done. Clarify their distinction at the beginning. Signed-off-by: Santi Béjar Signed-off-by: Junio C Hamano --- Documentation/rev-list-options.txt | 48 ++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 668923893e..78c381a8e0 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -285,8 +285,52 @@ See also linkgit:git-reflog[1]. History Simplification ~~~~~~~~~~~~~~~~~~~~~~ -When optional paths are given, 'git-rev-list' simplifies commits with -various strategies, according to the options you have selected. +Sometimes you are only interested in parts of the history, for example the +commits modifying a particular . But there are two parts of +'History Simplification', one part is selecting the commits and the other +is how to do it, as there are various strategies to simplify the history. + +The following options select the commits to be shown: + +:: + + Commits modifying the given are selected. + +--simplify-by-decoration:: + + Commits that are referred by some branch or tag are selected. + +Note that extra commits can be shown to give a meaningful history. + +The following options affect the way the simplification is performed: + +Default mode:: + + Simplifies the history to the simplest history explaining the + final state of the tree. Simplest because it prunes some side + branches if the end result is the same (i.e. merging branches + with the same content) + +--full-history:: + + As the default mode but does not prune some history. + +--dense:: + + Only the selected commits are shown, plus some to have a + meaningful history. + +--sparse:: + + All commits in the simplified history are shown. + +--simplify-merges:: + + Additional option to '--full-history' to remove some needless + merges from the resulting history, as there are no selected + commits contributing to this merge. + +A more detailed explanation follows. Suppose you specified `foo` as the . We shall call commits that modify `foo` !TREESAME, and the rest TREESAME. (In a diff From a1e4760fcfece8eb9b556f35a04a521fdee3963c Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Wed, 12 Nov 2008 13:23:58 -0500 Subject: [PATCH 108/138] Fix pack.packSizeLimit and --max-pack-size handling If the limit was sufficiently low, having a single object written could bust the limit (by design), but caused the remaining allowed size to go negative for subsequent objects, which for an unsigned variable is a rather huge limit. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 12 ++++++++++-- t/t5300-pack-object.sh | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b0dddbee4f..8fe51244e0 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -245,8 +245,16 @@ static unsigned long write_object(struct sha1file *f, type = entry->type; /* write limit if limited packsize and not first object */ - limit = pack_size_limit && nr_written ? - pack_size_limit - write_offset : 0; + if (!pack_size_limit || !nr_written) + limit = 0; + else if (pack_size_limit <= write_offset) + /* + * the earlier object did not fit the limit; avoid + * mistaking this with unlimited (i.e. limit = 0). + */ + limit = 1; + else + limit = pack_size_limit - write_offset; if (!entry->delta) usable_delta = 0; /* no delta */ diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 3a0ef8759c..2852a03265 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -375,4 +375,10 @@ test_expect_success 'index-pack with --strict' ' ) ' +test_expect_success 'tolerate absurdly small packsizelimit' ' + git config pack.packSizeLimit 2 && + packname_9=$(git pack-objects test-9 Date: Wed, 12 Nov 2008 15:03:03 -0800 Subject: [PATCH 109/138] Start 1.6.0.5 cycle Signed-off-by: Junio C Hamano --- Documentation/RelNotes-1.6.0.5.txt | 21 +++++++++++++++++++++ RelNotes | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Documentation/RelNotes-1.6.0.5.txt diff --git a/Documentation/RelNotes-1.6.0.5.txt b/Documentation/RelNotes-1.6.0.5.txt new file mode 100644 index 0000000000..62f95e6bad --- /dev/null +++ b/Documentation/RelNotes-1.6.0.5.txt @@ -0,0 +1,21 @@ +GIT v1.6.0.5 Release Notes +========================== + +Fixes since v1.6.0.4 +-------------------- + +* 'git checkout' used to crash when your HEAD was pointing at a deleted + branch. + +* 'git checkout' from an un-checked-out state did not allow switching out + of the current branch. + +* 'git pack-objects' did not make its best effort to honor --max-pack-size + option when a single first object already busted the given limit and + placed many objects in a single pack. + +* 'make check' cannot be run without sparse; people may have meant to say + 'make test' instead, so suggest that. + +* Many unsafe call to sprintf() style varargs functions are corrected. + diff --git a/RelNotes b/RelNotes index f9eb552873..ebf508f2d7 120000 --- a/RelNotes +++ b/RelNotes @@ -1 +1 @@ -Documentation/RelNotes-1.6.0.4.txt \ No newline at end of file +Documentation/RelNotes-1.6.0.5.txt \ No newline at end of file From 171d7661eda111d3e35f6e8097a1a3a07b30026c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 12 Nov 2008 15:04:54 -0800 Subject: [PATCH 110/138] git.html: Update the links to stale versions Signed-off-by: Junio C Hamano --- Documentation/git.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/git.txt b/Documentation/git.txt index df420aeb33..7e0a041436 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -43,9 +43,11 @@ unreleased) version of git, that is available from 'master' branch of the `git.git` repository. Documentation for older releases are available here: -* link:v1.6.0.2/git.html[documentation for release 1.6.0.2] +* link:v1.6.0.4/git.html[documentation for release 1.6.0.4] * release notes for + link:RelNotes-1.6.0.4.txt[1.6.0.4], + link:RelNotes-1.6.0.3.txt[1.6.0.3], link:RelNotes-1.6.0.2.txt[1.6.0.2], link:RelNotes-1.6.0.1.txt[1.6.0.1], link:RelNotes-1.6.0.txt[1.6.0]. From 3289b9dec56d34fe05f90c262d11adc0a61e16e7 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Wed, 12 Nov 2008 18:50:26 -0600 Subject: [PATCH 111/138] t7700: test that 'repack -a' packs alternate packed objects Previously, when 'repack -a' was called and there were no packs in the local repository without a .keep file, the repack would fall back to calling pack-objects with '--unpacked --incremental'. This resulted in the created pack file, if any, to be missing the packed objects in the alternate object store. Test that this specific case has been fixed. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7700-repack.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 960bff47fa..3f602ea7de 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -53,5 +53,21 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' test -z "$found_duplicate_object" ' +test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' ' + mkdir alt_objects/pack + mv .git/objects/pack/* alt_objects/pack && + git repack -a && + myidx=$(ls -1 .git/objects/pack/*.idx) && + test -f "$myidx" && + for p in alt_objects/pack/*.idx; do + git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" + done | while read sha1 rest; do + if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then + echo "Missing object in local pack: $sha1" + return 1 + fi + done +' + test_done From e599e7ff1f89fc3d46a6e3b5fe04976402e12a49 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 12 Nov 2008 22:47:15 -0800 Subject: [PATCH 112/138] Update draft release notes to 1.6.1 A large number of topics are merged to prepare for -rc0 now. Signed-off-by: Junio C Hamano --- Documentation/RelNotes-1.6.1.txt | 34 +++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Documentation/RelNotes-1.6.1.txt b/Documentation/RelNotes-1.6.1.txt index d0e30e95d4..7fdf83f604 100644 --- a/Documentation/RelNotes-1.6.1.txt +++ b/Documentation/RelNotes-1.6.1.txt @@ -27,6 +27,8 @@ on. * Sample pre-auto-gc script has OS X support. +* Makefile has support for (ancient) FreeBSD 4.9. + (performance) * The underlying diff machinery to produce textual output has been @@ -53,6 +55,10 @@ on. to a non-zero value to accept the suggestion when git can uniquely guess. +* The packfile machinery hopefully is more robust when dealilng with + corrupt packs if redundant objects involved in the corruption are + available elsehwere. + * "git add -N path..." adds the named paths as an empty blob, so that subsequent "git diff" will show a diff as if they are creation events. @@ -110,8 +116,18 @@ on. * "git diff" learned --dirstat-by-file to count changed files, not number of lines, when summarizing the global picture. +* "git diff" learned "textconv" filters --- a binary or hard-to-read + contents can be munged into human readable form and the difference + between the results of the conversion can be viewed (obviously this + cannot produce a patch that can be applied, so this is disabled in + format-patch among other things). + * "git diff" hunk header pattern for ObjC has been added. +* "--cached" option to "git diff has an easier to remember synonym "--staged", + to ask "what is the difference between the given commit and the + contents staged in the index?" + * a "textconv" filter that makes binary files textual form for human consumption can be specified as an attribute for paths; "git diff" learnt to make use of it. @@ -138,6 +154,12 @@ on. * "git log" learned --simplify-merges, a milder variant of --full-history; "gitk --simplify-merges" is easier to view than with --full-history. +* "git log" learned "--source" to show what ref each commit was reached + from. + +* "git log" also learned "--simplify-by-decration" to show the + birds-eye-view of the topology of the history. + * "git log --pretty=format:" learned "%d" format element that inserts names of tags that point at the commit. @@ -213,6 +235,9 @@ release, unless otherwise noted. * "git filter-branch" failed to rewrite a tag name with slashes in it. +* "git repack" used to grab objects out of packs marked with .keep + into a new pack (fix scheduled to be further downmerged to maint). + * "git push --tags --all $there" failed with generic usage message without telling saying these two options are incompatible. @@ -220,8 +245,15 @@ release, unless otherwise noted. timestamp part, exposing internal implementation detail. Also these did not work with --fixed-strings match at all. +* "git tag" did not complain about incompatible combination of options + e.g. "tag -l -d" (fix scheduled to be further downmerged to maint). + +* Internal diff machinery had a corner case performance bug that choked on a + large file with many repeated contents (fix scheduled to be further cherry- + picked to maint). + -- exec >/var/tmp/1 -O=v1.6.0.3-639-ga1a846a +O=v1.6.0.4-697-g168d5bd echo O=$(git describe master) git shortlog --no-merges $O..master ^maint From cea07cf8dc9b3677e0c50433c0d72bce83adbdc7 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 9 Nov 2008 13:00:45 +0300 Subject: [PATCH 113/138] gitk: Add accelerators to frequently used menu commands This commit documents keyboard accelerators used for menu commands in the menu, as it is usually done, and adds some more, e.g. F4 to invoke Edit View (or New View if the current view is the un-editable "All files" view). The changes include a workaround for handling Shift-F4 on systems where XKB binds special XF86_Switch_VT_* symbols to Ctrl-Alt-F* combinations. Tk often receives these codes when Shift-F* is pressed, so it is necessary to bind the relevant actions to them as well. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/gitk b/gitk index 18d153e569..9b2a6e5445 100755 --- a/gitk +++ b/gitk @@ -1801,6 +1801,11 @@ proc setoptions {} { # command to invoke for command, or {variable value} for radiobutton proc makemenu {m items} { menu $m + if {[tk windowingsystem] eq {aqua}} { + set Meta1 Cmd + } else { + set Meta1 Ctrl + } foreach i $items { set name [mc [lindex $i 1]] set type [lindex $i 2] @@ -1826,7 +1831,9 @@ proc makemenu {m items} { -value [lindex $thing 1] } } - eval $m add $params [lrange $i 4 end] + set tail [lrange $i 4 end] + regsub -all {\yMeta1\y} $tail $Meta1 tail + eval $m add $params $tail if {$type eq "cascade"} { makemenu $m.$submenu $thing } @@ -1860,17 +1867,17 @@ proc makewindow {} { makemenu .bar { {mc "File" cascade { {mc "Update" command updatecommits -accelerator F5} - {mc "Reload" command reloadcommits} + {mc "Reload" command reloadcommits -accelerator Meta1-F5} {mc "Reread references" command rereadrefs} - {mc "List references" command showrefs} - {mc "Quit" command doquit} + {mc "List references" command showrefs -accelerator F2} + {mc "Quit" command doquit -accelerator Meta1-Q} }} {mc "Edit" cascade { {mc "Preferences" command doprefs} }} {mc "View" cascade { - {mc "New view..." command {newview 0}} - {mc "Edit view..." command editview -state disabled} + {mc "New view..." command {newview 0} -accelerator Shift-F4} + {mc "Edit view..." command editview -state disabled -accelerator F4} {mc "Delete view" command delview -state disabled} {xx "" separator} {mc "All files" radiobutton {selectedview 0} -command {showview 0}} @@ -2232,7 +2239,12 @@ proc makewindow {} { bindkey {dofind 1 1} bindkey ? {dofind -1 1} bindkey f nextfile - bindkey updatecommits + bind . updatecommits + bind . <$M1B-F5> reloadcommits + bind . showrefs + bind . {newview 0} + catch { bind . {newview 0} } + bind . edit_or_newview bind . <$M1B-q> doquit bind . <$M1B-f> {dofind 1 1} bind . <$M1B-g> {dofind 1 0} @@ -3624,6 +3636,16 @@ proc decode_view_opts {n view_args} { set newviewopts($n,args) [shellarglist $oargs] } +proc edit_or_newview {} { + global curview + + if {$curview > 0} { + editview + } else { + newview 0 + } +} + proc editview {} { global curview global viewname viewperm newviewname newviewopts From e7d640086e0d3eb332542da287c40262c6eae207 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Tue, 11 Nov 2008 23:55:42 +0300 Subject: [PATCH 114/138] gitk: Fix transient windows on Win32 and MacOS Transient windows cause problems on these platforms: - On Win32 the windows appear in the top left corner of the screen. In order to fix it, this patch causes them to be explicitly centered on their parents by an idle handler. - On MacOS with Tk 8.4 they appear without a title bar. Since it is clearly unacceptable, this patch disables transient on that platform. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/gitk b/gitk index 9b2a6e5445..e6aafe8a68 100755 --- a/gitk +++ b/gitk @@ -1739,6 +1739,24 @@ proc removehead {id name} { unset headids($name) } +proc make_transient {window origin} { + global have_tk85 + + # In MacOS Tk 8.4 transient appears to work by setting + # overrideredirect, which is utterly useless, since the + # windows get no border, and are not even kept above + # the parent. + if {!$have_tk85 && [tk windowingsystem] eq {aqua}} return + + wm transient $window $origin + + # Windows fails to place transient windows normally, so + # schedule a callback to center them on the parent. + if {[tk windowingsystem] eq {win32}} { + after idle [list tk::PlaceWindow $window widget $origin] + } +} + proc show_error {w top msg} { message $w.m -text $msg -justify center -aspect 400 pack $w.m -side top -fill x -padx 20 -pady 20 @@ -1754,7 +1772,7 @@ proc show_error {w top msg} { proc error_popup {msg {owner .}} { set w .error toplevel $w - wm transient $w $owner + make_transient $w $owner show_error $w $w $msg } @@ -1763,7 +1781,7 @@ proc confirm_popup {msg {owner .}} { set confirm_ok 0 set w .confirm toplevel $w - wm transient $w $owner + make_transient $w $owner message $w.m -text $msg -justify center -aspect 400 pack $w.m -side top -fill x -padx 20 -pady 20 button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w" @@ -2558,7 +2576,7 @@ proc about {} { } toplevel $w wm title $w [mc "About gitk"] - wm transient $w . + make_transient $w . message $w.m -text [mc " Gitk - a commit viewer for git @@ -2587,7 +2605,7 @@ proc keys {} { } toplevel $w wm title $w [mc "Gitk key bindings"] - wm transient $w . + make_transient $w . message $w.m -text " [mc "Gitk key bindings:"] @@ -3669,7 +3687,7 @@ proc vieweditor {top n title} { toplevel $top wm title $top $title - wm transient $top . + make_transient $top . # View name frame $top.nfr @@ -7912,7 +7930,7 @@ proc mkpatch {} { set patchtop $top catch {destroy $top} toplevel $top - wm transient $top . + make_transient $top . label $top.title -text [mc "Generate patch"] grid $top.title - -pady 10 label $top.from -text [mc "From:"] @@ -7999,7 +8017,7 @@ proc mktag {} { set mktagtop $top catch {destroy $top} toplevel $top - wm transient $top . + make_transient $top . label $top.title -text [mc "Create tag"] grid $top.title - -pady 10 label $top.id -text [mc "ID:"] @@ -8102,7 +8120,7 @@ proc writecommit {} { set wrcomtop $top catch {destroy $top} toplevel $top - wm transient $top . + make_transient $top . label $top.title -text [mc "Write commit to file"] grid $top.title - -pady 10 label $top.id -text [mc "ID:"] @@ -8159,7 +8177,7 @@ proc mkbranch {} { set top .makebranch catch {destroy $top} toplevel $top - wm transient $top . + make_transient $top . label $top.title -text [mc "Create new branch"] grid $top.title - -pady 10 label $top.id -text [mc "ID:"] @@ -8322,7 +8340,7 @@ proc resethead {} { set confirm_ok 0 set w ".confirmreset" toplevel $w - wm transient $w . + make_transient $w . wm title $w [mc "Confirm reset"] message $w.m -text \ [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]] \ @@ -8502,7 +8520,7 @@ proc showrefs {} { } toplevel $top wm title $top [mc "Tags and heads: %s" [file tail [pwd]]] - wm transient $top . + make_transient $top . text $top.list -background $bgcolor -foreground $fgcolor \ -selectbackground $selectbgcolor -font mainfont \ -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \ @@ -9844,7 +9862,7 @@ proc choosefont {font which} { font create sample eval font config sample [font actual $font] toplevel $top - wm transient $top $prefstop + make_transient $top $prefstop wm title $top [mc "Gitk font chooser"] label $top.l -textvariable fontparam(which) pack $top.l -side top @@ -9961,7 +9979,7 @@ proc doprefs {} { } toplevel $top wm title $top [mc "Gitk preferences"] - wm transient $top . + make_transient $top . label $top.ldisp -text [mc "Commit list display options"] grid $top.ldisp - -sticky w -pady 10 label $top.spacer -text " " From 590915dab8aaf464f5819c4ccec7941c3490e3ce Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 9 Nov 2008 18:06:07 +0300 Subject: [PATCH 115/138] gitk: Fix commit encoding support This commit fixes two problems with commit encodings: 1) git-log actually uses i18n.logoutputencoding to generate its output, and falls back to i18n.commitencoding only when that option is not set. Thus, gitk should use its value to read the results, if available. 2) The readcommit function did not process encodings at all. This led to randomly appearing misconverted commits if the commit encoding differed from the current locale. Now commit messages should be displayed correctly, except when logoutputencoding is set to an encoding that cannot represent charecters in the message. For example, it is impossible to convert Japanese characters from Shift-JIS to CP-1251 (although the reverse conversion works). The reason for using git log to read the commit and then getting Tcl to convert its output is that is essentially what happens in the normal path through getcommitlines, hence there is less chance for unintended differences in how commits are processed in getcommitlines and do_readcommit. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras --- gitk | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/gitk b/gitk index e6aafe8a68..3864d3826d 100755 --- a/gitk +++ b/gitk @@ -1555,9 +1555,27 @@ proc chewcommits {} { return 0 } +proc do_readcommit {id} { + global tclencoding + + # Invoke git-log to handle automatic encoding conversion + set fd [open [concat | git log --no-color --pretty=raw -1 $id] r] + # Read the results using i18n.logoutputencoding + fconfigure $fd -translation lf -eofchar {} + if {$tclencoding != {}} { + fconfigure $fd -encoding $tclencoding + } + set contents [read $fd] + close $fd + # Remove the heading line + regsub {^commit [0-9a-f]+\n} $contents {} contents + + return $contents +} + proc readcommit {id} { - if {[catch {set contents [exec git cat-file commit $id]}]} return - parsecommit $id $contents 0 + if {[catch {set contents [do_readcommit $id]}]} return + parsecommit $id $contents 1 } proc parsecommit {id contents listed} { @@ -10558,6 +10576,9 @@ set gitencoding {} catch { set gitencoding [exec git config --get i18n.commitencoding] } +catch { + set gitencoding [exec git config --get i18n.logoutputencoding] +} if {$gitencoding == ""} { set gitencoding "utf-8" } From d98d50e214643379734ac3ffe891770457f1c419 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Thu, 13 Nov 2008 22:39:00 +1100 Subject: [PATCH 116/138] gitk: Fix linehtag undefined error with file highlighting Occasionally gitk will throw a Tcl error complaining that linehtag(n) is undefined when. It happens when the commit list is still growing (e.g. when updating the commit list) and gitk is set to highlight commits that affect certain file(s). What happens is that the changes to the commit list set need_redisplay to indicate that the display needs to be redrawn. That causes the next call to drawcommits to call clear_display, which unsets iddrawn and thus ensures that readfhighlight won't call bolden on any rows that have moved. However, it is possible for readfhighlight to be called after the commit list has changed but before drawcommits has run, meaning that readfhighlight will potentially think that rows have been drawn when they haven't, because of the change in the id -> row mapping (and the fact that iddrawn is indexed by id but line[hnd]tag are indexed by row number). This fixes it (and also optimizes things a little) by making bolden and bolden_name check need_redisplay before doing anything. If need_redisplay is set, then there is no point doing anything because the whole display is about to get cleared and redrawn, and it avoids looking up line[hn]tag using stale row numbers. Signed-off-by: Paul Mackerras --- gitk | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gitk b/gitk index 3864d3826d..3353f4a271 100755 --- a/gitk +++ b/gitk @@ -4005,8 +4005,10 @@ proc ishighlighted {id} { } proc bolden {row font} { - global canv linehtag selectedline boldrows + global canv linehtag selectedline boldrows need_redisplay + # need_redisplay = 1 means the display is stale and about to be redrawn + if {$need_redisplay} return lappend boldrows $row $canv itemconf $linehtag($row) -font $font if {$row == $selectedline} { @@ -4019,8 +4021,9 @@ proc bolden {row font} { } proc bolden_name {row font} { - global canv2 linentag selectedline boldnamerows + global canv2 linentag selectedline boldnamerows need_redisplay + if {$need_redisplay} return lappend boldnamerows $row $canv2 itemconf $linentag($row) -font $font if {$row == $selectedline} { From e9854a767208776f4745922945f0982ef5caab66 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 16 Aug 2008 21:25:40 -0700 Subject: [PATCH 117/138] date/time: do not get confused by fractional seconds The date/time parsing code was confused if the input time HH:MM:SS is followed by fractional seconds. Since we do not record anything finer grained than seconds, we could just drop fractional part, but there is a twist. We have taught people that not just spaces but dot can be used as word separators when spelling things like: $ git log --since 2.days $ git show @{12:34:56.7.days.ago} and we shouldn't mistake "7" in the latter example as a fraction and discard it. The rules are: - valid days of month/mday are always single or double digits. - valid years are either two or four digits No, we don't support the year 600 _anyway_, since our encoding is based on the UNIX epoch, and the day we worry about the year 10,000 is far away and we can raise the limit to five digits when we get closer. - Other numbers (eg "600 days ago") can have any number of digits, but they cannot start with a zero. Again, the only exception is for two-digit numbers, since that is fairly common for dates ("Dec 01" is not unheard of) So that means that any milli- or micro-second would be thrown out just because the number of digits shows that it cannot be an interesting date. A milli- or micro-second can obviously be a perfectly fine number according to the rules above, as long as it doesn't start with a '0'. So if we have 12:34:56.123 then that '123' gets parsed as a number, and we remember it. But because it's bigger than 31, we'll never use it as such _unless_ there is something after it to trigger that use. So you can say "12:34:56.123.days.ago", and because of the "days", that 123 will actually be meaninful now. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- date.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/date.c b/date.c index 35a52576c5..950b88fdcf 100644 --- a/date.c +++ b/date.c @@ -402,6 +402,15 @@ static int match_multi_number(unsigned long num, char c, const char *date, char return end - date; } +/* Have we filled in any part of the time/date yet? */ +static inline int nodate(struct tm *tm) +{ + return tm->tm_year < 0 && + tm->tm_mon < 0 && + tm->tm_mday < 0 && + !(tm->tm_hour | tm->tm_min | tm->tm_sec); +} + /* * We've seen a digit. Time? Year? Date? */ @@ -418,7 +427,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt * more than 8 digits. This is because we don't want to rule out * numbers like 20070606 as a YYYYMMDD date. */ - if (num >= 100000000) { + if (num >= 100000000 && nodate(tm)) { time_t time = num; if (gmtime_r(&time, tm)) { *tm_gmt = 1; @@ -462,6 +471,13 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt return n; } + /* + * Ignore lots of numerals. We took care of 4-digit years above. + * Days or months must be one or two digits. + */ + if (n > 2) + return n; + /* * NOTE! We will give precedence to day-of-month over month or * year numbers in the 1-12 range. So 05 is always "mday 5", @@ -488,10 +504,6 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt if (num > 0 && num < 32) { tm->tm_mday = num; - } else if (num > 1900) { - tm->tm_year = num - 1900; - } else if (num > 70) { - tm->tm_year = num; } else if (num > 0 && num < 13) { tm->tm_mon = num-1; } @@ -823,7 +835,9 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num) } } - *num = number; + /* Accept zero-padding only for small numbers ("Dec 02", never "Dec 0002") */ + if (date[0] != '0' || end - date <= 2) + *num = number; return end; } From 6a004d3f2e531936d6d91324a0610a874f91a867 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 21 Oct 2008 14:12:15 -0700 Subject: [PATCH 118/138] git-svn: don't escape tilde ('~') for http(s) URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Jose Carlos Garcia Sogo and Björn Steinbrink for the bug report. On 2008.10.18 23:39:19 +0200, Björn Steinbrink wrote: > Hi, > > Jose Carlos Garcia Sogo reported on #git that a git-svn clone of this > svn repo fails for him: > https://sucs.org/~welshbyte/svn/backuptool/trunk > > I can reproduce that here with: > git-svn version 1.6.0.2.541.g46dc1.dirty (svn 1.5.1) > > The error message I get is: > Apache got a malformed URI: Unusable URI: it does not refer to this > repository at /usr/local/libexec/git-core/git-svn line 4057 > > strace revealed that git-svn url-encodes ~ while svn does not do that. > > For svn we have: > write(5, " > https://sucs.org/~welshbyte/svn/backuptool/trunk... > > While git-svn shows: > write(7, " > https://sucs.org/%7Ewelshbyte/svn/backuptool/trunk... Signed-off-by: Eric Wong --- git-svn.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 5702b100f1..70a664ca0b 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -852,7 +852,7 @@ sub escape_uri_only { my ($uri) = @_; my @tmp; foreach (split m{/}, $uri) { - s/([^\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg; + s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg; push @tmp, $_; } join('/', @tmp); @@ -3537,7 +3537,7 @@ sub repo_path { sub url_path { my ($self, $path) = @_; if ($self->{url} =~ m#^https?://#) { - $path =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; + $path =~ s/([^~a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; } $self->{url} . '/' . $self->repo_path($path); } @@ -3890,7 +3890,7 @@ sub escape_uri_only { my ($uri) = @_; my @tmp; foreach (split m{/}, $uri) { - s/([^\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg; + s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg; push @tmp, $_; } join('/', @tmp); From 16fc08e2d86dad152194829d21bc55b2ef0c8fb1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 29 Oct 2008 23:49:26 -0700 Subject: [PATCH 119/138] git-svn: respect i18n.commitencoding config SVN itself always stores log messages in the repository as UTF-8. git always stores/retrieves everything as raw binary data with no transformations whatsoever. To interact with SVN, we need to encode log messages as UTF-8 before sending them to SVN, as SVN cannot do it for us. When retrieving log messages from SVN, we also need to (attempt to) reencode the UTF-8 log message back to the user-specified commit encoding. Note, handling i18n.logoutputencoding for "git svn log" also needs to be done in a future change. Also, this change only deals with the encoding of commit messages and nothing else (path names, blob content, ...). In-Reply-To: <8b168cfb0810282014r789ac01dnec51824de1078f0@mail.gmail.com> James North wrote: > Hi, > > I'm using git-svn on a system with ISO-8859-1 encoding. The problem is > when I try to use "git svn dcommit" to send changes to a remote svn > (also ISO-8859-1). > > Seems like git-svn is sending commit messages with utf-8 (just a > guessing...) and they look bad on the remote svn log. E.g. "Ca?\241a > de cami?\243n" > > I have tried using i18n.commitencoding=ISO-8859-1 as suggested by the > warning when doing "git svn dcommit" but messages still are sent with > wrong encoding. Signed-off-by: Eric Wong --- git-svn.perl | 24 +++++++- t/t9129-git-svn-i18n-commitencoding.sh | 80 ++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) create mode 100755 t/t9129-git-svn-i18n-commitencoding.sh diff --git a/git-svn.perl b/git-svn.perl index 70a664ca0b..2abb7b5937 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -1136,9 +1136,19 @@ sub get_commit_entry { system($editor, $commit_editmsg); } rename $commit_editmsg, $commit_msg or croak $!; - open $log_fh, '<', $commit_msg or croak $!; - { local $/; chomp($log_entry{log} = <$log_fh>); } - close $log_fh or croak $!; + { + # SVN requires messages to be UTF-8 when entering the repo + local $/; + open $log_fh, '<', $commit_msg or croak $!; + binmode $log_fh; + chomp($log_entry{log} = <$log_fh>); + + if (my $enc = Git::config('i18n.commitencoding')) { + require Encode; + Encode::from_to($log_entry{log}, $enc, 'UTF-8'); + } + close $log_fh or croak $!; + } unlink $commit_msg; \%log_entry; } @@ -2273,6 +2283,14 @@ sub do_git_commit { } defined(my $pid = open3(my $msg_fh, my $out_fh, '>&STDERR', @exec)) or croak $!; + binmode $msg_fh; + + # we always get UTF-8 from SVN, but we may want our commits in + # a different encoding. + if (my $enc = Git::config('i18n.commitencoding')) { + require Encode; + Encode::from_to($log_entry->{log}, 'UTF-8', $enc); + } print $msg_fh $log_entry->{log} or croak $!; restore_commit_header_env($old_env); unless ($self->no_metadata) { diff --git a/t/t9129-git-svn-i18n-commitencoding.sh b/t/t9129-git-svn-i18n-commitencoding.sh new file mode 100755 index 0000000000..2848e46e38 --- /dev/null +++ b/t/t9129-git-svn-i18n-commitencoding.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# +# Copyright (c) 2008 Eric Wong + +test_description='git svn honors i18n.commitEncoding in config' + +. ./lib-git-svn.sh + +compare_git_head_with () { + nr=`wc -l < "$1"` + a=7 + b=$(($a + $nr - 1)) + git cat-file commit HEAD | sed -ne "$a,${b}p" >current && + test_cmp current "$1" +} + +compare_svn_head_with () { + LC_ALL=en_US.UTF-8 svn log --limit 1 `git svn info --url` | \ + sed -e 1,3d -e "/^-\+\$/d" >current && + test_cmp current "$1" +} + +for H in ISO-8859-1 EUCJP ISO-2022-JP +do + test_expect_success "$H setup" ' + mkdir $H && + svn import -m "$H test" $H "$svnrepo"/$H && + git svn clone "$svnrepo"/$H $H + ' +done + +for H in ISO-8859-1 EUCJP ISO-2022-JP +do + test_expect_success "$H commit on git side" ' + ( + cd $H && + git config i18n.commitencoding $H && + git checkout -b t refs/remotes/git-svn && + echo $H >F && + git add F && + git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt && + E=$(git cat-file commit HEAD | sed -ne "s/^encoding //p") && + test "z$E" = "z$H" + compare_git_head_with "$TEST_DIRECTORY"/t3900/$H.txt + ) + ' +done + +for H in ISO-8859-1 EUCJP ISO-2022-JP +do + test_expect_success "$H dcommit to svn" ' + ( + cd $H && + git svn dcommit && + git cat-file commit HEAD | grep git-svn-id: && + E=$(git cat-file commit HEAD | sed -ne "s/^encoding //p") && + test "z$E" = "z$H" && + compare_git_head_with "$TEST_DIRECTORY"/t3900/$H.txt + ) + ' +done + +test_expect_success 'ISO-8859-1 should match UTF-8 in svn' ' +( + cd ISO-8859-1 && + compare_svn_head_with "$TEST_DIRECTORY"/t3900/1-UTF-8.txt +) +' + +for H in EUCJP ISO-2022-JP +do + test_expect_success '$H should match UTF-8 in svn' ' + ( + cd $H && + compare_svn_head_with "$TEST_DIRECTORY"/t3900/2-UTF-8.txt + ) + ' +done + +test_done From fe4003f6308b88bcc44a989f12e1baddd97f22d4 Mon Sep 17 00:00:00 2001 From: Deskin Miller Date: Thu, 6 Nov 2008 00:07:39 -0500 Subject: [PATCH 120/138] git-svn: proper detection of bare repositories When in a bare repository (or .git, for that matter), git-svn would fail to initialise properly, since git rev-parse --show-cdup would not output anything. However, git rev-parse --show-cdup actually returns an error code if it's really not in a git directory. Fix the issue by checking for an explicit error from git rev-parse, and setting $git_dir appropriately if instead it just does not output. Signed-off-by: Deskin Miller Acked-by: Eric Wong --- git-svn.perl | 12 +++++++----- t/t9100-git-svn-basic.sh | 9 +++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 2abb7b5937..86075ec616 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -223,11 +223,13 @@ unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) { "but it is not a directory\n"; } my $git_dir = delete $ENV{GIT_DIR}; - chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/)); - unless (length $cdup) { - die "Already at toplevel, but $git_dir ", - "not found '$cdup'\n"; - } + my $cdup = undef; + git_cmd_try { + $cdup = command_oneline(qw/rev-parse --show-cdup/); + $git_dir = '.' unless ($cdup); + chomp $cdup if ($cdup); + $cdup = "." unless ($cdup && length $cdup); + } "Already at toplevel, but $git_dir not found\n"; chdir $cdup or die "Unable to chdir up to '$cdup'\n"; unless (-d $git_dir) { die "$git_dir still not found after going to ", diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh index 9b238c329b..bb921af56a 100755 --- a/t/t9100-git-svn-basic.sh +++ b/t/t9100-git-svn-basic.sh @@ -265,4 +265,13 @@ test_expect_success 'able to set-tree to a subdirectory' " test -z \"\`git diff refs/heads/my-bar refs/remotes/bar\`\" " +test_expect_success 'git-svn works in a bare repository' ' + mkdir bare-repo && + ( cd bare-repo && + git init --bare && + GIT_DIR=. git svn init "$svnrepo" && + git svn fetch ) && + rm -rf bare-repo + ' + test_done From bcdd1b4456998256df19ea0347bf4a7fa5410eef Mon Sep 17 00:00:00 2001 From: "Marten Svanfeldt (dev)" Date: Thu, 13 Nov 2008 20:04:09 +0800 Subject: [PATCH 121/138] Git.pm: Make _temp_cache use the repository directory Update the usage of File::Temp->tempfile to place the temporary files within the repository directory instead of just letting Perl decide what directory to use, given there is a repository specified when requesting the temporary file. This is needed to be able to fix git-svn on msys as msysperl generates paths with UNIX-style paths (/tmp/xxx) while the git tools expect natvie path format (c:/..). The repository dir is stored in native format so by using it as the base directory for temporary files we always get a usable native full path. Signed-off-by: Marten Svanfeldt Acked-by: Eric Wong --- perl/Git.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/perl/Git.pm b/perl/Git.pm index ba94453781..dde9105df8 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -961,9 +961,7 @@ issue. =cut sub temp_acquire { - my ($self, $name) = _maybe_self(@_); - - my $temp_fd = _temp_cache($name); + my $temp_fd = _temp_cache(@_); $TEMP_FILES{$temp_fd}{locked} = 1; $temp_fd; @@ -1005,7 +1003,7 @@ sub temp_release { } sub _temp_cache { - my ($name) = @_; + my ($self, $name) = _maybe_self(@_); _verify_require(); @@ -1022,9 +1020,16 @@ sub _temp_cache { "' was closed. Opening replacement."; } my $fname; + + my $tmpdir; + if (defined $self) { + $tmpdir = $self->repo_path(); + } + ($$temp_fd, $fname) = File::Temp->tempfile( - 'Git_XXXXXX', UNLINK => 1 + 'Git_XXXXXX', UNLINK => 1, DIR => $tmpdir, ) or throw Error::Simple("couldn't open new temp file"); + $$temp_fd->autoflush; binmode $$temp_fd; $TEMP_FILES{$$temp_fd}{fname} = $fname; From 1b3069a753e2a2a3794db9235ea79747833cad65 Mon Sep 17 00:00:00 2001 From: "Marten Svanfeldt (dev)" Date: Thu, 13 Nov 2008 00:38:06 +0800 Subject: [PATCH 122/138] git-svn: Update git-svn to use the ability to place temporary files within repository directory This fixes git-svn within msys where Perl will provide temporary files with path such as /tmp while the git suit expects native Windows paths. Signed-off-by: Marten Svanfeldt Acked-by: Eric Wong --- git-svn.perl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/git-svn.perl b/git-svn.perl index 86075ec616..914c707a90 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -3332,11 +3332,11 @@ sub change_file_prop { sub apply_textdelta { my ($self, $fb, $exp) = @_; - my $fh = Git::temp_acquire('svn_delta'); + my $fh = $::_repository->temp_acquire('svn_delta'); # $fh gets auto-closed() by SVN::TxDelta::apply(), # (but $base does not,) so dup() it for reading in close_file open my $dup, '<&', $fh or croak $!; - my $base = Git::temp_acquire('git_blob'); + my $base = $::_repository->temp_acquire('git_blob'); if ($fb->{blob}) { print $base 'link ' if ($fb->{mode_a} == 120000); my $size = $::_repository->cat_blob($fb->{blob}, $base); @@ -3377,7 +3377,8 @@ sub close_file { warn "$path has mode 120000", " but is not a link\n"; } else { - my $tmp_fh = Git::temp_acquire('svn_hash'); + my $tmp_fh = $::_repository->temp_acquire( + 'svn_hash'); my $res; while ($res = sysread($fh, my $str, 1024)) { my $out = syswrite($tmp_fh, $str, $res); @@ -3765,7 +3766,7 @@ sub change_file_prop { sub _chg_file_get_blob ($$$$) { my ($self, $fbat, $m, $which) = @_; - my $fh = Git::temp_acquire("git_blob_$which"); + my $fh = $::_repository->temp_acquire("git_blob_$which"); if ($m->{"mode_$which"} =~ /^120/) { print $fh 'link ' or croak $!; $self->change_file_prop($fbat,'svn:special','*'); From a2df1fb2e52a49bf6b17b352581510efd851f337 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 13 Nov 2008 20:28:49 +0300 Subject: [PATCH 123/138] Documentation: New GUI configuration and command-line options. Add information on new git-gui and gitk command-line options, configuration variables, and the encoding attribute. Signed-off-by: Alexander Gavrilov Signed-off-by: Junio C Hamano --- Documentation/config.txt | 24 ++++++++++++++++++++++++ Documentation/git-gui.txt | 19 +++++++++++++++++++ Documentation/gitattributes.txt | 17 +++++++++++++++++ Documentation/gitk.txt | 5 +++++ 4 files changed, 65 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index 32dcd643d2..d536732217 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -796,6 +796,14 @@ gui.diffcontext:: Specifies how many context lines should be used in calls to diff made by the linkgit:git-gui[1]. The default is "5". +gui.encoding:: + Specifies the default encoding to use for displaying of + file contents in linkgit:git-gui[1] and linkgit:gitk[1]. + It can be overridden by setting the 'encoding' attribute + for relevant files (see linkgit:gitattributes[5]). + If this option is not set, the tools default to the + locale encoding. + gui.matchtrackingbranch:: Determines if new branches created with linkgit:git-gui[1] should default to tracking remote branches with matching names or @@ -818,6 +826,22 @@ gui.spellingdictionary:: the linkgit:git-gui[1]. When set to "none" spell checking is turned off. +gui.fastcopyblame:: + If true, 'git gui blame' uses '-C' instead of '-C -C' for original + location detection. It makes blame significantly faster on huge + repositories at the expense of less thorough copy detection. + +gui.copyblamethreshold:: + Specifies the theshold to use in 'git gui blame' original location + detection, measured in alphanumeric characters. See the + linkgit:git-blame[1] manual for more information on copy detection. + +gui.blamehistoryctx:: + Specifies the radius of history context in days to show in + linkgit:gitk[1] for the selected commit, when the `Show History + Context` menu item is invoked from 'git gui blame'. If this + variable is set to zero, the whole history is shown. + help.browser:: Specify the browser that will be used to display help in the 'web' format. See linkgit:git-help[1]. diff --git a/Documentation/git-gui.txt b/Documentation/git-gui.txt index 0e650f497b..d0bc98b852 100644 --- a/Documentation/git-gui.txt +++ b/Documentation/git-gui.txt @@ -65,9 +65,28 @@ git gui blame v0.99.8 Makefile:: example the file is read from the object database and not the working directory. +git gui blame --line=100 Makefile:: + + Loads annotations as described above and automatically + scrolls the view to center on line '100'. + git gui citool:: Make one commit and return to the shell when it is complete. + This command returns a non-zero exit code if the window was + closed in any way other than by making a commit. + +git gui citool --amend:: + + Automatically enter the 'Amend Last Commit' mode of + the interface. + +git gui citool --nocommit:: + + Behave as normal citool, but instead of making a commit + simply terminate with a zero exit code. It still checks + that the index does not contain any unmerged entries, so + you can use it as a GUI version of linkgit:git-mergetool[1] git citool:: diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index a172baf993..8af22eccac 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -535,6 +535,23 @@ in the file. E.g. the string `$Format:%H$` will be replaced by the commit hash. +Viewing files in GUI tools +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`encoding` +^^^^^^^^^^ + +The value of this attribute specifies the character encoding that should +be used by GUI tools (e.g. linkgit:gitk[1] and linkgit:git-gui[1]) to +display the contents of the relevant file. Note that due to performance +considerations linkgit:gitk[1] does not use this attribute unless you +manually enable per-file encodings in its options. + +If this attribute is not set or has an invalid value, the value of the +`gui.encoding` configuration variable is used instead +(See linkgit:git-config[1]). + + USING ATTRIBUTE MACROS ---------------------- diff --git a/Documentation/gitk.txt b/Documentation/gitk.txt index ae29a00d59..317f6317c2 100644 --- a/Documentation/gitk.txt +++ b/Documentation/gitk.txt @@ -56,6 +56,11 @@ frequently used options. Use this instead of explicitly specifying if the set of commits to show may vary between refreshes. +--select-commit=:: + + Automatically select the specified commit after loading the graph. + Default behavior is equivalent to specifying '--select-commit=HEAD'. + :: Limit the revisions to show. This can be either a single revision From 83d0289df6fb4deae100ee3fc37b90683c2e8c9f Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 13 Nov 2008 14:11:46 -0600 Subject: [PATCH 124/138] repack: only unpack-unreachable if we are deleting redundant packs The -A option calls pack-objects with the --unpack-unreachable option so that the unreachable objects in local packs are left in the local object store loose. But if the -d option to repack was _not_ used, then these unpacked loose objects are redundant and unnecessary. Update tests in t7701. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- Documentation/git-repack.txt | 11 +++++------ git-repack.sh | 3 ++- t/t7701-repack-unpack-unreachable.sh | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt index bbe1485a97..aaa8852629 100644 --- a/Documentation/git-repack.txt +++ b/Documentation/git-repack.txt @@ -38,12 +38,11 @@ OPTIONS dangling. -A:: - Same as `-a`, but any unreachable objects in a previous - pack become loose, unpacked objects, instead of being - left in the old pack. Unreachable objects are never - intentionally added to a pack, even when repacking. - When used with '-d', this option - prevents unreachable objects from being immediately + Same as `-a`, unless '-d' is used. Then any unreachable + objects in a previous pack become loose, unpacked objects, + instead of being left in the old pack. Unreachable objects + are never intentionally added to a pack, even when repacking. + This option prevents unreachable objects from being immediately deleted by way of being left in the old pack and then removed. Instead, the loose unreachable objects will be pruned according to normal expiry rules diff --git a/git-repack.sh b/git-repack.sh index 4d313d136e..458a497af8 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -71,7 +71,8 @@ case ",$all_into_one," in existing="$existing $e" fi done - if test -n "$args" -a -n "$unpack_unreachable" + if test -n "$args" -a -n "$unpack_unreachable" -a \ + -n "$remove_redundant" then args="$args $unpack_unreachable" fi diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh index 531dac060a..9813f113a2 100755 --- a/t/t7701-repack-unpack-unreachable.sh +++ b/t/t7701-repack-unpack-unreachable.sh @@ -8,7 +8,7 @@ fsha1= csha1= tsha1= -test_expect_success '-A option leaves unreachable objects unpacked' ' +test_expect_success '-A with -d option leaves unreachable objects unpacked' ' echo content > file1 && git add . && git commit -m initial_commit && @@ -58,7 +58,7 @@ compare_mtimes () ' -- "$@" } -test_expect_success 'unpacked objects receive timestamp of pack file' ' +test_expect_success '-A without -d option leaves unreachable objects packed' ' fsha1path=$(echo "$fsha1" | sed -e "s|\(..\)|\1/|") && fsha1path=".git/objects/$fsha1path" && csha1path=$(echo "$csha1" | sed -e "s|\(..\)|\1/|") && @@ -75,7 +75,19 @@ test_expect_success 'unpacked objects receive timestamp of pack file' ' git branch -D transient_branch && sleep 1 && git repack -A -l && - compare_mtimes "$packfile" "$fsha1path" "$csha1path" "$tsha1path" + test ! -f "$fsha1path" && + test ! -f "$csha1path" && + test ! -f "$tsha1path" && + git show $fsha1 && + git show $csha1 && + git show $tsha1 +' + +test_expect_success 'unpacked objects receive timestamp of pack file' ' + tmppack=".git/objects/pack/tmp_pack" && + ln "$packfile" "$tmppack" && + git repack -A -l -d && + compare_mtimes "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" ' test_done From d0f19d0471792ace6d440c2789ce42227f07e69e Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 13 Nov 2008 14:20:37 -0600 Subject: [PATCH 125/138] revision.c: use proper data type in call to sizeof() within xrealloc A type char** was being used instead of char*. Signed-off-by: Junio C Hamano --- revision.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/revision.c b/revision.c index 270294af83..45fd7a3660 100644 --- a/revision.c +++ b/revision.c @@ -968,7 +968,7 @@ static void add_ignore_packed(struct rev_info *revs, const char *name) int num = ++revs->num_ignore_packed; revs->ignore_packed = xrealloc(revs->ignore_packed, - sizeof(const char **) * (num + 1)); + sizeof(const char *) * (num + 1)); revs->ignore_packed[num-1] = name; revs->ignore_packed[num] = NULL; } From de07767faefc7ee08e1842b07106aaae55a1a6df Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 14 Nov 2008 13:26:47 +0100 Subject: [PATCH 126/138] Documentation: fix links to "everyday.html" In some places the links are wrong. They should be: "link:everyday.html", instead of: "linkgit:everyday[7]". This patch fixes that. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/gitcore-tutorial.txt | 6 ++++-- Documentation/gitglossary.txt | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Documentation/gitcore-tutorial.txt b/Documentation/gitcore-tutorial.txt index a417e592ac..61fc5d7be8 100644 --- a/Documentation/gitcore-tutorial.txt +++ b/Documentation/gitcore-tutorial.txt @@ -1690,8 +1690,10 @@ to follow, not easier. SEE ALSO -------- -linkgit:gittutorial[7], linkgit:gittutorial-2[7], -linkgit:everyday[7], linkgit:gitcvs-migration[7], +linkgit:gittutorial[7], +linkgit:gittutorial-2[7], +linkgit:gitcvs-migration[7], +link:everyday.html[Everyday git], link:user-manual.html[The Git User's Manual] GIT diff --git a/Documentation/gitglossary.txt b/Documentation/gitglossary.txt index 565719ed5f..d77a45aed6 100644 --- a/Documentation/gitglossary.txt +++ b/Documentation/gitglossary.txt @@ -16,8 +16,10 @@ include::glossary-content.txt[] SEE ALSO -------- -linkgit:gittutorial[7], linkgit:gittutorial-2[7], -linkgit:everyday[7], linkgit:gitcvs-migration[7], +linkgit:gittutorial[7], +linkgit:gittutorial-2[7], +linkgit:gitcvs-migration[7], +link:everyday.html[Everyday git], link:user-manual.html[The Git User's Manual] GIT From 9e77353e0ea6e9e6d88ad1943570afb526d54a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kr=C3=BCger?= Date: Fri, 14 Nov 2008 18:45:14 +0100 Subject: [PATCH 127/138] Documentation: git-svn: fix example for centralized SVN clone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The example that tells users how to centralize the effort of the initial git svn clone operation doesn't work properly. It uses rebase but that only works if HEAD exists. This adds one extra command to create a somewhat sensible HEAD that should work in all cases. Signed-off-by: Jan Krüger Acked-by: Eric Wong Signed-off-by: Junio C Hamano --- Documentation/git-svn.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 82d03b4ced..e160b99bdb 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -522,6 +522,8 @@ have each person clone that repository with 'git-clone': git remote add origin server:/pub/project git config --add remote.origin.fetch '+refs/remotes/*:refs/remotes/*' git fetch +# Create a local branch from one of the branches just fetched + git checkout -b master FETCH_HEAD # Initialize git-svn locally (be sure to use the same URL and -T/-b/-t options as were used on server) git svn init http://svn.example.com/project # Pull the latest changes from Subversion From 07e77e40ff5d2cb6c7e2c5a68d9748f7811da85e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Nov 2008 00:15:43 -0800 Subject: [PATCH 128/138] builtin-ls-files.c: coding style fix. Signed-off-by: Junio C Hamano --- builtin-ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-ls-files.c b/builtin-ls-files.c index b48327db95..21b0bf75f7 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -329,7 +329,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix) if (prefix) { static const char *(matchbuf[2]); matchbuf[0] = prefix; - matchbuf [1] = NULL; + matchbuf[1] = NULL; match = matchbuf; } else match = NULL; From 4b4e26d21f77d9e90125ca1c8f48592a9cd6f543 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Nov 2008 00:10:25 -0800 Subject: [PATCH 129/138] Teach ls-files --with-tree= to work with options other than -c Originally --with-tree= was designed for the sole purpose of checking if a given pathspec makes sense as a parameter to git-commit using it in conjunction with --error-unmatch. It had logic to avoid showing the same entry (one came from the original index, another from the overlayed tree) twice so that it works with -c (i.e. "show-cached"), but otherwise it was not designed to work with the flags such as -m, -d, etc. This teaches the same logic to cover the codepath for -m and -d. Signed-off-by: Junio C Hamano --- builtin-ls-files.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin-ls-files.c b/builtin-ls-files.c index 21b0bf75f7..f72eb85475 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -227,6 +227,8 @@ static void show_files(struct dir_struct *dir, const char *prefix) int dtype = ce_to_dtype(ce); if (excluded(dir, ce->name, &dtype) != dir->show_ignored) continue; + if (ce->ce_flags & CE_UPDATE) + continue; err = lstat(ce->name, &st); if (show_deleted && err) show_ce_entry(tag_removed, ce); From 8c4021abfd170278d1a3431e2777bedd0c01fbb1 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 15 Nov 2008 10:02:01 -0800 Subject: [PATCH 130/138] Fix machine-parseability of 'git log --source' The space between the commit and the source attribute is not easily machine-parseable: if we combine --source with --parents and give a SHA1 as a starting point, it's unnecessarily hard to see where the list of parents ends and the source decoration begins. Example: git show --parents --source $(git rev-list HEAD) which is admittedly contrived, but can easily happen in scripting. So use a instead of a space as the source separator. The other decorations didn't have this issue, because they were surrounded by parenthesis, so it's obvious that they aren't parent SHA1's. It so happens that _visually_ this makes no difference for "git log --source", since "commit <40-char SHA1>" is 47 characters, so both a space and a will end up showing as a single commit. Of course, with '--pretty=oneline' or '--parents' or '--abbrev-commit' you'll see the difference. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log-tree.c b/log-tree.c index 5444f0860b..194ddb13da 100644 --- a/log-tree.c +++ b/log-tree.c @@ -58,7 +58,7 @@ void show_decorations(struct rev_info *opt, struct commit *commit) struct name_decoration *decoration; if (opt->show_source && commit->util) - printf(" %s", (char *) commit->util); + printf("\t%s", (char *) commit->util); if (!opt->show_decorations) return; decoration = lookup_decoration(&name_decoration, &commit->object); From d1f2b362b7937c1ecb0d1b9a21d76b362705b87d Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 16 Nov 2008 03:42:32 +0100 Subject: [PATCH 131/138] git-gui: try to provide a window icon under X When running under X, we try to set up a window icon by providing a hand-crafted 16x16 Tk photo image equivalent to the .ico. Wrap in a catch because the earlier Tcl/Tk 8.4 releases didn't provide the 'wm iconphoto' command. Signed-off-by: Giuseppe Bilotta Signed-off-by: Shawn O. Pearce --- git-gui.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index cf9ef6ee07..6ed6230d3c 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -597,6 +597,28 @@ if {[is_Windows]} { if {![info exists env(DISPLAY)]} { set env(DISPLAY) :9999 } +} else { + catch { + image create photo gitlogo -width 16 -height 16 + + gitlogo put #33CC33 -to 7 0 9 2 + gitlogo put #33CC33 -to 4 2 12 4 + gitlogo put #33CC33 -to 7 4 9 6 + gitlogo put #CC3333 -to 4 6 12 8 + gitlogo put gray26 -to 4 9 6 10 + gitlogo put gray26 -to 3 10 6 12 + gitlogo put gray26 -to 8 9 13 11 + gitlogo put gray26 -to 8 11 10 12 + gitlogo put gray26 -to 11 11 13 14 + gitlogo put gray26 -to 3 12 5 14 + gitlogo put gray26 -to 5 13 + gitlogo put gray26 -to 10 13 + gitlogo put gray26 -to 4 14 12 15 + gitlogo put gray26 -to 5 15 11 16 + gitlogo redither + + wm iconphoto . -default gitlogo + } } ###################################################################### From 153ad78b5074b37215654b1ccb59e67dc5831883 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 16 Nov 2008 21:46:47 +0300 Subject: [PATCH 132/138] git-gui: Implement system-wide configuration handling. With the old implementation any system-wide options appear to be set locally in the current repository. This commit adds explicit handling of system options, essentially interpreting them as customized default_config. The difficulty in interpreting system options stems from the fact that simple 'git config' lists all values, while 'git config --global' only values set in ~/.gitconfig, excluding both local and system options. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce --- git-gui.sh | 12 +++++++++--- lib/option.tcl | 12 ++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 6ed6230d3c..f849e745ba 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -940,19 +940,25 @@ git-version proc _parse_config {arr_name args} { } proc load_config {include_global} { - global repo_config global_config default_config + global repo_config global_config system_config default_config if {$include_global} { + _parse_config system_config --system _parse_config global_config --global } _parse_config repo_config foreach name [array names default_config] { + if {[catch {set v $system_config($name)}]} { + set system_config($name) $default_config($name) + } + } + foreach name [array names system_config] { if {[catch {set v $global_config($name)}]} { - set global_config($name) $default_config($name) + set global_config($name) $system_config($name) } if {[catch {set v $repo_config($name)}]} { - set repo_config($name) $default_config($name) + set repo_config($name) $system_config($name) } } } diff --git a/lib/option.tcl b/lib/option.tcl index c80c939878..1d55b49c9b 100644 --- a/lib/option.tcl +++ b/lib/option.tcl @@ -25,7 +25,7 @@ proc config_check_encodings {} { proc save_config {} { global default_config font_descs - global repo_config global_config + global repo_config global_config system_config global repo_config_new global_config_new global ui_comm_spell @@ -49,7 +49,7 @@ proc save_config {} { foreach name [array names default_config] { set value $global_config_new($name) if {$value ne $global_config($name)} { - if {$value eq $default_config($name)} { + if {$value eq $system_config($name)} { catch {git config --global --unset $name} } else { regsub -all "\[{}\]" $value {"} value @@ -284,17 +284,17 @@ proc do_options {} { } proc do_restore_defaults {} { - global font_descs default_config repo_config + global font_descs default_config repo_config system_config global repo_config_new global_config_new foreach name [array names default_config] { - set repo_config_new($name) $default_config($name) - set global_config_new($name) $default_config($name) + set repo_config_new($name) $system_config($name) + set global_config_new($name) $system_config($name) } foreach option $font_descs { set name [lindex $option 0] - set repo_config(gui.$name) $default_config(gui.$name) + set repo_config(gui.$name) $system_config(gui.$name) } apply_config From 7cf4566f48b7f17c68ab215a9ca6ef7792d9d791 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 16 Nov 2008 21:46:48 +0300 Subject: [PATCH 133/138] git-gui: Fix the after callback execution in rescan. The rescan function receives a callback command as its parameter, which is supposed to be executed after the scan finishes. It is generally used to update status. However, rescan may initiate a loading of a diff, which always calls ui_ready after completion. If the after handler is called before that, ui_ready will override the new status. This commit ensures that the after callback is properly threaded through the diff machinery. Since it uncovered the fact that force_first_diff actually didn't work due to an undeclared global variable, and the desired effects appeared only because of the race condition between the diff system and the rescan callback, I also reimplement this function to make it behave as originally intended. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce --- git-gui.sh | 43 +++++++++++++++++++++++++++++-------------- lib/diff.tcl | 6 +++--- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index f849e745ba..922bcd6796 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1491,10 +1491,8 @@ proc rescan_done {fd buf after} { prune_selection unlock_index display_all_files - if {$current_diff_path ne {}} reshow_diff - if {$current_diff_path eq {}} select_first_diff - - uplevel #0 $after + if {$current_diff_path ne {}} { reshow_diff $after } + if {$current_diff_path eq {}} { select_first_diff $after } } proc prune_selection {} { @@ -2006,16 +2004,16 @@ proc do_rescan {} { } proc ui_do_rescan {} { - rescan {force_first_diff; ui_ready} + rescan {force_first_diff ui_ready} } proc do_commit {} { commit_tree } -proc next_diff {} { +proc next_diff {{after {}}} { global next_diff_p next_diff_w next_diff_i - show_diff $next_diff_p $next_diff_w {} + show_diff $next_diff_p $next_diff_w {} {} $after } proc find_anchor_pos {lst name} { @@ -2100,25 +2098,42 @@ proc next_diff_after_action {w path {lno {}} {mmask {}}} { } } -proc select_first_diff {} { +proc select_first_diff {after} { global ui_workdir if {[find_next_diff $ui_workdir {} 1 {^_?U}] || [find_next_diff $ui_workdir {} 1 {[^O]$}]} { - next_diff + next_diff $after + } else { + uplevel #0 $after } } -proc force_first_diff {} { - global current_diff_path +proc force_first_diff {after} { + global ui_workdir current_diff_path file_states if {[info exists file_states($current_diff_path)]} { set state [lindex $file_states($current_diff_path) 0] - - if {[string index $state 1] ne {O}} return + } else { + set state {OO} } - select_first_diff + set reselect 0 + if {[string first {U} $state] >= 0} { + # Already a conflict, do nothing + } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} { + set reselect 1 + } elseif {[string index $state 1] ne {O}} { + # Already a diff & no conflicts, do nothing + } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} { + set reselect 1 + } + + if {$reselect} { + next_diff $after + } else { + uplevel #0 $after + } } proc toggle_or_diff {w x y} { diff --git a/lib/diff.tcl b/lib/diff.tcl index 94ee38cccc..bbbf15c875 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -16,7 +16,7 @@ proc clear_diff {} { $ui_workdir tag remove in_diff 0.0 end } -proc reshow_diff {} { +proc reshow_diff {{after {}}} { global file_states file_lists global current_diff_path current_diff_side global ui_diff @@ -30,13 +30,13 @@ proc reshow_diff {} { || [lsearch -sorted -exact $file_lists($current_diff_side) $p] == -1} { if {[find_next_diff $current_diff_side $p {} {[^O]}]} { - next_diff + next_diff $after } else { clear_diff } } else { set save_pos [lindex [$ui_diff yview] 0] - show_diff $p $current_diff_side {} $save_pos + show_diff $p $current_diff_side {} $save_pos $after } } From 0ce76ded1b207063a460f859fe7bfeb6d90b4eb6 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 16 Nov 2008 21:46:49 +0300 Subject: [PATCH 134/138] git-gui: Add a Tools menu for arbitrary commands. Due to the emphasis on scriptability in the git design, it is impossible to provide 100% complete GUI. Currently unaccounted areas include git-svn and other source control system interfaces, TopGit, all custom scripts. This problem can be mitigated by providing basic customization capabilities in Git Gui. This commit adds a new Tools menu, which can be configured to contain items invoking arbitrary shell commands. The interface is powerful enough to allow calling both batch text programs like git-svn, and GUI editors. To support the latter use, the commands have access to the name of the currently selected file through the environment. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce --- git-gui.sh | 17 ++++ lib/tools.tcl | 108 +++++++++++++++++++++ lib/tools_dlg.tcl | 234 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 359 insertions(+) create mode 100644 lib/tools.tcl create mode 100644 lib/tools_dlg.tcl diff --git a/git-gui.sh b/git-gui.sh index 922bcd6796..8a4b42dbd7 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2289,6 +2289,9 @@ if {[is_enabled transport]} { .mbar add cascade -label [mc Merge] -menu .mbar.merge .mbar add cascade -label [mc Remote] -menu .mbar.remote } +if {[is_enabled multicommit] || [is_enabled singlecommit]} { + .mbar add cascade -label [mc Tools] -menu .mbar.tools +} . configure -menu .mbar # -- Repository Menu @@ -2563,6 +2566,20 @@ if {[is_MacOSX]} { -command do_options } +# -- Tools Menu +# +if {[is_enabled multicommit] || [is_enabled singlecommit]} { + set tools_menubar .mbar.tools + menu $tools_menubar + $tools_menubar add separator + $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog + $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog + set tools_tailcnt 3 + if {[array names repo_config guitool.*.cmd] ne {}} { + tools_populate_all + } +} + # -- Help Menu # .mbar add cascade -label [mc Help] -menu .mbar.help diff --git a/lib/tools.tcl b/lib/tools.tcl new file mode 100644 index 0000000000..00d46ddab5 --- /dev/null +++ b/lib/tools.tcl @@ -0,0 +1,108 @@ +# git-gui Tools menu implementation + +proc tools_list {} { + global repo_config + + set names {} + foreach item [array names repo_config guitool.*.cmd] { + lappend names [string range $item 8 end-4] + } + return [lsort $names] +} + +proc tools_populate_all {} { + global tools_menubar tools_menutbl + global tools_tailcnt + + set mbar_end [$tools_menubar index end] + set mbar_base [expr {$mbar_end - $tools_tailcnt}] + if {$mbar_base >= 0} { + $tools_menubar delete 0 $mbar_base + } + + array unset tools_menutbl + + foreach fullname [tools_list] { + tools_populate_one $fullname + } +} + +proc tools_create_item {parent args} { + global tools_menubar tools_tailcnt + if {$parent eq $tools_menubar} { + set pos [expr {[$parent index end]-$tools_tailcnt+1}] + eval [list $parent insert $pos] $args + } else { + eval [list $parent add] $args + } +} + +proc tools_populate_one {fullname} { + global tools_menubar tools_menutbl tools_id + + if {![info exists tools_id]} { + set tools_id 0 + } + + set names [split $fullname '/'] + set parent $tools_menubar + for {set i 0} {$i < [llength $names]-1} {incr i} { + set subname [join [lrange $names 0 $i] '/'] + if {[info exists tools_menutbl($subname)]} { + set parent $tools_menutbl($subname) + } else { + set subid $parent.t$tools_id + tools_create_item $parent cascade \ + -label [lindex $names $i] -menu $subid + menu $subid + set tools_menutbl($subname) $subid + set parent $subid + incr tools_id + } + } + + tools_create_item $parent command \ + -label [lindex $names end] \ + -command [list tools_exec $fullname] +} + +proc tools_exec {fullname} { + global repo_config env current_diff_path + global current_branch is_detached + + if {[is_config_true "guitool.$fullname.needsfile"]} { + if {$current_diff_path eq {}} { + error_popup [mc "Running %s requires a selected file." $fullname] + return + } + } + + if {[is_config_true "guitool.$fullname.confirm"]} { + if {[ask_popup [mc "Are you sure you want to run %s?" $fullname]] ne {yes}} { + return + } + } + + set env(GIT_GUITOOL) $fullname + set env(FILENAME) $current_diff_path + if {$is_detached} { + set env(CUR_BRANCH) "" + } else { + set env(CUR_BRANCH) $current_branch + } + + set cmdline $repo_config(guitool.$fullname.cmd) + if {[is_config_true "guitool.$fullname.noconsole"]} { + exec sh -c $cmdline & + } else { + regsub {/} $fullname { / } title + set w [console::new \ + [mc "Tool: %s" $title] \ + [mc "Running: %s" $cmdline]] + console::exec $w [list sh -c $cmdline] + } + + unset env(GIT_GUITOOL) + unset env(FILENAME) + unset env(CUR_BRANCH) +} diff --git a/lib/tools_dlg.tcl b/lib/tools_dlg.tcl new file mode 100644 index 0000000000..c221ba90a1 --- /dev/null +++ b/lib/tools_dlg.tcl @@ -0,0 +1,234 @@ +# git-gui Tools menu dialogs + +class tools_add { + +field w ; # widget path +field w_name ; # new remote name widget +field w_cmd ; # new remote location widget + +field name {}; # name of the tool +field command {}; # command to execute +field add_global 0; # add to the --global config +field no_console 0; # disable using the console +field needs_file 0; # ensure filename is set +field confirm 0; # ask for confirmation + +constructor dialog {} { + global repo_config + + make_toplevel top w + wm title $top [append "[appname] ([reponame]): " [mc "Add Tool"]] + if {$top ne {.}} { + wm geometry $top "+[winfo rootx .]+[winfo rooty .]" + wm transient $top . + } + + label $w.header -text [mc "Add New Tool Command"] -font font_uibold + pack $w.header -side top -fill x + + frame $w.buttons + checkbutton $w.buttons.global \ + -text [mc "Add globally"] \ + -variable @add_global + pack $w.buttons.global -side left -padx 5 + button $w.buttons.create -text [mc Add] \ + -default active \ + -command [cb _add] + pack $w.buttons.create -side right + button $w.buttons.cancel -text [mc Cancel] \ + -command [list destroy $w] + pack $w.buttons.cancel -side right -padx 5 + pack $w.buttons -side bottom -fill x -pady 10 -padx 10 + + labelframe $w.desc -text [mc "Tool Details"] + + label $w.desc.name_cmnt -anchor w\ + -text [mc "Use '/' separators to create a submenu tree:"] + grid x $w.desc.name_cmnt -sticky we -padx {0 5} -pady {0 2} + label $w.desc.name_l -text [mc "Name:"] + set w_name $w.desc.name_t + entry $w_name \ + -borderwidth 1 \ + -relief sunken \ + -width 40 \ + -textvariable @name \ + -validate key \ + -validatecommand [cb _validate_name %d %S] + grid $w.desc.name_l $w_name -sticky we -padx {0 5} + + label $w.desc.cmd_l -text [mc "Command:"] + set w_cmd $w.desc.cmd_t + entry $w_cmd \ + -borderwidth 1 \ + -relief sunken \ + -width 40 \ + -textvariable @command + grid $w.desc.cmd_l $w_cmd -sticky we -padx {0 5} -pady {0 3} + + grid columnconfigure $w.desc 1 -weight 1 + pack $w.desc -anchor nw -fill x -pady 5 -padx 5 + + checkbutton $w.confirm \ + -text [mc "Ask for confirmation before running"] \ + -variable @confirm + pack $w.confirm -anchor w -pady {5 0} -padx 5 + + checkbutton $w.noconsole \ + -text [mc "Don't show the command output window"] \ + -variable @no_console + pack $w.noconsole -anchor w -padx 5 + + checkbutton $w.needsfile \ + -text [mc "Run only if a diff is selected (\$FILENAME not empty)"] \ + -variable @needs_file + pack $w.needsfile -anchor w -padx 5 + + bind $w [cb _visible] + bind $w [list destroy $w] + bind $w [cb _add]\;break + tkwait window $w +} + +method _add {} { + global repo_config + + if {$name eq {}} { + error_popup [mc "Please supply a name for the tool."] + focus $w_name + return + } + + set item "guitool.$name.cmd" + + if {[info exists repo_config($item)]} { + error_popup [mc "Tool '%s' already exists." $name] + focus $w_name + return + } + + set cmd [list git config] + if {$add_global} { lappend cmd --global } + set items {} + if {$no_console} { lappend items "guitool.$name.noconsole" } + if {$confirm} { lappend items "guitool.$name.confirm" } + if {$needs_file} { lappend items "guitool.$name.needsfile" } + + if {[catch { + eval $cmd [list $item $command] + foreach citem $items { eval $cmd [list $citem yes] } + } err]} { + error_popup [mc "Could not add tool:\n%s" $err] + } else { + set repo_config($item) $command + foreach citem $items { set repo_config($citem) yes } + + tools_populate_all + } + + destroy $w +} + +method _validate_name {d S} { + if {$d == 1} { + if {[regexp {[~?*&\[\0\"\\\{]} $S]} { + return 0 + } + } + return 1 +} + +method _visible {} { + grab $w + $w_name icursor end + focus $w_name +} + +} + +class tools_remove { + +field w ; # widget path +field w_names ; # name list + +constructor dialog {} { + global repo_config global_config system_config + + load_config 1 + + make_toplevel top w + wm title $top [append "[appname] ([reponame]): " [mc "Remove Tool"]] + if {$top ne {.}} { + wm geometry $top "+[winfo rootx .]+[winfo rooty .]" + wm transient $top . + } + + label $w.header -text [mc "Remove Tool Commands"] -font font_uibold + pack $w.header -side top -fill x + + frame $w.buttons + button $w.buttons.create -text [mc Remove] \ + -default active \ + -command [cb _remove] + pack $w.buttons.create -side right + button $w.buttons.cancel -text [mc Cancel] \ + -command [list destroy $w] + pack $w.buttons.cancel -side right -padx 5 + pack $w.buttons -side bottom -fill x -pady 10 -padx 10 + + frame $w.list + set w_names $w.list.l + listbox $w_names \ + -height 10 \ + -width 30 \ + -selectmode extended \ + -exportselection false \ + -yscrollcommand [list $w.list.sby set] + scrollbar $w.list.sby -command [list $w.list.l yview] + pack $w.list.sby -side right -fill y + pack $w.list.l -side left -fill both -expand 1 + pack $w.list -fill both -expand 1 -pady 5 -padx 5 + + set local_cnt 0 + foreach fullname [tools_list] { + # Cannot delete system tools + if {[info exists system_config(guitool.$fullname.cmd)]} continue + + $w_names insert end $fullname + if {![info exists global_config(guitool.$fullname.cmd)]} { + $w_names itemconfigure end -foreground blue + incr local_cnt + } + } + + if {$local_cnt > 0} { + label $w.colorlbl -foreground blue \ + -text [mc "(Blue denotes repository-local tools)"] + pack $w.colorlbl -fill x -pady 5 -padx 5 + } + + bind $w [cb _visible] + bind $w [list destroy $w] + bind $w [cb _remove]\;break + tkwait window $w +} + +method _remove {} { + foreach i [$w_names curselection] { + set name [$w_names get $i] + + catch { git config --remove-section guitool.$name } + catch { git config --global --remove-section guitool.$name } + } + + load_config 0 + tools_populate_all + + destroy $w +} + +method _visible {} { + grab $w + focus $w_names +} + +} From 67df911ceebb57596b0d3aea405e1d12137bc6f4 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 16 Nov 2008 21:46:50 +0300 Subject: [PATCH 135/138] git-gui: Allow Tools request arguments from the user. While static commands are already useful, some tools need additional parameters to reach maximum usability. This commit adds support for passing them one revision name parameter, and one arbitrary string. With this addition, the tools menu becomes flexible enough to implement basic rebase support: [core] editor = kwrite [guitool "Rebase/Abort"] cmd = git rebase --abort confirm = yes [guitool "Rebase/Continue"] cmd = git rebase --continue [guitool "Rebase/Skip Commit"] cmd = git rebase --skip confirm = yes [guitool "Rebase/Start..."] cmd = git rebase $ARGS $REVISION $CUR_BRANCH title = Start Rebase prompt = Rebase Current Branch argprompt = Flags revprompt = New Base revunmerged = yes Some of the options, like title or prompt, are intentionally not included in the Add dialog to avoid clutter. Also, the dialog handles argprompt and revprompt as boolean vars. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce --- lib/tools.tcl | 13 +++- lib/tools_dlg.tcl | 195 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 203 insertions(+), 5 deletions(-) diff --git a/lib/tools.tcl b/lib/tools.tcl index 00d46ddab5..044432e39e 100644 --- a/lib/tools.tcl +++ b/lib/tools.tcl @@ -77,7 +77,16 @@ proc tools_exec {fullname} { } } - if {[is_config_true "guitool.$fullname.confirm"]} { + catch { unset env(ARGS) } + catch { unset env(REVISION) } + + if {[get_config "guitool.$fullname.revprompt"] ne {} || + [get_config "guitool.$fullname.argprompt"] ne {}} { + set dlg [tools_askdlg::dialog $fullname] + if {![tools_askdlg::execute $dlg]} { + return + } + } elseif {[is_config_true "guitool.$fullname.confirm"]} { if {[ask_popup [mc "Are you sure you want to run %s?" $fullname]] ne {yes}} { return } @@ -105,4 +114,6 @@ proc tools_exec {fullname} { unset env(GIT_GUITOOL) unset env(FILENAME) unset env(CUR_BRANCH) + catch { unset env(ARGS) } + catch { unset env(REVISION) } } diff --git a/lib/tools_dlg.tcl b/lib/tools_dlg.tcl index c221ba90a1..5f7f08e239 100644 --- a/lib/tools_dlg.tcl +++ b/lib/tools_dlg.tcl @@ -12,6 +12,8 @@ field add_global 0; # add to the --global config field no_console 0; # disable using the console field needs_file 0; # ensure filename is set field confirm 0; # ask for confirmation +field ask_branch 0; # ask for a revision +field ask_args 0; # ask for additional args constructor dialog {} { global repo_config @@ -69,9 +71,22 @@ constructor dialog {} { pack $w.desc -anchor nw -fill x -pady 5 -padx 5 checkbutton $w.confirm \ - -text [mc "Ask for confirmation before running"] \ - -variable @confirm - pack $w.confirm -anchor w -pady {5 0} -padx 5 + -text [mc "Show a dialog before running"] \ + -variable @confirm -command [cb _check_enable_dlg] + + labelframe $w.dlg -labelwidget $w.confirm + + checkbutton $w.dlg.askbranch \ + -text [mc "Ask the user to select a revision (sets \$REVISION)"] \ + -variable @ask_branch -state disabled + pack $w.dlg.askbranch -anchor w -padx 15 + + checkbutton $w.dlg.askargs \ + -text [mc "Ask the user for additional arguments (sets \$ARGS)"] \ + -variable @ask_args -state disabled + pack $w.dlg.askargs -anchor w -padx 15 + + pack $w.dlg -anchor nw -fill x -pady {0 8} -padx 5 checkbutton $w.noconsole \ -text [mc "Don't show the command output window"] \ @@ -89,6 +104,16 @@ constructor dialog {} { tkwait window $w } +method _check_enable_dlg {} { + if {$confirm} { + $w.dlg.askbranch configure -state normal + $w.dlg.askargs configure -state normal + } else { + $w.dlg.askbranch configure -state disabled + $w.dlg.askargs configure -state disabled + } +} + method _add {} { global repo_config @@ -110,8 +135,14 @@ method _add {} { if {$add_global} { lappend cmd --global } set items {} if {$no_console} { lappend items "guitool.$name.noconsole" } - if {$confirm} { lappend items "guitool.$name.confirm" } if {$needs_file} { lappend items "guitool.$name.needsfile" } + if {$confirm} { + if {$ask_args} { lappend items "guitool.$name.argprompt" } + if {$ask_branch} { lappend items "guitool.$name.revprompt" } + if {!$ask_args && !$ask_branch} { + lappend items "guitool.$name.confirm" + } + } if {[catch { eval $cmd [list $item $command] @@ -232,3 +263,159 @@ method _visible {} { } } + +class tools_askdlg { + +field w ; # widget path +field w_rev {}; # revision browser +field w_args {}; # arguments + +field is_ask_args 0; # has arguments field +field is_ask_revs 0; # has revision browser + +field is_ok 0; # ok to start +field argstr {}; # arguments + +constructor dialog {fullname} { + global M1B + + set title [get_config "guitool.$fullname.title"] + if {$title eq {}} { + regsub {/} $fullname { / } title + } + + make_toplevel top w -autodelete 0 + wm title $top [append "[appname] ([reponame]): " $title] + if {$top ne {.}} { + wm geometry $top "+[winfo rootx .]+[winfo rooty .]" + wm transient $top . + } + + set prompt [get_config "guitool.$fullname.prompt"] + if {$prompt eq {}} { + set command [get_config "guitool.$fullname.cmd"] + set prompt [mc "Run Command: %s" $command] + } + + label $w.header -text $prompt -font font_uibold + pack $w.header -side top -fill x + + set argprompt [get_config "guitool.$fullname.argprompt"] + set revprompt [get_config "guitool.$fullname.revprompt"] + + set is_ask_args [expr {$argprompt ne {}}] + set is_ask_revs [expr {$revprompt ne {}}] + + if {$is_ask_args} { + if {$argprompt eq {yes} || $argprompt eq {true} || $argprompt eq {1}} { + set argprompt [mc "Arguments"] + } + + labelframe $w.arg -text $argprompt + + set w_args $w.arg.txt + entry $w_args \ + -borderwidth 1 \ + -relief sunken \ + -width 40 \ + -textvariable @argstr + pack $w_args -padx 5 -pady 5 -fill both + pack $w.arg -anchor nw -fill both -pady 5 -padx 5 + } + + if {$is_ask_revs} { + if {$revprompt eq {yes} || $revprompt eq {true} || $revprompt eq {1}} { + set revprompt [mc "Revision"] + } + + if {[is_config_true "guitool.$fullname.revunmerged"]} { + set w_rev [::choose_rev::new_unmerged $w.rev $revprompt] + } else { + set w_rev [::choose_rev::new $w.rev $revprompt] + } + + pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5 + } + + frame $w.buttons + if {$is_ask_revs} { + button $w.buttons.visualize \ + -text [mc Visualize] \ + -command [cb _visualize] + pack $w.buttons.visualize -side left + } + button $w.buttons.ok \ + -text [mc OK] \ + -command [cb _start] + pack $w.buttons.ok -side right + button $w.buttons.cancel \ + -text [mc "Cancel"] \ + -command [cb _cancel] + pack $w.buttons.cancel -side right -padx 5 + pack $w.buttons -side bottom -fill x -pady 10 -padx 10 + + bind $w <$M1B-Key-Return> [cb _start] + bind $w [cb _start] + bind $w [cb _cancel] + wm protocol $w WM_DELETE_WINDOW [cb _cancel] + + bind $w [cb _visible] + return $this +} + +method execute {} { + tkwait window $w + set rv $is_ok + delete_this + return $rv +} + +method _visible {} { + grab $w + if {$is_ask_args} { + focus $w_args + } elseif {$is_ask_revs} { + $w_rev focus_filter + } +} + +method _cancel {} { + wm protocol $w WM_DELETE_WINDOW {} + destroy $w +} + +method _rev {} { + if {[catch {$w_rev commit_or_die}]} { + return {} + } + return [$w_rev get] +} + +method _visualize {} { + global current_branch + set rev [_rev $this] + if {$rev ne {}} { + do_gitk [list --left-right "$current_branch...$rev"] + } +} + +method _start {} { + global env + + if {$is_ask_revs} { + set name [_rev $this] + if {$name eq {}} { + return + } + set env(REVISION) $name + } + + if {$is_ask_args} { + set env(ARGS) $argstr + } + + set is_ok 1 + _cancel $this +} + +} From b8dfb16d3668c57b1286d854e762368c25a2eaaf Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 16 Nov 2008 21:46:51 +0300 Subject: [PATCH 136/138] git-gui: Implement automatic rescan after Tool execution. The Tools menu is generally intended for commands that affect the working directory or repository state. Thus, the user would usually want to initiate rescan after execution of a tool. This commit implements it. In case somebody would want to avoid rescanning after certain tools, it also adds an option that controls it, although it is not made available through the Add dialog. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce --- lib/tools.tcl | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/tools.tcl b/lib/tools.tcl index 044432e39e..6ae63b6c7c 100644 --- a/lib/tools.tcl +++ b/lib/tools.tcl @@ -102,13 +102,15 @@ proc tools_exec {fullname} { set cmdline $repo_config(guitool.$fullname.cmd) if {[is_config_true "guitool.$fullname.noconsole"]} { - exec sh -c $cmdline & + tools_run_silent [list sh -c $cmdline] \ + [list tools_complete $fullname {}] } else { regsub {/} $fullname { / } title set w [console::new \ [mc "Tool: %s" $title] \ [mc "Running: %s" $cmdline]] - console::exec $w [list sh -c $cmdline] + console::exec $w [list sh -c $cmdline] \ + [list tools_complete $fullname $w] } unset env(GIT_GUITOOL) @@ -117,3 +119,41 @@ proc tools_exec {fullname} { catch { unset env(ARGS) } catch { unset env(REVISION) } } + +proc tools_run_silent {cmd after} { + lappend cmd 2>@1 + set fd [_open_stdout_stderr $cmd] + + fconfigure $fd -blocking 0 -translation binary + fileevent $fd readable [list tools_consume_input $fd $after] +} + +proc tools_consume_input {fd after} { + read $fd + if {[eof $fd]} { + fconfigure $fd -blocking 1 + if {[catch {close $fd}]} { + uplevel #0 $after 0 + } else { + uplevel #0 $after 1 + } + } +} + +proc tools_complete {fullname w {ok 1}} { + if {$w ne {}} { + console::done $w $ok + } + + if {$ok} { + set msg [mc "Tool completed succesfully: %s" $fullname] + } else { + set msg [mc "Tool failed: %s" $fullname] + } + + if {[is_config_true "guitool.$fullname.norescan"]} { + ui_status $msg + } else { + rescan [list ui_status $msg] + } +} From bd45bd91e6606bea77a02a979a3a48cf058d981d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 16 Nov 2008 13:56:55 -0800 Subject: [PATCH 137/138] Update the po template Signed-off-by: Shawn O. Pearce --- po/git-gui.pot | 1132 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 819 insertions(+), 313 deletions(-) diff --git a/po/git-gui.pot b/po/git-gui.pot index e295000e77..58db67c217 100644 --- a/po/git-gui.pot +++ b/po/git-gui.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-08-02 14:45-0700\n" +"POT-Creation-Date: 2008-11-16 13:56-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,33 +16,33 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: git-gui.sh:41 git-gui.sh:688 git-gui.sh:702 git-gui.sh:715 git-gui.sh:798 -#: git-gui.sh:817 +#: git-gui.sh:41 git-gui.sh:737 git-gui.sh:751 git-gui.sh:764 git-gui.sh:847 +#: git-gui.sh:866 msgid "git-gui: fatal error" msgstr "" -#: git-gui.sh:644 +#: git-gui.sh:689 #, tcl-format msgid "Invalid font specified in %s:" msgstr "" -#: git-gui.sh:674 +#: git-gui.sh:723 msgid "Main Font" msgstr "" -#: git-gui.sh:675 +#: git-gui.sh:724 msgid "Diff/Console Font" msgstr "" -#: git-gui.sh:689 +#: git-gui.sh:738 msgid "Cannot find git in PATH." msgstr "" -#: git-gui.sh:716 +#: git-gui.sh:765 msgid "Cannot parse Git version string:" msgstr "" -#: git-gui.sh:734 +#: git-gui.sh:783 #, tcl-format msgid "" "Git version cannot be determined.\n" @@ -54,379 +54,444 @@ msgid "" "Assume '%s' is version 1.5.0?\n" msgstr "" -#: git-gui.sh:972 +#: git-gui.sh:1062 msgid "Git directory not found:" msgstr "" -#: git-gui.sh:979 +#: git-gui.sh:1069 msgid "Cannot move to top of working directory:" msgstr "" -#: git-gui.sh:986 +#: git-gui.sh:1076 msgid "Cannot use funny .git directory:" msgstr "" -#: git-gui.sh:991 +#: git-gui.sh:1081 msgid "No working directory" msgstr "" -#: git-gui.sh:1138 lib/checkout_op.tcl:305 +#: git-gui.sh:1247 lib/checkout_op.tcl:305 msgid "Refreshing file status..." msgstr "" -#: git-gui.sh:1194 +#: git-gui.sh:1303 msgid "Scanning for modified files ..." msgstr "" -#: git-gui.sh:1369 lib/browser.tcl:246 +#: git-gui.sh:1367 +msgid "Calling prepare-commit-msg hook..." +msgstr "" + +#: git-gui.sh:1384 +msgid "Commit declined by prepare-commit-msg hook." +msgstr "" + +#: git-gui.sh:1542 lib/browser.tcl:246 msgid "Ready." msgstr "" -#: git-gui.sh:1635 +#: git-gui.sh:1819 msgid "Unmodified" msgstr "" -#: git-gui.sh:1637 +#: git-gui.sh:1821 msgid "Modified, not staged" msgstr "" -#: git-gui.sh:1638 git-gui.sh:1643 +#: git-gui.sh:1822 git-gui.sh:1830 msgid "Staged for commit" msgstr "" -#: git-gui.sh:1639 git-gui.sh:1644 +#: git-gui.sh:1823 git-gui.sh:1831 msgid "Portions staged for commit" msgstr "" -#: git-gui.sh:1640 git-gui.sh:1645 +#: git-gui.sh:1824 git-gui.sh:1832 msgid "Staged for commit, missing" msgstr "" -#: git-gui.sh:1642 +#: git-gui.sh:1826 +msgid "File type changed, not staged" +msgstr "" + +#: git-gui.sh:1827 +msgid "File type changed, staged" +msgstr "" + +#: git-gui.sh:1829 msgid "Untracked, not staged" msgstr "" -#: git-gui.sh:1647 +#: git-gui.sh:1834 msgid "Missing" msgstr "" -#: git-gui.sh:1648 +#: git-gui.sh:1835 msgid "Staged for removal" msgstr "" -#: git-gui.sh:1649 +#: git-gui.sh:1836 msgid "Staged for removal, still present" msgstr "" -#: git-gui.sh:1651 git-gui.sh:1652 git-gui.sh:1653 git-gui.sh:1654 +#: git-gui.sh:1838 git-gui.sh:1839 git-gui.sh:1840 git-gui.sh:1841 +#: git-gui.sh:1842 git-gui.sh:1843 msgid "Requires merge resolution" msgstr "" -#: git-gui.sh:1689 +#: git-gui.sh:1878 msgid "Starting gitk... please wait..." msgstr "" -#: git-gui.sh:1698 +#: git-gui.sh:1887 msgid "Couldn't find gitk in PATH" msgstr "" -#: git-gui.sh:1948 lib/choose_repository.tcl:36 +#: git-gui.sh:2280 lib/choose_repository.tcl:36 msgid "Repository" msgstr "" -#: git-gui.sh:1949 +#: git-gui.sh:2281 msgid "Edit" msgstr "" -#: git-gui.sh:1951 lib/choose_rev.tcl:561 +#: git-gui.sh:2283 lib/choose_rev.tcl:561 msgid "Branch" msgstr "" -#: git-gui.sh:1954 lib/choose_rev.tcl:548 +#: git-gui.sh:2286 lib/choose_rev.tcl:548 msgid "Commit@@noun" msgstr "" -#: git-gui.sh:1957 lib/merge.tcl:120 lib/merge.tcl:149 lib/merge.tcl:167 +#: git-gui.sh:2289 lib/merge.tcl:121 lib/merge.tcl:150 lib/merge.tcl:168 msgid "Merge" msgstr "" -#: git-gui.sh:1958 lib/choose_rev.tcl:557 +#: git-gui.sh:2290 lib/choose_rev.tcl:557 msgid "Remote" msgstr "" -#: git-gui.sh:1967 +#: git-gui.sh:2293 +msgid "Tools" +msgstr "" + +#: git-gui.sh:2302 +msgid "Explore Working Copy" +msgstr "" + +#: git-gui.sh:2307 msgid "Browse Current Branch's Files" msgstr "" -#: git-gui.sh:1971 +#: git-gui.sh:2311 msgid "Browse Branch Files..." msgstr "" -#: git-gui.sh:1976 +#: git-gui.sh:2316 msgid "Visualize Current Branch's History" msgstr "" -#: git-gui.sh:1980 +#: git-gui.sh:2320 msgid "Visualize All Branch History" msgstr "" -#: git-gui.sh:1987 +#: git-gui.sh:2327 #, tcl-format msgid "Browse %s's Files" msgstr "" -#: git-gui.sh:1989 +#: git-gui.sh:2329 #, tcl-format msgid "Visualize %s's History" msgstr "" -#: git-gui.sh:1994 lib/database.tcl:27 lib/database.tcl:67 +#: git-gui.sh:2334 lib/database.tcl:27 lib/database.tcl:67 msgid "Database Statistics" msgstr "" -#: git-gui.sh:1997 lib/database.tcl:34 +#: git-gui.sh:2337 lib/database.tcl:34 msgid "Compress Database" msgstr "" -#: git-gui.sh:2000 +#: git-gui.sh:2340 msgid "Verify Database" msgstr "" -#: git-gui.sh:2007 git-gui.sh:2011 git-gui.sh:2015 lib/shortcut.tcl:7 +#: git-gui.sh:2347 git-gui.sh:2351 git-gui.sh:2355 lib/shortcut.tcl:7 #: lib/shortcut.tcl:39 lib/shortcut.tcl:71 msgid "Create Desktop Icon" msgstr "" -#: git-gui.sh:2023 lib/choose_repository.tcl:177 lib/choose_repository.tcl:185 +#: git-gui.sh:2363 lib/choose_repository.tcl:183 lib/choose_repository.tcl:191 msgid "Quit" msgstr "" -#: git-gui.sh:2031 +#: git-gui.sh:2371 msgid "Undo" msgstr "" -#: git-gui.sh:2034 +#: git-gui.sh:2374 msgid "Redo" msgstr "" -#: git-gui.sh:2038 git-gui.sh:2545 +#: git-gui.sh:2378 git-gui.sh:2923 msgid "Cut" msgstr "" -#: git-gui.sh:2041 git-gui.sh:2548 git-gui.sh:2622 git-gui.sh:2715 +#: git-gui.sh:2381 git-gui.sh:2926 git-gui.sh:3000 git-gui.sh:3082 #: lib/console.tcl:69 msgid "Copy" msgstr "" -#: git-gui.sh:2044 git-gui.sh:2551 +#: git-gui.sh:2384 git-gui.sh:2929 msgid "Paste" msgstr "" -#: git-gui.sh:2047 git-gui.sh:2554 lib/branch_delete.tcl:26 +#: git-gui.sh:2387 git-gui.sh:2932 lib/branch_delete.tcl:26 #: lib/remote_branch_delete.tcl:38 msgid "Delete" msgstr "" -#: git-gui.sh:2051 git-gui.sh:2558 git-gui.sh:2719 lib/console.tcl:71 +#: git-gui.sh:2391 git-gui.sh:2936 git-gui.sh:3086 lib/console.tcl:71 msgid "Select All" msgstr "" -#: git-gui.sh:2060 +#: git-gui.sh:2400 msgid "Create..." msgstr "" -#: git-gui.sh:2066 +#: git-gui.sh:2406 msgid "Checkout..." msgstr "" -#: git-gui.sh:2072 +#: git-gui.sh:2412 msgid "Rename..." msgstr "" -#: git-gui.sh:2077 git-gui.sh:2187 +#: git-gui.sh:2417 msgid "Delete..." msgstr "" -#: git-gui.sh:2082 +#: git-gui.sh:2422 msgid "Reset..." msgstr "" -#: git-gui.sh:2094 git-gui.sh:2491 -msgid "New Commit" +#: git-gui.sh:2432 +msgid "Done" msgstr "" -#: git-gui.sh:2102 git-gui.sh:2498 -msgid "Amend Last Commit" -msgstr "" - -#: git-gui.sh:2111 git-gui.sh:2458 lib/remote_branch_delete.tcl:99 -msgid "Rescan" -msgstr "" - -#: git-gui.sh:2117 -msgid "Stage To Commit" -msgstr "" - -#: git-gui.sh:2123 -msgid "Stage Changed Files To Commit" -msgstr "" - -#: git-gui.sh:2129 -msgid "Unstage From Commit" -msgstr "" - -#: git-gui.sh:2134 lib/index.tcl:395 -msgid "Revert Changes" -msgstr "" - -#: git-gui.sh:2141 git-gui.sh:2702 -msgid "Show Less Context" -msgstr "" - -#: git-gui.sh:2145 git-gui.sh:2706 -msgid "Show More Context" -msgstr "" - -#: git-gui.sh:2151 git-gui.sh:2470 git-gui.sh:2569 -msgid "Sign Off" -msgstr "" - -#: git-gui.sh:2155 git-gui.sh:2474 +#: git-gui.sh:2434 msgid "Commit@@verb" msgstr "" -#: git-gui.sh:2166 +#: git-gui.sh:2443 git-gui.sh:2864 +msgid "New Commit" +msgstr "" + +#: git-gui.sh:2451 git-gui.sh:2871 +msgid "Amend Last Commit" +msgstr "" + +#: git-gui.sh:2461 git-gui.sh:2825 lib/remote_branch_delete.tcl:99 +msgid "Rescan" +msgstr "" + +#: git-gui.sh:2467 +msgid "Stage To Commit" +msgstr "" + +#: git-gui.sh:2473 +msgid "Stage Changed Files To Commit" +msgstr "" + +#: git-gui.sh:2479 +msgid "Unstage From Commit" +msgstr "" + +#: git-gui.sh:2484 lib/index.tcl:410 +msgid "Revert Changes" +msgstr "" + +#: git-gui.sh:2491 git-gui.sh:3069 +msgid "Show Less Context" +msgstr "" + +#: git-gui.sh:2495 git-gui.sh:3073 +msgid "Show More Context" +msgstr "" + +#: git-gui.sh:2502 git-gui.sh:2838 git-gui.sh:2947 +msgid "Sign Off" +msgstr "" + +#: git-gui.sh:2518 msgid "Local Merge..." msgstr "" -#: git-gui.sh:2171 +#: git-gui.sh:2523 msgid "Abort Merge..." msgstr "" -#: git-gui.sh:2183 +#: git-gui.sh:2535 git-gui.sh:2575 +msgid "Add..." +msgstr "" + +#: git-gui.sh:2539 msgid "Push..." msgstr "" -#: git-gui.sh:2197 git-gui.sh:2219 lib/about.tcl:14 -#: lib/choose_repository.tcl:44 lib/choose_repository.tcl:50 +#: git-gui.sh:2543 +msgid "Delete Branch..." +msgstr "" + +#: git-gui.sh:2553 git-gui.sh:2589 lib/about.tcl:14 +#: lib/choose_repository.tcl:44 lib/choose_repository.tcl:53 #, tcl-format msgid "About %s" msgstr "" -#: git-gui.sh:2201 +#: git-gui.sh:2557 msgid "Preferences..." msgstr "" -#: git-gui.sh:2209 git-gui.sh:2740 +#: git-gui.sh:2565 git-gui.sh:3115 msgid "Options..." msgstr "" -#: git-gui.sh:2215 lib/choose_repository.tcl:47 +#: git-gui.sh:2576 +msgid "Remove..." +msgstr "" + +#: git-gui.sh:2585 lib/choose_repository.tcl:50 msgid "Help" msgstr "" -#: git-gui.sh:2256 +#: git-gui.sh:2611 msgid "Online Documentation" msgstr "" -#: git-gui.sh:2340 +#: git-gui.sh:2614 lib/choose_repository.tcl:47 lib/choose_repository.tcl:56 +msgid "Show SSH Key" +msgstr "" + +#: git-gui.sh:2707 #, tcl-format msgid "fatal: cannot stat path %s: No such file or directory" msgstr "" -#: git-gui.sh:2373 +#: git-gui.sh:2740 msgid "Current Branch:" msgstr "" -#: git-gui.sh:2394 +#: git-gui.sh:2761 msgid "Staged Changes (Will Commit)" msgstr "" -#: git-gui.sh:2414 +#: git-gui.sh:2781 msgid "Unstaged Changes" msgstr "" -#: git-gui.sh:2464 +#: git-gui.sh:2831 msgid "Stage Changed" msgstr "" -#: git-gui.sh:2480 lib/transport.tcl:93 lib/transport.tcl:182 +#: git-gui.sh:2850 lib/transport.tcl:93 lib/transport.tcl:182 msgid "Push" msgstr "" -#: git-gui.sh:2510 +#: git-gui.sh:2885 msgid "Initial Commit Message:" msgstr "" -#: git-gui.sh:2511 +#: git-gui.sh:2886 msgid "Amended Commit Message:" msgstr "" -#: git-gui.sh:2512 +#: git-gui.sh:2887 msgid "Amended Initial Commit Message:" msgstr "" -#: git-gui.sh:2513 +#: git-gui.sh:2888 msgid "Amended Merge Commit Message:" msgstr "" -#: git-gui.sh:2514 +#: git-gui.sh:2889 msgid "Merge Commit Message:" msgstr "" -#: git-gui.sh:2515 +#: git-gui.sh:2890 msgid "Commit Message:" msgstr "" -#: git-gui.sh:2561 git-gui.sh:2723 lib/console.tcl:73 +#: git-gui.sh:2939 git-gui.sh:3090 lib/console.tcl:73 msgid "Copy All" msgstr "" -#: git-gui.sh:2585 lib/blame.tcl:100 +#: git-gui.sh:2963 lib/blame.tcl:104 msgid "File:" msgstr "" -#: git-gui.sh:2691 -msgid "Apply/Reverse Hunk" -msgstr "" - -#: git-gui.sh:2696 -msgid "Apply/Reverse Line" -msgstr "" - -#: git-gui.sh:2711 +#: git-gui.sh:3078 msgid "Refresh" msgstr "" -#: git-gui.sh:2732 +#: git-gui.sh:3099 msgid "Decrease Font Size" msgstr "" -#: git-gui.sh:2736 +#: git-gui.sh:3103 msgid "Increase Font Size" msgstr "" -#: git-gui.sh:2747 +#: git-gui.sh:3111 lib/blame.tcl:281 +msgid "Encoding" +msgstr "" + +#: git-gui.sh:3122 +msgid "Apply/Reverse Hunk" +msgstr "" + +#: git-gui.sh:3127 +msgid "Apply/Reverse Line" +msgstr "" + +#: git-gui.sh:3137 +msgid "Run Merge Tool" +msgstr "" + +#: git-gui.sh:3142 +msgid "Use Remote Version" +msgstr "" + +#: git-gui.sh:3146 +msgid "Use Local Version" +msgstr "" + +#: git-gui.sh:3150 +msgid "Revert To Base" +msgstr "" + +#: git-gui.sh:3169 msgid "Unstage Hunk From Commit" msgstr "" -#: git-gui.sh:2748 +#: git-gui.sh:3170 msgid "Unstage Line From Commit" msgstr "" -#: git-gui.sh:2750 +#: git-gui.sh:3172 msgid "Stage Hunk For Commit" msgstr "" -#: git-gui.sh:2751 +#: git-gui.sh:3173 msgid "Stage Line For Commit" msgstr "" -#: git-gui.sh:2771 +#: git-gui.sh:3196 msgid "Initializing..." msgstr "" -#: git-gui.sh:2876 +#: git-gui.sh:3301 #, tcl-format msgid "" "Possible environment issues exist.\n" @@ -437,14 +502,14 @@ msgid "" "\n" msgstr "" -#: git-gui.sh:2906 +#: git-gui.sh:3331 msgid "" "\n" "This is due to a known issue with the\n" "Tcl binary distributed by Cygwin." msgstr "" -#: git-gui.sh:2911 +#: git-gui.sh:3336 #, tcl-format msgid "" "\n" @@ -459,80 +524,108 @@ msgstr "" msgid "git-gui - a graphical user interface for Git." msgstr "" -#: lib/blame.tcl:70 +#: lib/blame.tcl:72 msgid "File Viewer" msgstr "" -#: lib/blame.tcl:74 +#: lib/blame.tcl:78 msgid "Commit:" msgstr "" -#: lib/blame.tcl:257 +#: lib/blame.tcl:271 msgid "Copy Commit" msgstr "" -#: lib/blame.tcl:260 +#: lib/blame.tcl:275 +msgid "Find Text..." +msgstr "" + +#: lib/blame.tcl:284 msgid "Do Full Copy Detection" msgstr "" -#: lib/blame.tcl:388 +#: lib/blame.tcl:288 +msgid "Show History Context" +msgstr "" + +#: lib/blame.tcl:291 +msgid "Blame Parent Commit" +msgstr "" + +#: lib/blame.tcl:450 #, tcl-format msgid "Reading %s..." msgstr "" -#: lib/blame.tcl:492 +#: lib/blame.tcl:557 msgid "Loading copy/move tracking annotations..." msgstr "" -#: lib/blame.tcl:512 +#: lib/blame.tcl:577 msgid "lines annotated" msgstr "" -#: lib/blame.tcl:704 +#: lib/blame.tcl:769 msgid "Loading original location annotations..." msgstr "" -#: lib/blame.tcl:707 +#: lib/blame.tcl:772 msgid "Annotation complete." msgstr "" -#: lib/blame.tcl:737 +#: lib/blame.tcl:802 msgid "Busy" msgstr "" -#: lib/blame.tcl:738 +#: lib/blame.tcl:803 msgid "Annotation process is already running." msgstr "" -#: lib/blame.tcl:777 +#: lib/blame.tcl:842 msgid "Running thorough copy detection..." msgstr "" -#: lib/blame.tcl:827 +#: lib/blame.tcl:910 msgid "Loading annotation..." msgstr "" -#: lib/blame.tcl:883 +#: lib/blame.tcl:964 msgid "Author:" msgstr "" -#: lib/blame.tcl:887 +#: lib/blame.tcl:968 msgid "Committer:" msgstr "" -#: lib/blame.tcl:892 +#: lib/blame.tcl:973 msgid "Original File:" msgstr "" -#: lib/blame.tcl:1006 +#: lib/blame.tcl:1021 +msgid "Cannot find HEAD commit:" +msgstr "" + +#: lib/blame.tcl:1076 +msgid "Cannot find parent commit:" +msgstr "" + +#: lib/blame.tcl:1091 +msgid "Unable to display parent" +msgstr "" + +#: lib/blame.tcl:1092 lib/diff.tcl:297 +msgid "Error loading diff:" +msgstr "" + +#: lib/blame.tcl:1232 msgid "Originally By:" msgstr "" -#: lib/blame.tcl:1012 +#: lib/blame.tcl:1238 msgid "In File:" msgstr "" -#: lib/blame.tcl:1017 +#: lib/blame.tcl:1243 msgid "Copied Or Moved Here By:" msgstr "" @@ -546,16 +639,18 @@ msgstr "" #: lib/branch_checkout.tcl:27 lib/branch_create.tcl:35 #: lib/branch_delete.tcl:32 lib/branch_rename.tcl:30 lib/browser.tcl:282 -#: lib/checkout_op.tcl:544 lib/choose_font.tcl:43 lib/merge.tcl:171 -#: lib/option.tcl:103 lib/remote_branch_delete.tcl:42 lib/transport.tcl:97 +#: lib/checkout_op.tcl:544 lib/choose_font.tcl:43 lib/merge.tcl:172 +#: lib/option.tcl:125 lib/remote_add.tcl:32 lib/remote_branch_delete.tcl:42 +#: lib/tools_dlg.tcl:40 lib/tools_dlg.tcl:204 lib/tools_dlg.tcl:352 +#: lib/transport.tcl:97 msgid "Cancel" msgstr "" -#: lib/branch_checkout.tcl:32 lib/browser.tcl:287 +#: lib/branch_checkout.tcl:32 lib/browser.tcl:287 lib/tools_dlg.tcl:328 msgid "Revision" msgstr "" -#: lib/branch_checkout.tcl:36 lib/branch_create.tcl:69 lib/option.tcl:244 +#: lib/branch_checkout.tcl:36 lib/branch_create.tcl:69 lib/option.tcl:280 msgid "Options" msgstr "" @@ -575,7 +670,7 @@ msgstr "" msgid "Create New Branch" msgstr "" -#: lib/branch_create.tcl:31 lib/choose_repository.tcl:371 +#: lib/branch_create.tcl:31 lib/choose_repository.tcl:377 msgid "Create" msgstr "" @@ -583,7 +678,7 @@ msgstr "" msgid "Branch Name" msgstr "" -#: lib/branch_create.tcl:43 +#: lib/branch_create.tcl:43 lib/remote_add.tcl:39 lib/tools_dlg.tcl:50 msgid "Name:" msgstr "" @@ -723,9 +818,9 @@ msgstr "" msgid "Browse Branch Files" msgstr "" -#: lib/browser.tcl:278 lib/choose_repository.tcl:387 -#: lib/choose_repository.tcl:472 lib/choose_repository.tcl:482 -#: lib/choose_repository.tcl:985 +#: lib/browser.tcl:278 lib/choose_repository.tcl:394 +#: lib/choose_repository.tcl:480 lib/choose_repository.tcl:491 +#: lib/choose_repository.tcl:995 msgid "Browse" msgstr "" @@ -740,6 +835,7 @@ msgid "fatal: Cannot resolve %s" msgstr "" #: lib/checkout_op.tcl:145 lib/console.tcl:81 lib/database.tcl:31 +#: lib/sshkey.tcl:53 msgid "Close" msgstr "" @@ -836,7 +932,7 @@ msgstr "" msgid "Reset '%s'?" msgstr "" -#: lib/checkout_op.tcl:532 lib/merge.tcl:163 +#: lib/checkout_op.tcl:532 lib/merge.tcl:164 lib/tools_dlg.tcl:343 msgid "Visualize" msgstr "" @@ -877,221 +973,225 @@ msgstr "" msgid "Git Gui" msgstr "" -#: lib/choose_repository.tcl:81 lib/choose_repository.tcl:376 +#: lib/choose_repository.tcl:87 lib/choose_repository.tcl:382 msgid "Create New Repository" msgstr "" -#: lib/choose_repository.tcl:87 +#: lib/choose_repository.tcl:93 msgid "New..." msgstr "" -#: lib/choose_repository.tcl:94 lib/choose_repository.tcl:458 +#: lib/choose_repository.tcl:100 lib/choose_repository.tcl:465 msgid "Clone Existing Repository" msgstr "" -#: lib/choose_repository.tcl:100 +#: lib/choose_repository.tcl:106 msgid "Clone..." msgstr "" -#: lib/choose_repository.tcl:107 lib/choose_repository.tcl:974 +#: lib/choose_repository.tcl:113 lib/choose_repository.tcl:983 msgid "Open Existing Repository" msgstr "" -#: lib/choose_repository.tcl:113 +#: lib/choose_repository.tcl:119 msgid "Open..." msgstr "" -#: lib/choose_repository.tcl:126 +#: lib/choose_repository.tcl:132 msgid "Recent Repositories" msgstr "" -#: lib/choose_repository.tcl:132 +#: lib/choose_repository.tcl:138 msgid "Open Recent Repository:" msgstr "" -#: lib/choose_repository.tcl:296 lib/choose_repository.tcl:303 -#: lib/choose_repository.tcl:310 +#: lib/choose_repository.tcl:302 lib/choose_repository.tcl:309 +#: lib/choose_repository.tcl:316 #, tcl-format msgid "Failed to create repository %s:" msgstr "" -#: lib/choose_repository.tcl:381 lib/choose_repository.tcl:476 +#: lib/choose_repository.tcl:387 msgid "Directory:" msgstr "" -#: lib/choose_repository.tcl:410 lib/choose_repository.tcl:535 -#: lib/choose_repository.tcl:1007 +#: lib/choose_repository.tcl:417 lib/choose_repository.tcl:544 +#: lib/choose_repository.tcl:1017 msgid "Git Repository" msgstr "" -#: lib/choose_repository.tcl:435 +#: lib/choose_repository.tcl:442 #, tcl-format msgid "Directory %s already exists." msgstr "" -#: lib/choose_repository.tcl:439 +#: lib/choose_repository.tcl:446 #, tcl-format msgid "File %s already exists." msgstr "" -#: lib/choose_repository.tcl:453 +#: lib/choose_repository.tcl:460 msgid "Clone" msgstr "" -#: lib/choose_repository.tcl:466 -msgid "URL:" +#: lib/choose_repository.tcl:473 +msgid "Source Location:" msgstr "" -#: lib/choose_repository.tcl:487 +#: lib/choose_repository.tcl:484 +msgid "Target Directory:" +msgstr "" + +#: lib/choose_repository.tcl:496 msgid "Clone Type:" msgstr "" -#: lib/choose_repository.tcl:493 +#: lib/choose_repository.tcl:502 msgid "Standard (Fast, Semi-Redundant, Hardlinks)" msgstr "" -#: lib/choose_repository.tcl:499 +#: lib/choose_repository.tcl:508 msgid "Full Copy (Slower, Redundant Backup)" msgstr "" -#: lib/choose_repository.tcl:505 +#: lib/choose_repository.tcl:514 msgid "Shared (Fastest, Not Recommended, No Backup)" msgstr "" -#: lib/choose_repository.tcl:541 lib/choose_repository.tcl:588 -#: lib/choose_repository.tcl:734 lib/choose_repository.tcl:804 -#: lib/choose_repository.tcl:1013 lib/choose_repository.tcl:1021 +#: lib/choose_repository.tcl:550 lib/choose_repository.tcl:597 +#: lib/choose_repository.tcl:743 lib/choose_repository.tcl:813 +#: lib/choose_repository.tcl:1023 lib/choose_repository.tcl:1031 #, tcl-format msgid "Not a Git repository: %s" msgstr "" -#: lib/choose_repository.tcl:577 +#: lib/choose_repository.tcl:586 msgid "Standard only available for local repository." msgstr "" -#: lib/choose_repository.tcl:581 +#: lib/choose_repository.tcl:590 msgid "Shared only available for local repository." msgstr "" -#: lib/choose_repository.tcl:602 +#: lib/choose_repository.tcl:611 #, tcl-format msgid "Location %s already exists." msgstr "" -#: lib/choose_repository.tcl:613 +#: lib/choose_repository.tcl:622 msgid "Failed to configure origin" msgstr "" -#: lib/choose_repository.tcl:625 +#: lib/choose_repository.tcl:634 msgid "Counting objects" msgstr "" -#: lib/choose_repository.tcl:626 +#: lib/choose_repository.tcl:635 msgid "buckets" msgstr "" -#: lib/choose_repository.tcl:650 +#: lib/choose_repository.tcl:659 #, tcl-format msgid "Unable to copy objects/info/alternates: %s" msgstr "" -#: lib/choose_repository.tcl:686 +#: lib/choose_repository.tcl:695 #, tcl-format msgid "Nothing to clone from %s." msgstr "" -#: lib/choose_repository.tcl:688 lib/choose_repository.tcl:902 -#: lib/choose_repository.tcl:914 +#: lib/choose_repository.tcl:697 lib/choose_repository.tcl:911 +#: lib/choose_repository.tcl:923 msgid "The 'master' branch has not been initialized." msgstr "" -#: lib/choose_repository.tcl:701 +#: lib/choose_repository.tcl:710 msgid "Hardlinks are unavailable. Falling back to copying." msgstr "" -#: lib/choose_repository.tcl:713 +#: lib/choose_repository.tcl:722 #, tcl-format msgid "Cloning from %s" msgstr "" -#: lib/choose_repository.tcl:744 +#: lib/choose_repository.tcl:753 msgid "Copying objects" msgstr "" -#: lib/choose_repository.tcl:745 +#: lib/choose_repository.tcl:754 msgid "KiB" msgstr "" -#: lib/choose_repository.tcl:769 +#: lib/choose_repository.tcl:778 #, tcl-format msgid "Unable to copy object: %s" msgstr "" -#: lib/choose_repository.tcl:779 +#: lib/choose_repository.tcl:788 msgid "Linking objects" msgstr "" -#: lib/choose_repository.tcl:780 +#: lib/choose_repository.tcl:789 msgid "objects" msgstr "" -#: lib/choose_repository.tcl:788 +#: lib/choose_repository.tcl:797 #, tcl-format msgid "Unable to hardlink object: %s" msgstr "" -#: lib/choose_repository.tcl:843 +#: lib/choose_repository.tcl:852 msgid "Cannot fetch branches and objects. See console output for details." msgstr "" -#: lib/choose_repository.tcl:854 +#: lib/choose_repository.tcl:863 msgid "Cannot fetch tags. See console output for details." msgstr "" -#: lib/choose_repository.tcl:878 +#: lib/choose_repository.tcl:887 msgid "Cannot determine HEAD. See console output for details." msgstr "" -#: lib/choose_repository.tcl:887 +#: lib/choose_repository.tcl:896 #, tcl-format msgid "Unable to cleanup %s" msgstr "" -#: lib/choose_repository.tcl:893 +#: lib/choose_repository.tcl:902 msgid "Clone failed." msgstr "" -#: lib/choose_repository.tcl:900 +#: lib/choose_repository.tcl:909 msgid "No default branch obtained." msgstr "" -#: lib/choose_repository.tcl:911 +#: lib/choose_repository.tcl:920 #, tcl-format msgid "Cannot resolve %s as a commit." msgstr "" -#: lib/choose_repository.tcl:923 +#: lib/choose_repository.tcl:932 msgid "Creating working directory" msgstr "" -#: lib/choose_repository.tcl:924 lib/index.tcl:65 lib/index.tcl:127 -#: lib/index.tcl:193 +#: lib/choose_repository.tcl:933 lib/index.tcl:65 lib/index.tcl:128 +#: lib/index.tcl:196 msgid "files" msgstr "" -#: lib/choose_repository.tcl:953 +#: lib/choose_repository.tcl:962 msgid "Initial file checkout failed." msgstr "" -#: lib/choose_repository.tcl:969 +#: lib/choose_repository.tcl:978 msgid "Open" msgstr "" -#: lib/choose_repository.tcl:979 +#: lib/choose_repository.tcl:988 msgid "Repository:" msgstr "" -#: lib/choose_repository.tcl:1027 +#: lib/choose_repository.tcl:1037 #, tcl-format msgid "Failed to open repository %s:" msgstr "" @@ -1176,7 +1276,7 @@ msgid "" "The rescan will be automatically started now.\n" msgstr "" -#: lib/commit.tcl:154 +#: lib/commit.tcl:156 #, tcl-format msgid "" "Unmerged files cannot be committed.\n" @@ -1185,7 +1285,7 @@ msgid "" "before committing.\n" msgstr "" -#: lib/commit.tcl:162 +#: lib/commit.tcl:164 #, tcl-format msgid "" "Unknown file state %s detected.\n" @@ -1193,14 +1293,14 @@ msgid "" "File %s cannot be committed by this program.\n" msgstr "" -#: lib/commit.tcl:170 +#: lib/commit.tcl:172 msgid "" "No changes to commit.\n" "\n" "You must stage at least 1 file before you can commit.\n" msgstr "" -#: lib/commit.tcl:183 +#: lib/commit.tcl:187 msgid "" "Please supply a commit message.\n" "\n" @@ -1211,45 +1311,45 @@ msgid "" "- Remaining lines: Describe why this change is good.\n" msgstr "" -#: lib/commit.tcl:207 +#: lib/commit.tcl:211 #, tcl-format msgid "warning: Tcl does not support encoding '%s'." msgstr "" -#: lib/commit.tcl:221 +#: lib/commit.tcl:227 msgid "Calling pre-commit hook..." msgstr "" -#: lib/commit.tcl:236 +#: lib/commit.tcl:242 msgid "Commit declined by pre-commit hook." msgstr "" -#: lib/commit.tcl:259 +#: lib/commit.tcl:265 msgid "Calling commit-msg hook..." msgstr "" -#: lib/commit.tcl:274 +#: lib/commit.tcl:280 msgid "Commit declined by commit-msg hook." msgstr "" -#: lib/commit.tcl:287 +#: lib/commit.tcl:293 msgid "Committing changes..." msgstr "" -#: lib/commit.tcl:303 +#: lib/commit.tcl:309 msgid "write-tree failed:" msgstr "" -#: lib/commit.tcl:304 lib/commit.tcl:348 lib/commit.tcl:368 +#: lib/commit.tcl:310 lib/commit.tcl:354 lib/commit.tcl:374 msgid "Commit failed." msgstr "" -#: lib/commit.tcl:321 +#: lib/commit.tcl:327 #, tcl-format msgid "Commit %s appears to be corrupt" msgstr "" -#: lib/commit.tcl:326 +#: lib/commit.tcl:332 msgid "" "No changes to commit.\n" "\n" @@ -1258,19 +1358,19 @@ msgid "" "A rescan will be automatically started now.\n" msgstr "" -#: lib/commit.tcl:333 +#: lib/commit.tcl:339 msgid "No changes to commit." msgstr "" -#: lib/commit.tcl:347 +#: lib/commit.tcl:353 msgid "commit-tree failed:" msgstr "" -#: lib/commit.tcl:367 +#: lib/commit.tcl:373 msgid "update-ref failed:" msgstr "" -#: lib/commit.tcl:454 +#: lib/commit.tcl:461 #, tcl-format msgid "Created commit %s: %s" msgstr "" @@ -1339,7 +1439,7 @@ msgstr "" msgid "Invalid date from Git: %s" msgstr "" -#: lib/diff.tcl:44 +#: lib/diff.tcl:59 #, tcl-format msgid "" "No differences detected.\n" @@ -1353,48 +1453,92 @@ msgid "" "the same state." msgstr "" -#: lib/diff.tcl:83 +#: lib/diff.tcl:99 #, tcl-format msgid "Loading diff of %s..." msgstr "" -#: lib/diff.tcl:116 lib/diff.tcl:190 +#: lib/diff.tcl:120 +msgid "" +"LOCAL: deleted\n" +"REMOTE:\n" +msgstr "" + +#: lib/diff.tcl:125 +msgid "" +"REMOTE: deleted\n" +"LOCAL:\n" +msgstr "" + +#: lib/diff.tcl:132 +msgid "LOCAL:\n" +msgstr "" + +#: lib/diff.tcl:135 +msgid "REMOTE:\n" +msgstr "" + +#: lib/diff.tcl:197 lib/diff.tcl:296 #, tcl-format msgid "Unable to display %s" msgstr "" -#: lib/diff.tcl:117 +#: lib/diff.tcl:198 msgid "Error loading file:" msgstr "" -#: lib/diff.tcl:124 +#: lib/diff.tcl:205 msgid "Git Repository (subproject)" msgstr "" -#: lib/diff.tcl:136 +#: lib/diff.tcl:217 msgid "* Binary file (not showing content)." msgstr "" -#: lib/diff.tcl:191 -msgid "Error loading diff:" +#: lib/diff.tcl:222 +#, tcl-format +msgid "" +"* Untracked file is %d bytes.\n" +"* Showing only first %d bytes.\n" msgstr "" -#: lib/diff.tcl:313 +#: lib/diff.tcl:228 +#, tcl-format +msgid "" +"\n" +"* Untracked file clipped here by %s.\n" +"* To see the entire file, use an external editor.\n" +msgstr "" + +#: lib/diff.tcl:436 msgid "Failed to unstage selected hunk." msgstr "" -#: lib/diff.tcl:320 +#: lib/diff.tcl:443 msgid "Failed to stage selected hunk." msgstr "" -#: lib/diff.tcl:386 +#: lib/diff.tcl:509 msgid "Failed to unstage selected line." msgstr "" -#: lib/diff.tcl:394 +#: lib/diff.tcl:517 msgid "Failed to stage selected line." msgstr "" +#: lib/encoding.tcl:443 +msgid "Default" +msgstr "" + +#: lib/encoding.tcl:448 +#, tcl-format +msgid "System (%s)" +msgstr "" + +#: lib/encoding.tcl:459 lib/encoding.tcl:465 +msgid "Other" +msgstr "" + #: lib/error.tcl:20 lib/error.tcl:114 msgid "error" msgstr "" @@ -1429,38 +1573,47 @@ msgstr "" msgid "Unlock Index" msgstr "" -#: lib/index.tcl:282 +#: lib/index.tcl:287 #, tcl-format msgid "Unstaging %s from commit" msgstr "" -#: lib/index.tcl:313 +#: lib/index.tcl:326 msgid "Ready to commit." msgstr "" -#: lib/index.tcl:326 +#: lib/index.tcl:339 #, tcl-format msgid "Adding %s" msgstr "" -#: lib/index.tcl:381 +#: lib/index.tcl:396 #, tcl-format msgid "Revert changes in file %s?" msgstr "" -#: lib/index.tcl:383 +#: lib/index.tcl:398 #, tcl-format msgid "Revert changes in these %i files?" msgstr "" -#: lib/index.tcl:391 +#: lib/index.tcl:406 msgid "Any unstaged changes will be permanently lost by the revert." msgstr "" -#: lib/index.tcl:394 +#: lib/index.tcl:409 msgid "Do Nothing" msgstr "" +#: lib/index.tcl:427 +msgid "Reverting selected files" +msgstr "" + +#: lib/index.tcl:431 +#, tcl-format +msgid "Reverting %s" +msgstr "" + #: lib/merge.tcl:13 msgid "" "Cannot merge while amending.\n" @@ -1478,7 +1631,7 @@ msgid "" "The rescan will be automatically started now.\n" msgstr "" -#: lib/merge.tcl:44 +#: lib/merge.tcl:45 #, tcl-format msgid "" "You are in the middle of a conflicted merge.\n" @@ -1489,7 +1642,7 @@ msgid "" "merge. Only then can you begin another merge.\n" msgstr "" -#: lib/merge.tcl:54 +#: lib/merge.tcl:55 #, tcl-format msgid "" "You are in the middle of a change.\n" @@ -1500,41 +1653,41 @@ msgid "" "will help you abort a failed merge, should the need arise.\n" msgstr "" -#: lib/merge.tcl:106 +#: lib/merge.tcl:107 #, tcl-format msgid "%s of %s" msgstr "" -#: lib/merge.tcl:119 +#: lib/merge.tcl:120 #, tcl-format msgid "Merging %s and %s..." msgstr "" -#: lib/merge.tcl:130 +#: lib/merge.tcl:131 msgid "Merge completed successfully." msgstr "" -#: lib/merge.tcl:132 +#: lib/merge.tcl:133 msgid "Merge failed. Conflict resolution is required." msgstr "" -#: lib/merge.tcl:157 +#: lib/merge.tcl:158 #, tcl-format msgid "Merge Into %s" msgstr "" -#: lib/merge.tcl:176 +#: lib/merge.tcl:177 msgid "Revision To Merge" msgstr "" -#: lib/merge.tcl:211 +#: lib/merge.tcl:212 msgid "" "Cannot abort while amending.\n" "\n" "You must finish amending this commit.\n" msgstr "" -#: lib/merge.tcl:221 +#: lib/merge.tcl:222 msgid "" "Abort merge?\n" "\n" @@ -1543,7 +1696,7 @@ msgid "" "Continue with aborting the current merge?" msgstr "" -#: lib/merge.tcl:227 +#: lib/merge.tcl:228 msgid "" "Reset changes?\n" "\n" @@ -1552,130 +1705,312 @@ msgid "" "Continue with resetting the current changes?" msgstr "" -#: lib/merge.tcl:238 +#: lib/merge.tcl:239 msgid "Aborting" msgstr "" -#: lib/merge.tcl:238 +#: lib/merge.tcl:239 msgid "files reset" msgstr "" -#: lib/merge.tcl:266 +#: lib/merge.tcl:267 msgid "Abort failed." msgstr "" -#: lib/merge.tcl:268 +#: lib/merge.tcl:269 msgid "Abort completed. Ready." msgstr "" -#: lib/option.tcl:95 +#: lib/mergetool.tcl:8 +msgid "Force resolution to the base version?" +msgstr "" + +#: lib/mergetool.tcl:9 +msgid "Force resolution to this branch?" +msgstr "" + +#: lib/mergetool.tcl:10 +msgid "Force resolution to the other branch?" +msgstr "" + +#: lib/mergetool.tcl:14 +#, tcl-format +msgid "" +"Note that the diff shows only conflicting changes.\n" +"\n" +"%s will be overwritten.\n" +"\n" +"This operation can be undone only by restarting the merge." +msgstr "" + +#: lib/mergetool.tcl:45 +#, tcl-format +msgid "File %s seems to have unresolved conflicts, still stage?" +msgstr "" + +#: lib/mergetool.tcl:60 +#, tcl-format +msgid "Adding resolution for %s" +msgstr "" + +#: lib/mergetool.tcl:141 +msgid "Cannot resolve deletion or link conflicts using a tool" +msgstr "" + +#: lib/mergetool.tcl:146 +msgid "Conflict file does not exist" +msgstr "" + +#: lib/mergetool.tcl:264 +#, tcl-format +msgid "Not a GUI merge tool: '%s'" +msgstr "" + +#: lib/mergetool.tcl:268 +#, tcl-format +msgid "Unsupported merge tool '%s'" +msgstr "" + +#: lib/mergetool.tcl:303 +msgid "Merge tool is already running, terminate it?" +msgstr "" + +#: lib/mergetool.tcl:323 +#, tcl-format +msgid "" +"Error retrieving versions:\n" +"%s" +msgstr "" + +#: lib/mergetool.tcl:343 +#, tcl-format +msgid "" +"Could not start the merge tool:\n" +"\n" +"%s" +msgstr "" + +#: lib/mergetool.tcl:347 +msgid "Running merge tool..." +msgstr "" + +#: lib/mergetool.tcl:375 lib/mergetool.tcl:383 +msgid "Merge tool failed." +msgstr "" + +#: lib/option.tcl:11 +#, tcl-format +msgid "Invalid global encoding '%s'" +msgstr "" + +#: lib/option.tcl:19 +#, tcl-format +msgid "Invalid repo encoding '%s'" +msgstr "" + +#: lib/option.tcl:117 msgid "Restore Defaults" msgstr "" -#: lib/option.tcl:99 +#: lib/option.tcl:121 msgid "Save" msgstr "" -#: lib/option.tcl:109 +#: lib/option.tcl:131 #, tcl-format msgid "%s Repository" msgstr "" -#: lib/option.tcl:110 +#: lib/option.tcl:132 msgid "Global (All Repositories)" msgstr "" -#: lib/option.tcl:116 +#: lib/option.tcl:138 msgid "User Name" msgstr "" -#: lib/option.tcl:117 +#: lib/option.tcl:139 msgid "Email Address" msgstr "" -#: lib/option.tcl:119 +#: lib/option.tcl:141 msgid "Summarize Merge Commits" msgstr "" -#: lib/option.tcl:120 +#: lib/option.tcl:142 msgid "Merge Verbosity" msgstr "" -#: lib/option.tcl:121 +#: lib/option.tcl:143 msgid "Show Diffstat After Merge" msgstr "" -#: lib/option.tcl:123 +#: lib/option.tcl:144 +msgid "Use Merge Tool" +msgstr "" + +#: lib/option.tcl:146 msgid "Trust File Modification Timestamps" msgstr "" -#: lib/option.tcl:124 +#: lib/option.tcl:147 msgid "Prune Tracking Branches During Fetch" msgstr "" -#: lib/option.tcl:125 +#: lib/option.tcl:148 msgid "Match Tracking Branches" msgstr "" -#: lib/option.tcl:126 +#: lib/option.tcl:149 msgid "Blame Copy Only On Changed Files" msgstr "" -#: lib/option.tcl:127 +#: lib/option.tcl:150 msgid "Minimum Letters To Blame Copy On" msgstr "" -#: lib/option.tcl:128 +#: lib/option.tcl:151 +msgid "Blame History Context Radius (days)" +msgstr "" + +#: lib/option.tcl:152 msgid "Number of Diff Context Lines" msgstr "" -#: lib/option.tcl:129 +#: lib/option.tcl:153 msgid "Commit Message Text Width" msgstr "" -#: lib/option.tcl:130 +#: lib/option.tcl:154 msgid "New Branch Name Template" msgstr "" -#: lib/option.tcl:194 +#: lib/option.tcl:155 +msgid "Default File Contents Encoding" +msgstr "" + +#: lib/option.tcl:203 +msgid "Change" +msgstr "" + +#: lib/option.tcl:230 msgid "Spelling Dictionary:" msgstr "" -#: lib/option.tcl:218 +#: lib/option.tcl:254 msgid "Change Font" msgstr "" -#: lib/option.tcl:222 +#: lib/option.tcl:258 #, tcl-format msgid "Choose %s" msgstr "" -#: lib/option.tcl:228 +#: lib/option.tcl:264 msgid "pt." msgstr "" -#: lib/option.tcl:242 +#: lib/option.tcl:278 msgid "Preferences" msgstr "" -#: lib/option.tcl:277 +#: lib/option.tcl:314 msgid "Failed to completely save options:" msgstr "" -#: lib/remote.tcl:165 +#: lib/remote.tcl:163 +msgid "Remove Remote" +msgstr "" + +#: lib/remote.tcl:168 msgid "Prune from" msgstr "" -#: lib/remote.tcl:170 +#: lib/remote.tcl:173 msgid "Fetch from" msgstr "" -#: lib/remote.tcl:213 +#: lib/remote.tcl:215 msgid "Push to" msgstr "" +#: lib/remote_add.tcl:19 +msgid "Add Remote" +msgstr "" + +#: lib/remote_add.tcl:24 +msgid "Add New Remote" +msgstr "" + +#: lib/remote_add.tcl:28 lib/tools_dlg.tcl:36 +msgid "Add" +msgstr "" + +#: lib/remote_add.tcl:37 +msgid "Remote Details" +msgstr "" + +#: lib/remote_add.tcl:50 +msgid "Location:" +msgstr "" + +#: lib/remote_add.tcl:62 +msgid "Further Action" +msgstr "" + +#: lib/remote_add.tcl:65 +msgid "Fetch Immediately" +msgstr "" + +#: lib/remote_add.tcl:71 +msgid "Initialize Remote Repository and Push" +msgstr "" + +#: lib/remote_add.tcl:77 +msgid "Do Nothing Else Now" +msgstr "" + +#: lib/remote_add.tcl:101 +msgid "Please supply a remote name." +msgstr "" + +#: lib/remote_add.tcl:114 +#, tcl-format +msgid "'%s' is not an acceptable remote name." +msgstr "" + +#: lib/remote_add.tcl:125 +#, tcl-format +msgid "Failed to add remote '%s' of location '%s'." +msgstr "" + +#: lib/remote_add.tcl:133 lib/transport.tcl:6 +#, tcl-format +msgid "fetch %s" +msgstr "" + +#: lib/remote_add.tcl:134 +#, tcl-format +msgid "Fetching the %s" +msgstr "" + +#: lib/remote_add.tcl:157 +#, tcl-format +msgid "Do not know how to initialize repository at location '%s'." +msgstr "" + +#: lib/remote_add.tcl:163 lib/transport.tcl:25 lib/transport.tcl:71 +#, tcl-format +msgid "push %s" +msgstr "" + +#: lib/remote_add.tcl:164 +#, tcl-format +msgid "Setting up the %s (at %s)" +msgstr "" + #: lib/remote_branch_delete.tcl:29 lib/remote_branch_delete.tcl:34 -msgid "Delete Remote Branch" +msgid "Delete Branch Remotely" msgstr "" #: lib/remote_branch_delete.tcl:47 @@ -1687,7 +2022,7 @@ msgid "Remote:" msgstr "" #: lib/remote_branch_delete.tcl:66 lib/transport.tcl:138 -msgid "Arbitrary URL:" +msgid "Arbitrary Location:" msgstr "" #: lib/remote_branch_delete.tcl:84 @@ -1750,6 +2085,22 @@ msgstr "" msgid "Scanning %s..." msgstr "" +#: lib/search.tcl:21 +msgid "Find:" +msgstr "" + +#: lib/search.tcl:23 +msgid "Next" +msgstr "" + +#: lib/search.tcl:24 +msgid "Prev" +msgstr "" + +#: lib/search.tcl:25 +msgid "Case-Sensitive" +msgstr "" + #: lib/shortcut.tcl:20 lib/shortcut.tcl:61 msgid "Cannot write shortcut:" msgstr "" @@ -1787,22 +2138,182 @@ msgstr "" msgid "No Suggestions" msgstr "" -#: lib/spellcheck.tcl:387 +#: lib/spellcheck.tcl:388 msgid "Unexpected EOF from spell checker" msgstr "" -#: lib/spellcheck.tcl:391 +#: lib/spellcheck.tcl:392 msgid "Spell Checker Failed" msgstr "" +#: lib/sshkey.tcl:31 +msgid "No keys found." +msgstr "" + +#: lib/sshkey.tcl:34 +#, tcl-format +msgid "Found a public key in: %s" +msgstr "" + +#: lib/sshkey.tcl:40 +msgid "Generate Key" +msgstr "" + +#: lib/sshkey.tcl:56 +msgid "Copy To Clipboard" +msgstr "" + +#: lib/sshkey.tcl:70 +msgid "Your OpenSSH Public Key" +msgstr "" + +#: lib/sshkey.tcl:78 +msgid "Generating..." +msgstr "" + +#: lib/sshkey.tcl:84 +#, tcl-format +msgid "" +"Could not start ssh-keygen:\n" +"\n" +"%s" +msgstr "" + +#: lib/sshkey.tcl:111 +msgid "Generation failed." +msgstr "" + +#: lib/sshkey.tcl:118 +msgid "Generation succeded, but no keys found." +msgstr "" + +#: lib/sshkey.tcl:121 +#, tcl-format +msgid "Your key is in: %s" +msgstr "" + #: lib/status_bar.tcl:83 #, tcl-format msgid "%s ... %*i of %*i %s (%3i%%)" msgstr "" -#: lib/transport.tcl:6 +#: lib/tools.tcl:75 #, tcl-format -msgid "fetch %s" +msgid "Running %s requires a selected file." +msgstr "" + +#: lib/tools.tcl:90 +#, tcl-format +msgid "Are you sure you want to run %s?" +msgstr "" + +#: lib/tools.tcl:110 +#, tcl-format +msgid "Tool: %s" +msgstr "" + +#: lib/tools.tcl:111 +#, tcl-format +msgid "Running: %s" +msgstr "" + +#: lib/tools.tcl:149 +#, tcl-format +msgid "Tool completed succesfully: %s" +msgstr "" + +#: lib/tools.tcl:151 +#, tcl-format +msgid "Tool failed: %s" +msgstr "" + +#: lib/tools_dlg.tcl:22 +msgid "Add Tool" +msgstr "" + +#: lib/tools_dlg.tcl:28 +msgid "Add New Tool Command" +msgstr "" + +#: lib/tools_dlg.tcl:33 +msgid "Add globally" +msgstr "" + +#: lib/tools_dlg.tcl:45 +msgid "Tool Details" +msgstr "" + +#: lib/tools_dlg.tcl:48 +msgid "Use '/' separators to create a submenu tree:" +msgstr "" + +#: lib/tools_dlg.tcl:61 +msgid "Command:" +msgstr "" + +#: lib/tools_dlg.tcl:74 +msgid "Show a dialog before running" +msgstr "" + +#: lib/tools_dlg.tcl:80 +msgid "Ask the user to select a revision (sets $REVISION)" +msgstr "" + +#: lib/tools_dlg.tcl:85 +msgid "Ask the user for additional arguments (sets $ARGS)" +msgstr "" + +#: lib/tools_dlg.tcl:92 +msgid "Don't show the command output window" +msgstr "" + +#: lib/tools_dlg.tcl:97 +msgid "Run only if a diff is selected ($FILENAME not empty)" +msgstr "" + +#: lib/tools_dlg.tcl:121 +msgid "Please supply a name for the tool." +msgstr "" + +#: lib/tools_dlg.tcl:129 +#, tcl-format +msgid "Tool '%s' already exists." +msgstr "" + +#: lib/tools_dlg.tcl:151 +#, tcl-format +msgid "" +"Could not add tool:\n" +"%s" +msgstr "" + +#: lib/tools_dlg.tcl:190 +msgid "Remove Tool" +msgstr "" + +#: lib/tools_dlg.tcl:196 +msgid "Remove Tool Commands" +msgstr "" + +#: lib/tools_dlg.tcl:200 +msgid "Remove" +msgstr "" + +#: lib/tools_dlg.tcl:236 +msgid "(Blue denotes repository-local tools)" +msgstr "" + +#: lib/tools_dlg.tcl:297 +#, tcl-format +msgid "Run Command: %s" +msgstr "" + +#: lib/tools_dlg.tcl:311 +msgid "Arguments" +msgstr "" + +#: lib/tools_dlg.tcl:348 +msgid "OK" msgstr "" #: lib/transport.tcl:7 @@ -1820,11 +2331,6 @@ msgstr "" msgid "Pruning tracking branches deleted from %s" msgstr "" -#: lib/transport.tcl:25 lib/transport.tcl:71 -#, tcl-format -msgid "push %s" -msgstr "" - #: lib/transport.tcl:26 #, tcl-format msgid "Pushing changes to %s" From 941930732fc0bbffbd19e9fa09fe00bc1512a3a7 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 13 Nov 2008 21:52:52 +0300 Subject: [PATCH 138/138] git-gui: Fix the search bar destruction handler. Since delete_this is an ordinary function, it should not be passed to cb; otherwise it produces errors when blame windows are closed. Unfortunately, it is not noticeable when blame is shown in the master window, so I missed this bug. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce --- lib/search.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/search.tcl b/lib/search.tcl index 32c8656fc9..b371e9a30a 100644 --- a/lib/search.tcl +++ b/lib/search.tcl @@ -35,7 +35,7 @@ constructor new {i_w i_text args} { trace add variable searchstring write [cb _incrsearch_cb] - bind $w [cb delete_this] + bind $w [list delete_this $this] return $this }