Skip to contentSkip to conversation

blame: can specify shas of commits to ignore on command line

PATCH In review Dylan Reid 4 participants 8 messages Jun 15, 2016 Documentation

lore
Share & tools
lore

Dylan Reid

author
#0 lore raw

PATCH 1/1 blame: can specify shas of commits to ignore on command line

Add the ability for git-blame to ignore changes that occur in certain commits. The new "-I <sha>" argument can be used to specify a commit that should be ignored. This is useful if you have a few commits that you know didn't cause a problem, for example you switched from "u8" to "uint8_t" and it messed up your history.

Allow multiple commits to be specified and store an array in the
scoreboard structure so it is accessible. Add should_ignore_commit function to check if a commit should be ignored. Call "should_ignore_commit" from blame_overlap and if the commit should be ignored then pass all the blame on to the parent of the ignored commit. This is done by calling "pass_whole_blame" which has been relocated to a above blame_overlap, but is unchanged.

---
 Documentation/blame-options.txt |    6 ++
 builtin/blame.c                 |  124 +++++++++++++++++++++++++++++----------
 t/t8003-blame.sh                |   42 +++++++++++++
 3 files changed, 141 insertions(+), 31 deletions(-)
Documentation/blame-options.txt +6 -0
index d820569..eb9c825 100644
@@ -52,6 +52,12 @@ of lines before or after the line given by <start>.
 --porcelain::
 	Show in a format designed for machine consumption.
 
+--ignore-commit <sha>::
+	Ignore the specified commit when assigning blame.  This is
+	useful if there are commits in the history that make non
+	functional changes to the lines you are interested in
+	finding blame for.
+
 --incremental::
 	Show the result incrementally in a format designed for
 	machine consumption.
builtin/blame.c +93 -31

196 lines not on this page · raw message

t/t8003-blame.sh +42 -0

46 lines not on this page · raw message

Signature · 1 line
1.7.1.6.gc7a9
#1 lore raw

Am 04.05.2010 04:21, schrieb Dylan Reid:

Quoted 5 lines

Add the ability for git-blame to ignore changes that occur in certain commits. The new "-I <sha>" argument can be used to specify a commit that should be ignored. This is useful if you have a few commits that you know didn't cause a problem, for example you switched from "u8" to "uint8_t" and it messed up your history.

Only the long option --ignore-commit works with your patch, -I doesn't.

Quoted 8 lines

Allow multiple commits to be specified and store an array in the
scoreboard structure so it is accessible. Add should_ignore_commit function to check if a commit should be ignored. Call "should_ignore_commit" from blame_overlap and if the commit should be ignored then pass all the blame on to the parent of the ignored commit. This is done by calling "pass_whole_blame" which has been relocated to a above blame_overlap, but is unchanged.

Quoted 6 lines
---
 Documentation/blame-options.txt |    6 ++
 builtin/blame.c                 |  124 +++++++++++++++++++++++++++++----------
 t/t8003-blame.sh                |   42 +++++++++++++
 3 files changed, 141 insertions(+), 31 deletions(-)

Oh, nice! And with tests and documentation! :)

Quoted 61 lines
Documentation/blame-options.txt +6 -0
index d820569..eb9c825 100644
@@ -52,6 +52,12 @@ of lines before or after the line given by <start>.
 --porcelain::
 	Show in a format designed for machine consumption.
 
+--ignore-commit <sha>::
+	Ignore the specified commit when assigning blame.  This is
+	useful if there are commits in the history that make non
+	functional changes to the lines you are interested in
+	finding blame for.
+
 --incremental::
 	Show the result incrementally in a format designed for
 	machine consumption.
builtin/blame.c +22 -0
index fc15863..e4bd095 100644
@@ -176,6 +176,14 @@ struct blame_entry {
 };
 
 /*
+ * List of any commits to ignore
+ */
+struct ignore_commits {
+	unsigned char (*ignore_shas)[20];
+	unsigned num_ignore_shas;
+};
+
+/*
  * The current state of the blame assignment.
  */
 struct scoreboard {
@@ -198,6 +206,9 @@ struct scoreboard {
 	/* look-up a line in the final buffer */
 	int num_lines;
 	int *lineno;
+
+	/* List of the shas of commits that should be ignored */
+	struct ignore_commits *ignored_commits;
 };
 
 static inline int same_suspect(struct origin *a, struct origin *b)
@@ -653,6 +664,44 @@ static void decref_split(struct blame_entry *split)
 }
 
 /*
+ * The blobs of origin and porigin exactly match, so everything
+ * origin is suspected for can be blamed on the parent.
+ */
+static void pass_whole_blame(struct scoreboard *sb,
+			     struct origin *origin, struct origin *porigin)
+{
+   struct blame_entry *e;
+
+   if (!porigin->file.ptr && origin->file.ptr) {
+      /* Steal its file */
+      porigin->file = origin->file;

builtin/blame.c static void decref_split(struct blame_entry *split) · line 687

Quoted 10 lines
builtin/blame.c +10 -0
+      origin->file.ptr = NULL;
+   }
+   for (e = sb->ent; e; e = e->next) {
+      if (!same_suspect(e->suspect, origin))
+	 continue;
+      origin_incref(porigin);
+      origin_decref(e->suspect);
+      e->suspect = porigin;
+   }
+}

This function was moved from below, but it seems to be indented with three spaces instead of tabs now. Adding a declaration without moving the function would avoid that and result in a smaller patch.

Quoted 76 lines
builtin/blame.c +26 -29
+
+/*
+ * Helper to determine if the given commit should be ignored
+ */
+static unsigned should_ignore_commit(const struct scoreboard *sb,
+				     struct commit *commit)
+{
+	unsigned i;
+	unsigned num_shas = sb->ignored_commits->num_ignore_shas;
+	for(i = 0; i < num_shas; i++)
+		if(!hashcmp(commit->object.sha1,
+			    sb->ignored_commits->ignore_shas[i]))
+			return 1;
+	return 0;
+}
+
+/*
  * Helper for blame_chunk().  blame_entry e is known to overlap with
  * the patch hunk; split it and pass blame to the parent.
  */
@@ -660,12 +709,15 @@ static void blame_overlap(struct scoreboard *sb, struct blame_entry *e,
 			  int tlno, int plno, int same,
 			  struct origin *parent)
 {
-	struct blame_entry split[3];
-
-	split_overlap(split, e, tlno, plno, same, parent);
-	if (split[1].suspect)
-		split_blame(sb, split, e);
-	decref_split(split);
+	if(should_ignore_commit(sb, e->suspect->commit))
+		pass_whole_blame(sb, e->suspect, parent);
+	else {
+		struct blame_entry split[3];
+		split_overlap(split, e, tlno, plno, same, parent);
+		if (split[1].suspect)
+			split_blame(sb, split, e);
+		decref_split(split);
+	}
 }
 
 /*
@@ -1105,29 +1157,6 @@ static int find_copy_in_parent(struct scoreboard *sb,
 }
 
 /*
- * The blobs of origin and porigin exactly match, so everything
- * origin is suspected for can be blamed on the parent.
- */
-static void pass_whole_blame(struct scoreboard *sb,
-			     struct origin *origin, struct origin *porigin)
-{
-	struct blame_entry *e;
-
-	if (!porigin->file.ptr && origin->file.ptr) {
-		/* Steal its file */
-		porigin->file = origin->file;
-		origin->file.ptr = NULL;
-	}
-	for (e = sb->ent; e; e = e->next) {
-		if (!same_suspect(e->suspect, origin))
-			continue;
-		origin_incref(porigin);
-		origin_decref(e->suspect);
-		e->suspect = porigin;
-	}
-}
-
-/*
  * We pass blame from the current commit to its parents.  We keep saying
  * "parent" (and "porigin"), but what we mean is to find scapegoat to
  * exonerate ourselves.
@@ -1540,8 +1569,14 @@ static void assign_blame(struct scoreboard *sb, int opt)
 
 		/* Take responsibility for the remaining entries */
 		for (ent = sb->ent; ent; ent = ent->next)

builtin/blame.c static void assign_blame(struct scoreboard *sb, int opt) · line 1579

Quoted 10 lines
builtin/blame.c +8 -2
-			if (same_suspect(ent->suspect, suspect))
-				found_guilty_entry(ent);
+			if (same_suspect(ent->suspect, suspect)) {
+				if (should_ignore_commit(sb, commit) &&
+				    ent->suspect->previous)
+					pass_whole_blame(sb, ent->suspect,
+							 ent->suspect->previous);
+				else
+					found_guilty_entry(ent);
+		   }

An ignored commit can still be blamed if there is no other commit to pass it on. So e.g. the initial commit for the file could end up being blamed for lines that were added by later commits which are being ignored. That may look confusing.

Would it make sense to pass the blame to some kind of null commit, i.e. a special marker that says "I could tell you who is to blame for this line but you said you don't want to know"?

René

author
#2 lore raw

Thanks for the speedy reply.

Quoted 2 lines

Only the long option --ignore-commit works with your patch, -I doesn't.

Correct. I took that out because I didn't want to use "-I' which could eventually be used by a more commonly used feature. Do you agree or do you think it is worth using it. It's a UI decision I didn't want to make.

Quoted 5 lines

This function was moved from below, but it seems to be indented with three spaces instead of tabs now.  Adding a declaration without moving the function would avoid that and result in a smaller patch.

Good catch, I'll do that and re-send.

Quoted 10 lines

An ignored commit can still be blamed if there is no other commit to pass it on.  So e.g. the initial commit for the file could end up being blamed for lines that were added by later commits which are being ignored.  That may look confusing.

Would it make sense to pass the blame to some kind of null commit, i.e. a special marker that says "I could tell you who is to blame for this line but you said you don't want to know"?

A null commit could work. I think the behavior should be to not ignore the commit. Meaning if you specify a commit that introduced a line of code that line of code will still be blamed on the ignored commit. Does That sound logical or is it too confusing?

Thanks,

Dylan

#3 lore raw
Quoted 4 lines · Dylan Reid

A null commit could work. I think the behavior should be to not ignore the commit. Meaning if you specify a commit that introduced a line of code that line of code will still be blamed on the ignored commit. Does That sound logical or is it too confusing?

I am already confused. If the command must return C when you say "ignore C" and C introduced a line you are interested in, then what is the point of specifying commits to be ignored?

author
#4 lore raw
Quoted 4 lines

I am already confused.  If the command must return C when you say "ignore C" and C introduced a line you are interested in, then what is the point of specifying commits to be ignored?

I was thinking that it would ignore changed lines, not added lines. Make sense?

#5 lore raw
Quoted 6 lines · Dylan Reid
Quoted 4 lines

I am already confused.  If the command must return C when you say "ignore C" and C introduced a line you are interested in, then what is the point of specifying commits to be ignored?

I was thinking that it would ignore changed lines, not added lines. Make sense?

Not really. I don't think you can distinguish "changed lines" and "added lines" reliably.

author
#6 lore raw

I've noticed that trying to come up with a solution tonight. I'll look at it some more tomorrow. If you can't tell the difference between added and changed then there would be no easy way to mark a line as ignored either.

If the changes get split fine enough could you tell that blame_ent doesn't exist in a parent commit?

Thanks,

Dylan

Quoted 12 lines · Junio C Hamano
Quoted 6 lines · Dylan Reid
Quoted 4 lines

I am already confused.  If the command must return C when you say "ignore C" and C introduced a line you are interested in, then what is the point of specifying commits to be ignored?

I was thinking that it would ignore changed lines, not added lines.  Make sense?

Not really.  I don't think you can distinguish "changed lines" and "added lines" reliably.

#7 lore raw

I'm not subscribed to the list, so please reply-to-all or cc me on responses.

Is this feature dead? There seems to be some question about the value of such a feature in the discussion along this thread, however, such a feature would have the wonderful benefit of allowing a change such as that being discussed here:
http://koha.1045719.n5.nabble.com/Koha-3-8-release-schedule-amp-perltidy-process-td5547369.html
to be made and yet preserve the usefulness of git-blame.

To recap the issue in the thread at koha-devel:

A massive perl-tidy is being considered to be applied project wide in a single commit. The real show-stopper is that this breaks git-blame. If git-blame could be told to ignore that single commit id, life would be good (I think).

At any rate it provides a use-case which might justify such a feature.

Kind Regards,
Chris

--
View this message in context: http://git.661346.n2.nabble.com/PATCH-blame-can-specify-shas-of-commits-to-ignore-on-command-line-tp5001395p7356224.html
Sent from the git mailing list archive at Nabble.com.