From: Neil Brown Date: Tue, 8 May 2012 08:54:11 +0000 (+1000) Subject: Encourage more context into conflict reports. X-Git-Tag: v0.9~30 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=f2aba8f729258265efea8636fc762ff9d09adf77;p=wiggle.git Encourage more context into conflict reports. Conflict reports currently don't contain much surrounding 'Extraneous' text. When the patch didn't really apply at all, this context is very useful. So encourage at least 3 lines of context from Extraneous or Unchanged texts. If it mostly comes from Unchanged text it isn't quite so useful, so reduce the requirement. Update self-tests to match. In most cases these are an improvement. In a couple of case we maybe get a bit more context than really necessary, but that is better than not enough. Signed-off-by: NeilBrown --- diff --git a/merge2.c b/merge2.c index 2bbb709..20b0305 100644 --- a/merge2.c +++ b/merge2.c @@ -121,6 +121,13 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf, * * A hunk header is never considered part of a conflict. It * thereby can serve as a separator between conflicts. + * + * We need to ensure there is adequate context for the conflict. + * So ensure there are at least 3 newlines in Extraneous or + * Unchanged on both sides of a Conflict - but don't go so far + * as including a hunk header. + * If there are 3, and they are all in 'Unchanged' sections, then + * that much context is not really needed - reduce it a bit. */ int i, j, k; int cnt = 0; @@ -143,6 +150,7 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf, * * Then search forward doing the same thing. */ + int newlines = 0; cnt++; m[i].in_conflict = 1; j = i; @@ -161,8 +169,19 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf, cnt--; break; } + if (m[j].type == Extraneous) { + for (k = m[j].bl; k > 0; k--) + if (ends_line(bf.list[m[j].b+k-1])) + newlines++; + } if (m[j].type == Unchanged || m[j].type == Changed) { + /* If we find enough newlines in this section, + * then we only really need 1, but would rather + * it wasn't the first one. 'firstk' allows us + * to track which newline we actually use + */ + int firstk = m[j].al; if (words) { m[j].hi = m[j].al; break; @@ -172,8 +191,15 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf, * is one, or might be at the start */ for (k = m[j].al; k > 0; k--) - if (ends_line(af.list[m[j].a+k-1])) - break; + if (ends_line(af.list[m[j].a+k-1])) { + if (firstk == m[j].al) + firstk = k; + newlines++; + if (newlines >= 3) { + k = firstk; + break; + } + } if (k > 0) m[j].hi = k; else if (is_cutpoint(m[j], af,bf,cf)) @@ -195,12 +221,18 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf, } /* now the forward search */ + newlines = 0; for (j = i+1; m[j].type != End; j++) { if (m[j].type == Extraneous && bf.list[m[j].b].start[0] == '\0') /* hunk header - not conflict any more */ break; m[j].in_conflict = 1; + if (m[j].type == Extraneous) { + for (k = 0; k < m[j].bl; k++) + if (ends_line(bf.list[m[j].b+k])) + newlines++; + } if (m[j].type == Unchanged || m[j].type == Changed) { m[j].hi = m[j].al; if (words) { @@ -214,9 +246,22 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf, if (is_cutpoint(m[j], af,bf,cf)) m[j].lo = 0; else { + /* If we find enough newlines in this section, + * then we only really need 1, but would rather + * it wasn't the first one. 'firstk' allows us + * to track which newline we actually use + */ + int firstk = 0; for (k = 0 ; k < m[j].al ; k++) - if (ends_line(af.list[m[j].a+k])) - break; + if (ends_line(af.list[m[j].a+k])) { + if (firstk == 0) + firstk = k; + newlines++; + if (newlines >= 3) { + k = firstk; + break; + } + } if (k < m[j].al) m[j].lo = k+1; else diff --git a/tests/linux/inode-justrej/lmerge b/tests/linux/inode-justrej/lmerge index 685b14e..08b0a9b 100644 --- a/tests/linux/inode-justrej/lmerge +++ b/tests/linux/inode-justrej/lmerge @@ -952,12 +952,14 @@ void remove_inode_hash(struct inode *inode) void generic_delete_inode(struct inode *inode) { struct super_operations *op = inode->i_sb->s_op; - <<<<<<< + hlist_del_init(&inode->i_hash); ||||||| + list_del_init(&inode->i_hash); ======= + >>>>>>> list_del_init(&inode->i_list); inode->i_state|=I_FREEING; diff --git a/tests/linux/md-loop/merge b/tests/linux/md-loop/merge index 682ed20..ebb59ea 100644 --- a/tests/linux/md-loop/merge +++ b/tests/linux/md-loop/merge @@ -3950,11 +3950,13 @@ MD_EXPORT_SYMBOL(md_update_sb); MD_EXPORT_SYMBOL(md_wakeup_thread); MD_EXPORT_SYMBOL(md_print_devices); MD_EXPORT_SYMBOL(find_rdev_nr); -MD_EXPORT_SYMBOL(md_interrupt_thread); <<<<<<< +MD_EXPORT_SYMBOL(md_interrupt_thread); MD_EXPORT_SYMBOL(mddev_map); ||||||| +MD_EXPORT_SYMBOL(md_interrupt_thread); EXPORT_SYMBOL(mddev_map); ======= +MD_EXPORT_SYMBOL(md_interrupt_thread); >>>>>>> MODULE_LICENSE("GPL"); diff --git a/tests/linux/md-resync/merge b/tests/linux/md-resync/merge index 7960304..09928a2 100644 --- a/tests/linux/md-resync/merge +++ b/tests/linux/md-resync/merge @@ -980,13 +980,13 @@ static int raid1_diskop(mddev_t *mddev, mdp_disk_t **d, int state) <<<<<<< if (conf->start_future > 0) { MD_BUG(); + err = -EBUSY; + break; + } ||||||| close_sync(conf); ======= >>>>>>> - err = -EBUSY; - break; - } sdisk = conf->mirrors + spare_disk; sdisk->operational = 0; sdisk->write_only = 0; @@ -1002,13 +1002,13 @@ static int raid1_diskop(mddev_t *mddev, mdp_disk_t **d, int state) <<<<<<< if (conf->start_future > 0) { MD_BUG(); + err = -EBUSY; + break; + } ||||||| close_sync(conf); ======= >>>>>>> - err = -EBUSY; - break; - } sdisk = conf->mirrors + spare_disk; fdisk = conf->mirrors + failed_disk; @@ -1306,12 +1306,14 @@ static int init_resync (conf_t *conf) *** 1144,16 **** 8 <<<<<<< raid1_conf_t *conf = data; + mddev_t *mddev = conf->mddev; ||||||| conf_t *conf = data; + mddev_t *mddev = conf->mddev; ======= sector_t max_sector, nr_sectors; ->>>>>>> int disk, partial; +>>>>>>> if (sector_nr == 0) if (init_resync(conf)) @@ -1497,19 +1499,6 @@ nomem: raid1_shrink_buffers(conf); return -ENOMEM; } -||||||| - if (!sector_nr) - if (init_resync(conf)) - return -ENOMEM; - /* -======= - if (sector_nr >= max_sector) { - close_sync(conf); - return 0; - } - - /* ->>>>>>> static void end_sync_read(struct buffer_head *bh, int uptodate) { @@ -1539,6 +1528,23 @@ static void end_sync_write(struct buffer_head *bh, int uptodate) raid1_free_buf(r1_bh); sync_request_done(sect, mddev_to_conf(mddev)); md_done_sync(mddev,size>>9, uptodate); +||||||| + if (!sector_nr) + if (init_resync(conf)) + return -ENOMEM; + /* + * If there is non-resync activity waiting for us then + * put in a delay to throttle resync. +======= + if (sector_nr >= max_sector) { + close_sync(conf); + return 0; + } + + /* + * If there is non-resync activity waiting for us then + * put in a delay to throttle resync. +>>>>>>> } } @@ -1761,11 +1767,13 @@ static int raid1_run (mddev_t *mddev) } <<<<<<< + if (!start_recovery && !(sb->state & (1 << MD_SB_CLEAN)) && (conf->working_disks > 1)) { const char * name = "raid1syncd"; conf->resync_thread = md_register_thread(raid1syncd, conf,name); ||||||| + if (!start_recovery && !(sb->state & (1 << MD_SB_CLEAN)) && (conf->working_disks > 1)) { const char * name = "raid1syncd"; diff --git a/tests/linux/raid5build/merge b/tests/linux/raid5build/merge index 77cfac8..0fe41cd 100644 --- a/tests/linux/raid5build/merge +++ b/tests/linux/raid5build/merge @@ -10,11 +10,13 @@ static void raid5_build_block (struct stripe_head *sh, int i) dev->vec.bv_len = STRIPE_SIZE; dev->vec.bv_offset = 0; - dev->req.bi_bdev = conf->disks[i].bdev; <<<<<<< + bh->b_dev = conf->disks[i].dev; ||||||| + bh->b_dev = conf->disks[i].dev; /* FIXME - later we will need bdev here */ ======= + dev->req.bi_bdev = conf->disks[i].bdev; dev->req.bi_sector = sh->sector; >>>>>>> dev->req.bi_private = sh; @@ -25,10 +27,12 @@ static void raid5_build_block (struct stripe_head *sh, int i) bh->b_size = sh->size; bh->b_list = BUF_LOCKED; return bh; +} ||||||| bh->b_size = sh->size; return bh; +} ======= dev->sector = compute_blocknr(sh, i); ->>>>>>> } +>>>>>>> diff --git a/tests/linux/rpc_tcp_nonagle/merge b/tests/linux/rpc_tcp_nonagle/merge index c66c37a..2f9aa46 100644 --- a/tests/linux/rpc_tcp_nonagle/merge +++ b/tests/linux/rpc_tcp_nonagle/merge @@ -1031,19 +1031,27 @@ svc_tcp_init(struct svc_sock *svsk) sk->write_space = svc_write_space; svsk->sk_reclen = 0; +<<<<<<< svsk->sk_tcplen = 0; -<<<<<<< /* initialise setting must have enough space to + * receive and respond to one request. + * svc_tcp_recvfrom will re-adjust if necessary ||||||| + svsk->sk_tcplen = 0; + /* initialise setting must have enough space to + * receive and respond to one request. + * svc_tcp_recvfrom will re-adjust if necessary ======= + svsk->sk_tcplen = 0; + tp->nonagle = 1; /* disable Nagle's algorithm */ /* initialise setting must have enough space to + * receive and respond to one request. + * svc_tcp_recvfrom will re-adjust if necessary >>>>>>> - * receive and respond to one request. - * svc_tcp_recvfrom will re-adjust if necessary */ svc_sock_setbufsize(svsk->sk_sock, 3 * svsk->sk_server->sv_bufsz, diff --git a/tests/simple/all-different/merge b/tests/simple/all-different/merge index ab83c87..28ee454 100644 --- a/tests/simple/all-different/merge +++ b/tests/simple/all-different/merge @@ -9,6 +9,7 @@ 8 9 0 +yes ||||||| a b @@ -20,6 +21,7 @@ g h i j +yes ======= A B @@ -31,5 +33,5 @@ G H I J ->>>>>>> yes +>>>>>>> diff --git a/tests/simple/conflict/merge b/tests/simple/conflict/merge index 4afaeff..8bbd487 100644 --- a/tests/simple/conflict/merge +++ b/tests/simple/conflict/merge @@ -1,10 +1,16 @@ +<<<<<<< this is a file with the word -<<<<<<< two which is +misspelt ||||||| +this is a file +with the word to which is +misspelt ======= +this is a file +with the word too which is ->>>>>>> misspelt +>>>>>>> diff --git a/tests/simple/conflictmixed/lmerge b/tests/simple/conflictmixed/lmerge index bb4d03c..6d7071e 100644 --- a/tests/simple/conflictmixed/lmerge +++ b/tests/simple/conflictmixed/lmerge @@ -1,10 +1,14 @@ +<<<<<<< this is a file with the word -<<<<<<< two which is ||||||| +this is a file +with the word to which is ======= +this is a file +with the word too which was >>>>>>> misspelt diff --git a/tests/simple/conflictmixed/merge b/tests/simple/conflictmixed/merge index bb4d03c..bb38d8a 100644 --- a/tests/simple/conflictmixed/merge +++ b/tests/simple/conflictmixed/merge @@ -1,10 +1,16 @@ +<<<<<<< this is a file with the word -<<<<<<< two which is +misspelt ||||||| +this is a file +with the word to which is +misspelt ======= +this is a file +with the word too which was ->>>>>>> misspelt +>>>>>>> diff --git a/tests/simple/multiple-add/lmerge b/tests/simple/multiple-add/lmerge index f2a4151..5827de2 100644 --- a/tests/simple/multiple-add/lmerge +++ b/tests/simple/multiple-add/lmerge @@ -4,12 +4,14 @@ the current version of -the <<<<<<< +the file. ||||||| +the file ======= +the file that has changed >>>>>>> diff --git a/tests/simple/multiple-add/merge b/tests/simple/multiple-add/merge index f2a4151..312609f 100644 --- a/tests/simple/multiple-add/merge +++ b/tests/simple/multiple-add/merge @@ -7,9 +7,11 @@ of the <<<<<<< file. + ||||||| file + ======= file that has changed ->>>>>>> +>>>>>>> diff --git a/tests/simple/show-wiggle-1/Wmerge b/tests/simple/show-wiggle-1/Wmerge index 2bb7d41..d5cba67 100644 --- a/tests/simple/show-wiggle-1/Wmerge +++ b/tests/simple/show-wiggle-1/Wmerge @@ -1,14 +1,20 @@ - <<<<<<< + This is one line of the file + ||||||| + This is 1 line of the file + ======= + This is 1 line of the document + &&&&&&& + This is one line of the document ->>>>>>> +>>>>>>> I think this is another line So is this