[英]How to obtain which lines changed for each commited file with git
I know git diff can show the differences between two commits.我知道 git diff 可以显示两次提交之间的差异。 However, I don't know how to obtain which lines changed (example @@ -12,6 +12,11 @@) for each commited file.但是,我不知道如何获取每个提交的文件更改了哪些行(例如@@ -12,6 +12,11 @@)。 I already use a regex to obtain the numbers, but I would like to have them separated for each file.我已经使用正则表达式来获取数字,但我希望每个文件都将它们分开。
In other words, I would like something like this :换句话说,我想要这样的东西:
a/aten/src/ATen/cpu/vec256/vec256_int.h
@@ -12,6 +12,11 @@
@@ -95,25 +100,19 @@
@@ -190,25 +189,19 @@
@@ -380,25 +373,19 @@
diff --git a/test/test_torch.py b/test/test_torch.py
@@ -1388,6 +1388,14 @@
from this output below :从下面的这个输出:
diff --git a/aten/src/ATen/cpu/vec256/vec256_int.h b/aten/src/ATen/cpu/vec256/vec256_int.h
index 9d2581e18..5c1cf80d5 100644
--- a/aten/src/ATen/cpu/vec256/vec256_int.h
+++ b/aten/src/ATen/cpu/vec256/vec256_int.h
@@ -12,6 +12,11 @@ namespace {
struct Vec256i {
protected:
__m256i values;
+
+ static inline __m256i invert(const __m256i& v) {
+ const auto ones = _mm256_set1_epi64x(-1);
+ return _mm256_xor_si256(ones, v);
+ }
public:
Vec256i() {}
Vec256i(__m256i v) : values(v) {}
@@ -95,25 +100,19 @@ struct Vec256<int64_t> : public Vec256i {
return _mm256_cmpeq_epi64(values, other.values);
}
@@ -190,25 +189,19 @@ struct Vec256<int32_t> : public Vec256i {
return _mm256_cmpeq_epi32(values, other.values);
}
@@ -380,25 +373,19 @@ struct Vec256<int16_t> : public Vec256i {
return _mm256_cmpeq_epi16(values, other.values);
}
diff --git a/test/test_torch.py b/test/test_torch.py
index 0c30c1f1a..10f6085cf 100644
--- a/test/test_torch.py
+++ b/test/test_torch.py
@@ -1388,6 +1388,14 @@ class _TestTorchMixin(object):
def test_neg(self):
self._test_neg(self, lambda t: t)
+ def test_threshold(self):
+ for dtype in torch.testing.get_all_dtypes():
+ if dtype != torch.uint8 and dtype != torch.float16:
+ # 100 is wide enough to use AVX2 instructions for all types
+ x = torch.randn(100).sign().to(dtype=dtype)
+ y = torch.threshold(x, 0, 0)
+ self.assertTrue(y.le(0).any())
+
def test_reciprocal(self):
a = torch.randn(100, 89)
res_div = 1 / a
Note : I am using Python language.注意:我使用的是 Python 语言。
Not a complete answer, but git log -p will show the patch from each commit.不是一个完整的答案,但git log -p将显示每个提交的补丁。 From that it would be possible to make a script just showing the part you want, if git does not have a feature which does it for you.如果 git 没有为您执行此操作的功能,则可以制作一个仅显示您想要的部分的脚本。
Not knowing if something already exists, I developped something to achieve this.不知道某些东西是否已经存在,我开发了一些东西来实现这一目标。
First, I split the patchfile
string using 'diff --git'
as separators.首先,我分裂了patchfile
使用字符串'diff --git'
作为分隔符。 This will return a separate patchfile
for each file changed (all stored in split_patchfile
) :这将返回一个单独的patchfile
进行更改的每个文件(全部存储在split_patchfile
):
def splitPatchfile(patchfile):
split_patchfile = patchfile.split('diff --git')
return split_patchfile
Second, I parse every patchfile
to find the changed lines.其次,我解析每个patchfile
以找到更改的行。 This will create the 2Dimensional-ish list
that are saved in lines_numbers
.这将创建保存在lines_numbers
的 2Dimensional-ish list
。 Each line_number
will contain the changed lines of each patchfile.每个line_number
将包含每个line_number
的更改行。
def findChangedLinesPerFile(split_patchfile):
lines_numbers = []
for split_patch in split_patchfile:
lines_numbers.append(findChangedLines(split_patch))
return lines_numbers
def findChangedLines(split_patch):
regex = r"^@@ [-+](\d+)"
matches = re.finditer(regex, split_patch, re.MULTILINE)
line_numbers = []
for matchNum, match in enumerate(matches, start=1):
# print(int(match.group(1))) # debug which lines are modified
line_numbers.append(int(match.group(1)))
return line_numbers
Third, since the order of elements is important for further work, I clear empty elements to make correspond each patchfile
to its line_numbers
.第三,由于元素的顺序对于进一步的工作很重要,我清除了空元素以使每个patchfile
与其line_numbers
对应。 Empty elements appear because of patchfile.split('diff --git')
.由于patchfile.split('diff --git')
出现空元素。 It created 3 patchfile
because I had 2 'diff --git'
(the first patchfile
was empty).它创造了3 patchfile
,因为我有2 'diff --git'
(第一patchfile
是空的)。
def removeEmptyElements(split_patchfile, lines_numbers):
split_patchfile = list(filter(None, split_patchfile))
lines_numbers = list(filter(None, lines_numbers))
return split_patchfile, lines_numbers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.