【问题标题】:Mercurial log/diff for range of lines in a file文件中行范围的 Mercurial log/diff
【发布时间】:2012-06-18 22:35:07
【问题描述】:

我想要一个扩展程序或工具来帮助我浏览给定文件中一系列行的历史记录。假设我想查看特定函数的历史记录,当前位于 [start, end] 行。 hg annotate 让我开始:

AAA  772 06-Aug-02: void Graphics2DDXF::lineTo(double x, // the x coordinate
AAA  772 06-Aug-02:                            double y // the y cooordinate
AAA  772 06-Aug-02:                            )
AAA  772 06-Aug-02:     {
BBB 2034 30-Aug-04:     LOG;
BBB 6989 05-Dec-11: 
BBB 4638 31-Oct-07:     transform_->transform(&x,&y);
AAA  772 06-Aug-02: 
BBB 7011 06-Jan-12:     AGcRoot<Line> line = gcnew Line;
BBB 6989 05-Dec-11: 
BBB 6989 05-Dec-11:     Point3d startPoint(lastPenLocation_->x(), lastPenLocation_->y(), 0.0);
BBB 6989 05-Dec-11:     Point3d endPoint(x, y, 0.0);
BBB 6989 05-Dec-11:     line->StartPoint = startPoint;
BBB 6989 05-Dec-11:     line->EndPoint = endPoint;
BBB 6989 05-Dec-11: 
BBB 4638 31-Oct-07:     lastPenLocation_ = APoint2D::New(x,y,AToleranceID::None);
BBB 7011 06-Jan-12: 
BBB 7011 06-Jan-12:     setAndAddEntity(line);
AAA  772 06-Aug-02:     }

此方法的最后一次更改是更改集 7011。我可以使用 'hg diff -c7011' 进行检查。

困难的部分是在那之前发生的事情。从 7011-1 的注释输出开始:

% hg annotate -r7010 file.cpp
...
AAA  772 06-Aug-02: void Graphics2DDXF::lineTo(double x, // the x coordinate
AAA  772 06-Aug-02:                            double y // the y cooordinate
AAA  772 06-Aug-02:                            )
AAA  772 06-Aug-02:     {
BBB 2034 30-Aug-04:     LOG;
BBB 6989 05-Dec-11: 
BBB 4638 31-Oct-07:     transform_->transform(&x,&y);
AAA  772 06-Aug-02: 
BBB 6989 05-Dec-11:     Line^ line = gcnew Line;
AAA  772 06-Aug-02:     addEntityToModelSpace(line);
AAA  772 06-Aug-02: 
AAA  772 06-Aug-02:     ensureLayerAvailable();
BBB 6989 05-Dec-11:     line->LayerId = s_currentLayerObjectId;
BBB 6989 05-Dec-11: 
BBB 6989 05-Dec-11:     Point3d startPoint(lastPenLocation_->x(), lastPenLocation_->y(), 0.0);
BBB 6989 05-Dec-11:     Point3d endPoint(x, y, 0.0);
BBB 6989 05-Dec-11:     line->StartPoint = startPoint;
BBB 6989 05-Dec-11:     line->EndPoint = endPoint;
BBB 6989 05-Dec-11: 
BBB 6989 05-Dec-11:     line->LinetypeId = currentLinetypeId();
BBB 6989 05-Dec-11:     line->ColorIndex = dwgColor(getColor());
BBB 4638 31-Oct-07:     lastPenLocation_ = APoint2D::New(x,y,AToleranceID::None);
AAA  772 06-Aug-02:     }

所以现在我可以看到影响这一行范围的先前变更集是 6989。等等。

如果有一个可视化工具来做这件事会很棒,但我会很高兴只给我一系列变更集:7011、6989 等。

过滤行号范围的注释输出并找到最大变更集编号并不难。困难的是调整行的范围以考虑添加和删除的行,尤其是当“差异”声称更改跨越了行范围的最小值或最大值时。至少 CVS diff 输出很难做到这一点,我还没有尝试过 hg diff 的输出。

如果我梦寐以求的工具/扩展不存在,是否至少有任何工具可以计算修改后的行号?

谢谢,

【问题讨论】:

  • 为了分析单个文件的历史,我使用了 TortoiseHg。我从特定版本的文件的注释版本开始,然后切换到文件历史记录并沿着 DAG 向下移动。不像你想要的那样自动化,但可以。

标签: mercurial diff history


【解决方案1】:

它不是为它而构建的,但您可以通过使用 hg grep 搜索 . 来近似它,这意味着 anything 在正则表达式中。这会让你得到这样的输出:

ry4an@four:~/projects/unblog$ hg grep --all --user --date . config.yaml 
config.yaml:79:-:ry4an-hg:Mon Apr 23 22:45:24 2012 -0400:TAGLINE: I think in a monospaced font.
config.yaml:79:+:ry4an-hg:Mon Apr 23 22:45:24 2012 -0400:TAGLINE: A blog about software, projects, and other little things I build.
config.yaml:52:-:ry4an-hg:Sat Apr 30 11:25:08 2011 -0500:AUTHOR: Ry4an Brase
config.yaml:52:-:ry4an-hg:Sat Apr 30 11:25:08 2011 -0500:#DISQUS: rafaelmartins-en
config.yaml:52:-:ry4an-hg:Sat Apr 30 11:25:08 2011 -0500:TIMEZONE: UTC
config.yaml:52:+:ry4an-hg:Sat Apr 30 11:25:08 2011 -0500:#POSTS_PER_PAGE: 10
config.yaml:52:+:ry4an-hg:Sat Apr 30 11:25:08 2011 -0500:AUTHOR: Ry4an Brase
config.yaml:52:+:ry4an-hg:Sat Apr 30 11:25:08 2011 -0500:#DISQUS: your-disqus-id
config.yaml:52:+:ry4an-hg:Sat Apr 30 11:25:08 2011 -0500:TIMEZONE: UTC
config.yaml:0:+:ry4an-hg:Sat Jan 22 22:51:22 2011 -0600:TITLE: Ry4an's Unblog
config.yaml:0:+:ry4an-hg:Sat Jan 22 22:51:22 2011 -0600:TITLE_HTML: Ry4an's Unblog
config.yaml:0:+:ry4an-hg:Sat Jan 22 22:51:22 2011 -0600:TAGLINE: I think in a monospaced font.
config.yaml:0:+:ry4an-hg:Sat Jan 22 22:51:22 2011 -0600:AUTHOR: Ry4an Brase
config.yaml:0:+:ry4an-hg:Sat Jan 22 22:51:22 2011 -0600:#DISQUS: rafaelmartins-en
config.yaml:0:+:ry4an-hg:Sat Jan 22 22:51:22 2011 -0600:TIMEZONE: UTC

+ 表示添加了一行,- 表示已删除。 --all 选项表示显示所有匹配项,而不仅仅是每行最近的匹配项。

【讨论】:

  • hg grep 没有帮助。我不是在寻找包含正则表达式的更改。我想要任何行范围内发生的更改。
  • 对,但是通过使该正则表达式 .(所有内容)并传入 --all,您可以获得对该文件中每个版本的所有行的所有更改。它不完美,但它是你能得到的最好的。
猜你喜欢
  • 2011-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-07
  • 2021-08-10
相关资源
最近更新 更多