Re: conflict status

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Michael Wild <themiwi@xxxxxxxxxxxxxxxxxxxxx> writes:

> # get all conflicts
> conflicts="$(git-status | awk '/unmerged:/{print $3;next}')"
>
> for f in $conflicts; do
>   # extract the file mode for base, local and remote
>   base_mode=$(git ls-files -u -- "$f" | awk '{if ($3==1) print $1;}')
>   local_mode=$(git ls-files -u -- "$f" | awk '{if ($3==2) print $1;}')
>   remote_mode=$(git ls-files -u -- "$f" | awk '{if ($3==3) print $1;}')
>   # create the status flags
>   describe_state "$local_mode"
>   describe_state "$remote_mode"
>   # append the file name
>   echo " $f"
> done

Looks an awfully inefficient way to say "git ls-files -u" to me.  If you
do not see stage 2, you do not have it.  If you do not see stage 3, they
do not have it.

If you really really want to condense the object name information out, you
could do something like this.

-- >8 --
#!/bin/sh
git ls-files -u -z |
perl -e '
	$/ = "\0";
        my ($last_path, @stage);
        sub describe_mode {
        	my $ours = $_[0];
		my $sign;
                if (!defined $ours) {
                	$sign = "d";
		} elsif (defined $stage[1]) {
                	$sign = "m";
		} else {
			$sign = "c";
                }
		return $sign;
        }
	sub flush_path {
        	printf("%s %s %s\n",
                	describe_mode($stage[2]),
                	describe_mode($stage[3]),
			$last_path);
		$last_path = undef;
        	@stage = ();
        }
        while (<>) {
		chomp;
        	my ($mode, $sha1, $stage, $path) =
                	/^([0-7]+) ([0-9a-f]{40}) ([1-3])\t(.*)$/;
		if (defined $last_path) {
			flush_path() if ($path ne $last_path);
                }
                $stage[$stage] = 1;
                $last_path = $path;
	}
        if (defined $last_path) {
                flush_path() if ($path ne $last_path);
        }
'
-- 8< --

I however do not think it is all that interesting, though.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]